Best JavaScript code snippet using playwright-internal
CCEventManager.js
Source: CCEventManager.js
...781 this._inDispatch++;782 if(!event || !event.getType)783 throw "event is undefined";784 if (event.getType() == cc.Event.TOUCH) {785 this._dispatchTouchEvent(event);786 this._inDispatch--;787 return;788 }789 var listenerID = cc.__getListenerID(event);790 this._sortEventListeners(listenerID);791 var selListeners = this._listenersMap[listenerID];792 if (selListeners != null)793 this._dispatchEventToListeners(selListeners, this._onListenerCallback, event);794 this._updateListeners(event);795 this._inDispatch--;796 },797 _onListenerCallback: function(listener, event){798 event._setCurrentTarget(listener._getSceneGraphPriority());799 listener._onEvent(event);...
PageAgent.js
Source: PageAgent.js
...521 } else {522 throw new Error(`Unknown type ${type}`);523 }524 }525 async _dispatchTouchEvent({type, touchPoints, modifiers}) {526 const frame = this._frameTree.mainFrame();527 const defaultPrevented = frame.domWindow().windowUtils.sendTouchEvent(528 type.toLowerCase(),529 touchPoints.map((point, id) => id),530 touchPoints.map(point => point.x),531 touchPoints.map(point => point.y),532 touchPoints.map(point => point.radiusX === undefined ? 1.0 : point.radiusX),533 touchPoints.map(point => point.radiusY === undefined ? 1.0 : point.radiusY),534 touchPoints.map(point => point.rotationAngle === undefined ? 0.0 : point.rotationAngle),535 touchPoints.map(point => point.force === undefined ? 1.0 : point.force),536 touchPoints.length,537 modifiers);538 return {defaultPrevented};539 }540 async _dispatchTapEvent({x, y, modifiers}) {541 // Force a layout at the point in question, because touch events542 // do not seem to trigger one like mouse events.543 this._frameTree.mainFrame().domWindow().windowUtils.elementFromPoint(544 x,545 y,546 false /* aIgnoreRootScrollFrame */,547 true /* aFlushLayout */);548 const {defaultPrevented: startPrevented} = await this._dispatchTouchEvent({549 type: 'touchstart',550 modifiers,551 touchPoints: [{x, y}]552 });553 const {defaultPrevented: endPrevented} = await this._dispatchTouchEvent({554 type: 'touchend',555 modifiers,556 touchPoints: [{x, y}]557 });558 if (startPrevented || endPrevented)559 return;560 const frame = this._frameTree.mainFrame();561 frame.domWindow().windowUtils.sendMouseEvent(562 'mousemove',563 x,564 y,565 0 /*button*/,566 0 /*clickCount*/,567 modifiers,...
application-Android.js
Source: application-Android.js
1const Accelerometer = require("../device/accelerometer");2const Location = require("../device/location");3const TypeUtil = require("../util/type");4const AndroidConfig = require("../util/Android/androidconfig");5const Http = require("../net/http");6const Network = require('../device/network');7const NativeSpratAndroidActivity = requireClass("io.smartface.android.SpratAndroidActivity");8const NativeActivityLifeCycleListener = requireClass("io.smartface.android.listeners.ActivityLifeCycleListener");9const NativeR = requireClass(AndroidConfig.packageName + '.R');10function ApplicationWrapper() {}11//InputMethodManager to close softinput keyboard12const { INPUT_METHOD_SERVICE, INPUT_METHOD_MANAGER } = require('../util/Android/systemservices');13// Intent.ACTION_VIEW14const ACTION_VIEW = "android.intent.action.VIEW";15// Intent.FLAG_ACTIVITY_NEW_TASK16const FLAG_ACTIVITY_NEW_TASK = 268435456;17const REQUEST_CODE_CALL_APPLICATION = 114, FLAG_SECURE = 8192;18var _onMinimize, _onMaximize, _onExit, _onBackButtonPressed,19 _onReceivedNotification, _onRequestPermissionsResult, _keepScreenAwake = false,20 _keyboardMode, _sliderDrawer, _dispatchTouchEvent, activity = AndroidConfig.activity,21 spratAndroidActivityInstance = NativeSpratAndroidActivity.getInstance(),_secureWindowContent = false;22var mDrawerLayout = activity.findViewById(NativeR.id.layout_root);23ApplicationWrapper.__mDrawerLayout = mDrawerLayout;24// Creating Activity Lifecycle listener25var activityLifeCycleListener = NativeActivityLifeCycleListener.implement({26 onCreate: function() {},27 onResume: function() {28 if (_onMaximize) {29 _onMaximize();30 }31 },32 onPause: function() {33 if (_onMinimize) {34 _onMinimize();35 }36 },37 onStop: function() {},38 onStart: function() {},39 onDestroy: function() {40 cancelAllBackgroundJobs();41 if (_onExit) {42 _onExit();43 }44 },45 onRequestPermissionsResult: function(requestCode, permission, grantResult) {46 var permissionResults = {};47 permissionResults['requestCode'] = requestCode;48 permissionResults['result'] = (grantResult === 0);49 ApplicationWrapper.android.onRequestPermissionsResult && ApplicationWrapper.android.onRequestPermissionsResult(permissionResults);50 },51 onActivityResult: function(requestCode, resultCode, data) {52 if (requestCode === Location.CHECK_SETTINGS_CODE) {53 Location.__onActivityResult && Location.__onActivityResult(resultCode);54 }55 },56 dispatchTouchEvent: function(actionType, x, y) {57 let dispatchTouchEvent;58 if (ApplicationWrapper.android.dispatchTouchEvent)59 dispatchTouchEvent = ApplicationWrapper.android.dispatchTouchEvent();60 return (typeof(dispatchTouchEvent) === 'boolean') ? dispatchTouchEvent : false;61 }62});63// Attaching Activity Lifecycle event64spratAndroidActivityInstance.addActivityLifeCycleCallbacks(activityLifeCycleListener);65Object.defineProperties(ApplicationWrapper, {66 // properties67 'sliderDrawer': {68 get: function() {69 return _sliderDrawer;70 },71 set: function(drawer) {72 const SliderDrawer = require('../ui/sliderdrawer');73 if (drawer instanceof SliderDrawer) {74 detachSliderDrawer(_sliderDrawer);75 _sliderDrawer = drawer;76 attachSliderDrawer(_sliderDrawer);77 } else {78 throw TypeError("Object must be SliderDrawer instance");79 }80 },81 enumerable: true82 },83 'keepScreenAwake': {84 get: function() {85 return _keepScreenAwake;86 },87 set: function(value) {88 _keepScreenAwake = value;89 if(_keepScreenAwake) {90 // 128 = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON91 activity.getWindow().addFlags(128);92 } else {93 // 128 = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON94 activity.getWindow().clearFlags(128);95 }96 },97 enumerable: true98 },99 'byteReceived': {100 get: function() {101 const NativeTrafficStats = requireClass("android.net.TrafficStats");102 var UID = activity.getApplicationInfo().uid;103 return NativeTrafficStats.getUidRxBytes(UID) / (1024 * 1024);104 },105 enumerable: true106 },107 'byteSent': {108 get: function() {109 const NativeTrafficStats = requireClass("android.net.TrafficStats");110 var UID = activity.getApplicationInfo().uid;111 return NativeTrafficStats.getUidTxBytes(UID) / (1024 * 1024);112 },113 enumerable: true114 },115 // For publish case, project.json file will be encrypted we can not decrypt this file, we do not have a key so let SMFApplication handle this116 'currentReleaseChannel': {117 get: function() {118 return Application.currentReleaseChannel;119 },120 enumerable: true121 },122 // For publish case, project.json file will be encrypted we can not decrypt this file, we do not have a key so let SMFApplication handle this123 'smartfaceAppName': {124 get: function() {125 return Application.smartfaceAppName;126 },127 enumerable: true128 },129 // For publish case, project.json file will be encrypted we can not decrypt this file, we do not have a key so let SMFApplication handle this130 'appName': {131 get: function() {132 return Application.smartfaceAppName;133 },134 enumerable: true135 },136 // For publish case, project.json file will be encrypted we can not decrypt this file, we do not have a key so let SMFApplication handle this137 'version': {138 get: function() {139 return Application.version;140 },141 enumerable: true142 },143 'android': {144 value: {},145 enumerable: true146 },147 'Android': {148 value: {},149 enumerable: true150 },151 'call': {152 /* ToDo : Multiple parameter is deprected.*/153 value: function() {154 if (arguments.length === 1 && (typeof arguments[0] === "object"))155 var {156 uriScheme,157 data,158 onSuccess,159 onFailure,160 isShowChooser,161 chooserTitle,162 action = ACTION_VIEW163 } = arguments[0];164 else165 var [uriScheme, data, onSuccess, onFailure, isShowChooser, chooserTitle, action = ACTION_VIEW] = arguments;166 if (!TypeUtil.isString(uriScheme)) {167 throw new TypeError('uriScheme must be string');168 }169 const NativeIntent = requireClass("android.content.Intent");170 const NativeUri = requireClass("android.net.Uri");171 let intent = new NativeIntent(action);172 let uriObject;173 if (TypeUtil.isObject(data) && Object.keys(data).length > 0) {174 // we should use intent.putExtra but it causes native crash.175 let params = Object.keys(data).map(function(k) {176 return k + '=' + data[k];177 }).join('&');178 if (uriScheme.indexOf("|") !== -1) {179 configureIntent.call(intent, uriScheme);180 uriObject = NativeUri.parse(params);181 } else {182 let uri = uriScheme + "?" + params;183 uriObject = NativeUri.parse(uri);184 }185 } else {186 if (uriScheme.indexOf("|") !== -1)187 configureIntent.call(intent, uriScheme);188 else189 uriObject = NativeUri.parse(uriScheme);190 }191 uriObject && intent.setData(uriObject);192 let packageManager = activity.getPackageManager();193 let activitiesCanHandle = packageManager.queryIntentActivities(intent, 0);194 if (activitiesCanHandle.size() > 0) {195 if (TypeUtil.isBoolean(isShowChooser) && isShowChooser) {196 let title = TypeUtil.isString(chooserTitle) ? chooserTitle : "Select and application";197 let chooserIntent = NativeIntent.createChooser(intent, title);198 try {199 activity.startActivity(chooserIntent); // Due to the AND-3202: we have changed startActivityForResult200 } catch (e) {201 onFailure && onFailure();202 return;203 }204 } else {205 try {206 activity.startActivity(intent); // Due to the AND-3202: we have changed startActivityForResult207 } catch (e) {208 onFailure && onFailure();209 return;210 }211 }212 onSuccess && onSuccess();213 return;214 }215 onFailure && onFailure();216 },217 enumerable: true218 },219 'exit': {220 value: function() {221 activity.finish();222 },223 enumerable: true224 },225 'restart': {226 value: function() {227 spratAndroidActivityInstance.restartSpratActivity();228 },229 enumerable: true230 },231 'checkUpdate': {232 value: function(callback, user) {233 if (TypeUtil.isFunction(callback)) {234 const RAU = require("./RAU");235 RAU.checkUpdate(callback, user);236 }237 },238 enumerable: true239 },240 'hideKeyboard': {241 value: function() {242 var focusedView = activity.getCurrentFocus();243 if (!focusedView)244 return;245 var windowToken = focusedView.getWindowToken();246 var inputManager = AndroidConfig.getSystemService(INPUT_METHOD_SERVICE, INPUT_METHOD_MANAGER);247 inputManager.hideSoftInputFromWindow(windowToken, 0); //2.parameter: Provides additional operating flags. Currently may be 0 248 },249 enumerable: true250 },251 // events252 // We can not handle application calls for now, so let SMFApplication handle this253 'onExit': {254 get: function() {255 return _onExit;256 },257 set: function(onExit) {258 if (TypeUtil.isFunction(onExit) || onExit === null) {259 _onExit = onExit;260 }261 },262 enumerable: true263 },264 'onMaximize': {265 get: function() {266 return _onMaximize;267 },268 set: function(onMaximize) {269 if (TypeUtil.isFunction(onMaximize) || onMaximize === null) {270 _onMaximize = onMaximize;271 }272 },273 enumerable: true274 },275 'onMinimize': {276 get: function() {277 return _onMinimize;278 },279 set: function(onMinimize) {280 if (TypeUtil.isFunction(onMinimize) || onMinimize === null) {281 _onMinimize = onMinimize;282 }283 },284 enumerable: true285 },286 'onReceivedNotification': {287 get: function() {288 return _onReceivedNotification;289 },290 set: function(callback) {291 if (TypeUtil.isFunction(callback) || callback === null) {292 _onReceivedNotification = callback;293 }294 },295 enumerable: true296 },297 // We can not detect js exceptions, so let SMFApplication handle this298 'onUnhandledError': {299 get: function() {300 return Application.onUnhandledError;301 },302 set: function(onUnhandledError) {303 if (TypeUtil.isFunction(onUnhandledError) || onUnhandledError === null) {304 Application.onUnhandledError = onUnhandledError;305 }306 },307 enumerable: true308 },309 'onApplicationCallReceived': {310 get: function() {311 return Application.onApplicationCallReceived;312 },313 set: function(_onApplicationCallReceived) {314 if (TypeUtil.isFunction(_onApplicationCallReceived) || _onApplicationCallReceived === null) {315 Application.onApplicationCallReceived = _onApplicationCallReceived;316 }317 },318 enumerable: true319 },320});321ApplicationWrapper.registOnItemSelectedListener = function() {322 if (ApplicationWrapper.__isSetOnItemSelectedListener) {323 return;324 }325 ApplicationWrapper.__isSetOnItemSelectedListener = true;326 spratAndroidActivityInstance.attachItemSelectedListener({327 onOptionsItemSelected: function() {328 let leftItem = ApplicationWrapper.currentPage._headerBarLeftItem;329 if (leftItem) {330 leftItem.onPress && leftItem.onPress();331 }332 }333 });334};335function cancelAllBackgroundJobs() {336 Location.stop();337 Accelerometer.stop();338 Http.__cancelAll();339 Network.__cancelAll();340}341// TODO: Beautify the class. It is too complex! It is not a readable file! 342ApplicationWrapper.setRootController = function(params) {343 const ViewController = require("../util/Android/transition/viewcontroller");344 ViewController.deactivateRootController(ApplicationWrapper.currentPage);345 // ViewController.activateController(params.controller);346 params.controller.__isActive = true;347 ViewController.setController(params);348};349function configureIntent(uriScheme) {350 const intent = this;351 let classActivityNameArray = uriScheme.split("|");352 intent.setClassName(classActivityNameArray[0], classActivityNameArray[1]);353}354function attachSliderDrawer(sliderDrawer) {355 if (sliderDrawer) {356 sliderDrawer.__isAttached = true;357 var sliderDrawerId = sliderDrawer.nativeObject.getId();358 var isExists = mDrawerLayout.findViewById(sliderDrawerId);359 if (!isExists) {360 mDrawerLayout.addView(sliderDrawer.nativeObject);361 mDrawerLayout.bringToFront();362 if (sliderDrawer.drawerListener) {363 mDrawerLayout.addDrawerListener(sliderDrawer.drawerListener);364 }365 }366 sliderDrawer.onLoad && sliderDrawer.onLoad();367 }368}369function detachSliderDrawer(sliderDrawer) {370 if (sliderDrawer) {371 sliderDrawer.__isAttached = false;372 mDrawerLayout.removeView(sliderDrawer.nativeObject);373 if (sliderDrawer.drawerListener) {374 mDrawerLayout.removeDrawerListener(sliderDrawer.drawerListener);375 }376 }377}378ApplicationWrapper.statusBar = require("./statusbar");379ApplicationWrapper.ios = {};380ApplicationWrapper.ios.canOpenUrl = function(url) {};381ApplicationWrapper.ios.onUserActivityWithBrowsingWeb = function() {};382Object.defineProperties(ApplicationWrapper.android, {383 'packageName': {384 value: activity.getPackageName(),385 enumerable: true386 },387 'dispatchTouchEvent': {388 get: function() {389 return _dispatchTouchEvent;390 },391 set: function(callback) {392 _dispatchTouchEvent = callback;393 },394 enumerable: true395 },396 'onBackButtonPressed': {397 get: function() {398 return _onBackButtonPressed;399 },400 set: function(callback) {401 _onBackButtonPressed = callback;402 spratAndroidActivityInstance.attachBackPressedListener({403 onBackPressed: function() {404 _onBackButtonPressed && _onBackButtonPressed();405 }406 });407 },408 enumerable: true409 },410 'checkPermission': {411 value: function(permission) {412 if (!TypeUtil.isString(permission)) {413 throw new Error('Permission must be Application.Permission type');414 }415 if (AndroidConfig.sdkVersion < AndroidConfig.SDK.SDK_MARSHMALLOW) {416 // PackageManager.PERMISSION_GRANTED417 const NativeContextCompat = requireClass('androidx.core.content.ContextCompat');418 return NativeContextCompat.checkSelfPermission(activity, permission) === 0;419 } else {420 var packageManager = activity.getPackageManager();421 // PackageManager.PERMISSION_GRANTED422 return packageManager.checkPermission(permission, ApplicationWrapper.android.packageName) == 0;423 }424 },425 enumerable: true426 },427 // @todo requestPermissions should accept permission array too, but due to AND- it accepts just one permission.428 'requestPermissions': {429 value: function(requestCode, permissions) {430 if (!TypeUtil.isNumeric(requestCode) || !(TypeUtil.isString(permissions))) {431 throw new Error('requestCode must be numeric or permission must be Application.Permission type or array of Application.Permission.');432 }433 if (AndroidConfig.sdkVersion < AndroidConfig.SDK.SDK_MARSHMALLOW) {434 ApplicationWrapper.android.onRequestPermissionsResult && ApplicationWrapper.android.onRequestPermissionsResult({435 requestCode: requestCode,436 result: ApplicationWrapper.android.checkPermission(permissions)437 });438 } else {439 activity.requestPermissions(array([permissions], "java.lang.String"), requestCode);440 }441 },442 enumerable: true443 },444 'shouldShowRequestPermissionRationale': {445 value: function(permission) {446 if (!TypeUtil.isString(permission)) {447 throw new Error('Permission must be Application.Permission type');448 }449 return ((AndroidConfig.sdkVersion > AndroidConfig.SDK.SDK_MARSHMALLOW) && activity.shouldShowRequestPermissionRationale(permission));450 },451 enumerable: true452 },453 'onRequestPermissionsResult': {454 get: function() {455 return _onRequestPermissionsResult;456 },457 set: function(callback) {458 if (TypeUtil.isFunction(callback) || callback === null) {459 _onRequestPermissionsResult = callback;460 }461 }462 },463 'Permissions': {464 value: {},465 enumerable: true466 },467 'navigationBar': {468 get: function() {469 return (require("./android/navigationbar"));470 },471 enumerable: true472 },473 'keyboardMode': {474 get: function() {475 return _keyboardMode;476 },477 set: function(modeEnum) {478 if (typeof modeEnum !== "number")479 return;480 _keyboardMode = modeEnum;481 activity.getWindow().setSoftInputMode(modeEnum);482 },483 enumerable: true484 },485 'locale': {486 get: function() {487 const LocaleConfigurationUtil = requireClass("io.smartface.android.utils.LocaleConfigurationUtil");488 return LocaleConfigurationUtil.getDeviceLanguage();489 },490 set: function(languageCode) {491 if (TypeUtil.isString(languageCode)) {492 const NativePreferenceManager = requireClass("android.preference.PreferenceManager");493 const LocaleHelperUtil = requireClass("io.smartface.android.utils.LocaleConfigurationUtil");494 var sharedPreferences = NativePreferenceManager.getDefaultSharedPreferences(activity);495 sharedPreferences.edit().putString("AppLocale", languageCode).commit();496 LocaleHelperUtil.changeConfigurationLocale(activity);497 }498 },499 enumerable: true500 },501 'getLayoutDirection': {502 get: function() {503 return activity.getResources().getConfiguration().getLayoutDirection();504 },505 enumerable: true506 },507 'setAppTheme': {508 value: currentTheme => {509 const NativePreferenceManager = requireClass("android.preference.PreferenceManager");510 let sharedPreferences = NativePreferenceManager.getDefaultSharedPreferences(activity);511 let _themeRes = activity.getResources().getIdentifier(currentTheme, "style", activity.getPackageName());512 sharedPreferences.edit().putInt("SFCurrentBaseTheme", _themeRes).commit();513 },514 enumerable: true515 },516 'secureWindowContent': {517 get : () => _secureWindowContent,518 set : (value) => {519 _secureWindowContent = value;520 if(_secureWindowContent)521 activity.getWindow().setFlags(FLAG_SECURE, FLAG_SECURE);522 else 523 activity.getWindow().clearFlags(FLAG_SECURE);524 } 525 }526});527Object.defineProperties(ApplicationWrapper.Android, {528 'Permissions': {529 value: {},530 enumerable: true531 }532});533Object.defineProperties(ApplicationWrapper.Android.Permissions, {534 'READ_CALENDAR': {535 value: 'android.permission.READ_CALENDAR',536 enumerable: true537 },538 'WRITE_CALENDAR': {539 value: 'android.permission.WRITE_CALENDAR',540 enumerable: true541 },542 'CAMERA': {543 value: 'android.permission.CAMERA',544 enumerable: true545 },546 'READ_CONTACTS': {547 value: 'android.permission.READ_CONTACTS',548 enumerable: true549 },550 'WRITE_CONTACTS': {551 value: 'android.permission.WRITE_CONTACTS',552 enumerable: true553 },554 'GET_ACCOUNTS': {555 value: 'android.permission.GET_ACCOUNTS',556 enumerable: true557 },558 'ACCESS_FINE_LOCATION': {559 value: 'android.permission.ACCESS_FINE_LOCATION',560 enumerable: true561 },562 'ACCESS_COARSE_LOCATION': {563 value: 'android.permission.ACCESS_COARSE_LOCATION',564 enumerable: true565 },566 'RECORD_AUDIO': {567 value: 'android.permission.RECORD_AUDIO',568 enumerable: true569 },570 'READ_PHONE_STATE': {571 value: 'android.permission.READ_PHONE_STATE',572 enumerable: true573 },574 'CALL_PHONE': {575 value: 'android.permission.CALL_PHONE',576 enumerable: true577 },578 'READ_CALL_LOG': {579 value: 'android.permission.READ_CALL_LOG',580 enumerable: true581 },582 'WRITE_CALL_LOG': {583 value: 'android.permission.WRITE_CALL_LOG',584 enumerable: true585 },586 'ADD_VOICEMAIL': {587 value: 'com.android.voicemail.permission.ADD_VOICEMAIL',588 enumerable: true589 },590 'USE_SIP': {591 value: 'android.permission.USE_SIP',592 enumerable: true593 },594 'PROCESS_OUTGOING_CALLS': {595 value: 'android.permission.PROCESS_OUTGOING_CALLS',596 enumerable: true597 },598 'BODY_SENSORS': {599 value: 'android.permission.BODY_SENSORS',600 enumerable: true601 },602 'SEND_SMS': {603 value: 'android.permission.SEND_SMS',604 enumerable: true605 },606 'RECEIVE_SMS': {607 value: 'android.permission.RECEIVE_SMS',608 enumerable: true609 },610 'READ_SMS': {611 value: 'android.permission.READ_SMS',612 enumerable: true613 },614 'RECEIVE_WAP_PUSH': {615 value: 'android.permission.RECEIVE_WAP_PUSH',616 enumerable: true617 },618 'RECEIVE_MMS': {619 value: 'android.permission.RECEIVE_MMS',620 enumerable: true621 },622 'READ_EXTERNAL_STORAGE': {623 value: 'android.permission.READ_EXTERNAL_STORAGE',624 enumerable: true625 },626 'WRITE_EXTERNAL_STORAGE': {627 value: 'android.permission.WRITE_EXTERNAL_STORAGE',628 enumerable: true629 },630 'USE_FINGERPRINT': {631 value: 'android.permission.USE_FINGERPRINT',632 enumerable: true633 },634 'WRITE_APN_SETTINGS': {635 value: 'android.permission.WRITE_APN_SETTINGS',636 enumerable: true637 }638});639Object.assign(ApplicationWrapper.android.Permissions, ApplicationWrapper.Android.Permissions);640ApplicationWrapper.Android.NavigationBar = {641 /** @type {typeof import("./android/navigationbar/style")} */642 Style: require("./android/navigationbar/style")643};644Object.freeze(ApplicationWrapper.Android.NavigationBar);645ApplicationWrapper.Android.KeyboardMode = {646 KeyboardAdjustNothing: 48, //SOFT_INPUT_ADJUST_NOTHING647 KeyboardAdjustPan: 32, //SOFT_INPUT_ADJUST_PAN648 KeyboardAdjustResize: 16, //SOFT_INPUT_ADJUST_RESIZE649 KeyboardAdjustUnspecified: 0, //SOFT_INPUT_ADJUST_UNSPECIFIED650 AlwaysVisible: 5, //SOFT_INPUT_STATE_ALWAYS_VISIBLE651 AlwaysHidden: 3 //SOFT_INPUT_STATE_ALWAYS_HIDDEN652};653Object.freeze(ApplicationWrapper.Android.KeyboardMode);654/**655 * @type {{LEFTTORIGHT: 0, RIGHTTOLEFT: 1}}656 */657ApplicationWrapper.LayoutDirection = {658 LEFTTORIGHT: 0,659 RIGHTTOLEFT: 1660};661Object.freeze(ApplicationWrapper.LayoutDirection);...
touch.js
Source: touch.js
1/**2 * Touchäºä»¶ç±»3 * ç¨äºæµè¯touchç³»åäºä»¶4 */5class Touch {6 /**7 * _createTouchEvent æ¯ææµè§å¨è°ç¨touchç³»åäºä»¶ï¼åå§åäºä»¶8 * @param {String} type äºä»¶å称(touchend)9 * @return {Object} æµè§å¨åçäºä»¶å¯¹è±¡10 */11 createTouchEvent(type) {12 return new window.TouchEvent(type, {13 bubbles: true,14 cancelable: true15 })16 }17 /**18 * _dispatchTouchEvent åºåtouchç³»åäºä»¶19 * @param {String(Selector) | HTMLDivElement} eventTarget äºä»¶è§¦åDOMå
ç´ 20 * @param {Object} event æµè§å¨åçäºä»¶å¯¹è±¡21 * @return {HTMLDivElement} äºä»¶è§¦åDOMå
ç´ 22 */23 dispatchTouchEvent(eventTarget, event) {24 if (typeof eventTarget === 'string') {25 eventTarget = document.querySelector(eventTarget)26 }27 eventTarget.dispatchEvent(event)28 return eventTarget29 }30}31
...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page._dispatchTouchEvent({7 timestamp: Date.now(),8 });9 await page._dispatchTouchEvent({10 timestamp: Date.now(),11 });12 await browser.close();13})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { _dispatchTouchEvent } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForSelector('text=Get started');8 await page.click('text=Get started');9 await page.waitForSelector('text=API');10 await page.click('text=API');11 await page.waitForSelector('text=Browser');12 await page.click('text=Browser');13 await page.waitForSelector('text=class: Browser');14 await page.click('text=class: Browser');15 await page.waitForSelector('text=close');16 await page.click('text=close');17 await page.waitForSelector('text=BrowserContext');18 await page.click('text=BrowserContext');19 await page.waitForSelector('text=class: BrowserContext');20 await page.click('text=class: BrowserContext');21 await page.waitForSelector('text=close');22 await page.click('text=close');23 await page.waitForSelector('text=Page');24 await page.click('text=Page');25 await page.waitForSelector('text=class: Page');26 await page.click('text=class: Page');27 await page.waitForSelector('text=close');28 await page.click('text=close');29 await page.waitForSelector('text=Selectors');30 await page.click('text=Selectors');31 await page.waitForSelector('text=class: Selectors');32 await page.click('text=class: Selectors');33 await page.waitForSelector('text=close');34 await page.click('text=close');35 await page.waitForSelector('text=Selectors');36 await page.click('text=Selectors');37 await page.waitForSelector('text=class: Selectors');38 await page.click('text=class: Selectors');39 await page.waitForSelector('text=close');40 await page.click('text=close');41 await page.waitForSelector('text=Selectors');42 await page.click('text=Selectors');43 await page.waitForSelector('text=class: Selectors');44 await page.click('text=class: Selectors');45 await page.waitForSelector('text=close');46 await page.click('text=close');
Using AI Code Generation
1const { _dispatchTouchEvent } = require('playwright/lib/server/chromium/crPage.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await _dispatchTouchEvent(page, 'touchstart', {8 });9 await browser.close();10})();
Using AI Code Generation
1const { _dispatchTouchEvent } = require('playwright/lib/server/chromium/crPage');2const { Page } = require('playwright/lib/server/chromium/crPage');3const { assert } = require('playwright/lib/utils/utils');4const { Touchscreen } = require('playwright/lib/server/chromium/crInput');5async function emulateTouchEvent(page, type, x, y, modifiers) {6 const touchPoint = {7 };8 const touchPoints = [touchPoint];9 const modifiersList = modifiers || 0;10 const timestamp = Date.now();11 const button = 'left';12 const buttons = 1;13 const clickCount = 1;14 const touchType = 'touchstart';15 const touchId = 1;16 const event = {17 };18 await _dispatchTouchEvent.call(page, event);19}20async function emulateTouch(page, x, y) {21 await emulateTouchEvent(page, 'touchstart', x, y);22 await emulateTouchEvent(page, 'touchend', x, y);23}24async function emulatePinch(page, x, y) {25 const touchPoint = {26 };27 const touchPoints = [touchPoint, touchPoint];28 const modifiersList = 0;29 const timestamp = Date.now();30 const button = 'left';31 const buttons = 1;32 const clickCount = 1;33 const touchType = 'touchstart';34 const touchId = 1;35 const event = {
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.evaluate(async () => {7 const touch = new Touch({8 identifier: Date.now(),9 target: document.elementFromPoint(100, 100),10 });11 const touchEvent = new TouchEvent('touchstart', {12 });13 await window._dispatchTouchEvent('touchstart', touchEvent);14 });15 await browser.close();16})();17class Touch {18 constructor({ identifier, target, clientX, clientY, pageX, pageY }) {19 this.identifier = identifier;20 this.target = target;21 this.clientX = clientX;22 this.clientY = clientY;23 this.pageX = pageX;24 this.pageY = pageY;25 }26}27class TouchEvent {28 constructor(type, {29 }) {30 this.type = type;31 this.cancelable = cancelable;32 this.bubbles = bubbles;33 this.touches = touches;34 this.targetTouches = targetTouches;35 this.changedTouches = changedTouches;36 this.shiftKey = shiftKey;37 }38}39const {helper} = require('playwright');40const {Touch} = require('./touch');41const {TouchEvent} = require('./touchevent');42const {EventEmitter} = require('events');43const {Page} = require('playwright');44class Dispatcher extends EventEmitter {45 constructor() {46 super();47 }48}49class TouchDispatcher extends Dispatcher {50 constructor() {51 super();52 }53}54class Input {55 constructor() {
Using AI Code Generation
1const { _dispatchTouchEvent } = require('playwright-core/lib/server/chromium/crInput');2const { getTestState } = require('playwright-core/lib/server/test');3const { getFrameExecutionContext } = require('playwright-core/lib/server/frames');4const frame = await page.mainFrame();5const context = await getFrameExecutionContext(page, frame);6const element = await frame.$('#myElement');7const boundingBox = await element.boundingBox();8const x = boundingBox.x;9const y = boundingBox.y;10const testState = getTestState(page);11_dispatchTouchEvent(testState, 'touchstart', x, y, 0);12_dispatchTouchEvent(testState, 'touchend', x, y, 0);13const frame = await page.mainFrame();14const context = await getFrameExecutionContext(page, frame);15const element = await frame.$('#myElement');16const boundingBox = await element.boundingBox();17const x = boundingBox.x;18const y = boundingBox.y;19const testState = getTestState(page);20await page.evaluate((x, y) => {21 const touchstart = new TouchEvent('touchstart', {22 touches: [new Touch({ identifier: Date.now(), target: document.elementFromPoint(x, y), clientX: x, clientY: y })],23 changedTouches: [new Touch({ identifier: Date.now(), target: document.elementFromPoint(x, y
Using AI Code Generation
1const { _dispatchTouchEvent } = require('playwright/lib/server/chromium/crPage');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type="submit"]:nth-child(1)')8 await _dispatchTouchEvent(page, 'touchstart', [9 { x: 100, y: 100 },10 ]);11 await _dispatchTouchEvent(page, 'touchend', [12 { x: 100, y: 100 },13 ]);14 await page.waitForTimeout(5000);15 await browser.close();16})();
Using AI Code Generation
1const { Page } = require('playwright-core/lib/server/page');2const { Dispatcher } = require('playwright-core/lib/server/dispatcher');3const { helper } = require('playwright-core/lib/server/helper');4const { Touchscreen } = require('playwright-core/lib/server/supplements/touchscreen');5const { TouchPoint } = require('playwright-core/lib/server/supplements/touchscreen');6const { TouchscreenDispatcher } = require('playwright-core/lib/server/supplements/touchscreenDispatcher');7const { TouchscreenImpl } = require('playwright-core/lib/server/supplements/touchscreenImpl');8const { Frame } = require('playwright-core/lib/server/frame');9const { FrameDispatcher } = require('playwright-core/lib/server/frameDispatcher');10const { FrameImpl } = require('playwright-core/lib/server/frameImpl');11const { PageDispatcher } = require('playwright-core/lib/server/pageDispatcher');12const { PageImpl } = require('playwright-core/lib/server/pageImpl');13const { PageChannelOwner } = require('playwright-core/lib/server/channels');14const { PageChannel } = require('playwright-core/lib/server/channels');15const { PageBinding } = require('playwright-core/lib/server/pageBinding');16const { PageBindingCall } = require('playwright-core/lib/server/pageBindingCall');17const { PageBindingInitializer } = require('playwright-core/lib/server/pageBindingInitializer');18const { PageBindingCallDispatcher } = require('playwright-core/lib/server/pageBindingCallDispatcher');19const { PageBindingCallImpl } = require('playwright-core/lib/server/pageBindingCallImpl');20const { PageBindingCallChannel } = require('playwright-core/lib/server/channels');21const { PageBindingDispatcher } = require('playwright-core/lib/server/pageBindingDispatcher');22const { PageBindingImpl } = require('playwright-core/lib/server/pageBindingImpl');23const { PageBindingChannel } = require('playwright-core/lib/server/channels');24const { PageBindingCallChannelOwner } = require('playwright-core/lib/server/channels');25const { PageBindingCallChannelOwner } = require('playwright-core/lib/server/channels');26const { PageBindingCallChannelOwner } = require('playwright-core/lib/server/channels');27const { PageBindingCallChannelOwner } = require('playwright-core/lib/server/channels');28const { PageBindingCallChannelOwner } = require('playwright-core/lib/server/channels');
Using AI Code Generation
1const { Page } = require('playwright-core/lib/server/page');2Page.prototype._dispatchTouchEvent = async function (type, x, y, modifiers) {3 const { page } = this._delegate;4 const { x: pageX, y: pageY } = await page.evaluateHandle(5 ({ x, y }) => {6 const { x: pageX, y: pageY } = document.elementFromPoint(x, y);7 return { x: pageX, y: pageY };8 },9 { x, y }10 );11 const eventInit = {12 };13 await page.dispatchEvent(pageX, pageY, 'touchstart', eventInit);14 await page.dispatchEvent(pageX, pageY, 'touchend', eventInit);15};16const { Page } = require('playwright-core/lib/server/page');17Page.prototype._dispatchTouchEvent = async function (type, x, y, modifiers) {18 const { page } = this._delegate;19 const { x: pageX, y: pageY } = await page.evaluateHandle(20 ({ x, y }) => {21 const { x: pageX, y: pageY } = document.elementFromPoint(x, y);22 return { x: pageX, y: pageY };23 },24 { x, y }25 );26 const eventInit = {27 };28 await page.dispatchEvent(pageX, pageY, 'touchstart', eventInit);29 await page.dispatchEvent(pageX, pageY, 'touchend', eventInit);30};31const { chromium } = require('playwright');32(async () => {33 const browser = await chromium.launch({ headless: false });34 const context = await browser.newContext();35 const page = await context.newPage();
Jest + Playwright - Test callbacks of event-based DOM library
firefox browser does not start in playwright
Is it possible to get the selector from a locator object in playwright?
How to run a list of test suites in a single file concurrently in jest?
Running Playwright in Azure Function
firefox browser does not start in playwright
This question is quite close to a "need more focus" question. But let's try to give it some focus:
Does Playwright has access to the cPicker object on the page? Does it has access to the window object?
Yes, you can access both cPicker and the window object inside an evaluate call.
Should I trigger the events from the HTML file itself, and in the callbacks, print in the DOM the result, in some dummy-element, and then infer from that dummy element text that the callbacks fired?
Exactly, or you can assign values to a javascript variable:
const cPicker = new ColorPicker({
onClickOutside(e){
},
onInput(color){
window['color'] = color;
},
onChange(color){
window['result'] = color;
}
})
And then
it('Should call all callbacks with correct arguments', async() => {
await page.goto(`http://localhost:5000/tests/visual/basic.html`, {waitUntil:'load'})
// Wait until the next frame
await page.evaluate(() => new Promise(requestAnimationFrame))
// Act
// Assert
const result = await page.evaluate(() => window['color']);
// Check the value
})
Check out the latest blogs from LambdaTest on this topic:
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!