How to use receiveAsyncResponse method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

commands.js

Source:commands.js Github

copy

Full Screen

1module.exports.commands = {2 "/status": {3 GET: { command: "getStatus" },4 },5 "/session": {6 POST: {7 command: "createSession",8 payloadParams: {9 validate: (jsonObj) =>10 !jsonObj.capabilities &&11 !jsonObj.desiredCapabilities &&12 'we require one of "desiredCapabilities" or "capabilities" object',13 optional: ["desiredCapabilities", "requiredCapabilities", "capabilities"],14 },15 },16 },17 "/sessions": {18 GET: { command: "getSessions" },19 },20 "/session/:sessionId": {21 GET: { command: "getSession" },22 DELETE: { command: "deleteSession" },23 },24 "/session/:sessionId/timeouts": {25 GET: { command: "getTimeouts" }, // W3C route26 POST: {27 command: "timeouts",28 payloadParams: {29 validate: (jsonObj, protocolName) => {30 if (protocolName === PROTOCOLS.W3C) {31 if (32 !util.hasValue(jsonObj.script) &&33 !util.hasValue(jsonObj.pageLoad) &&34 !util.hasValue(jsonObj.implicit)35 ) {36 return "W3C protocol expects any of script, pageLoad or implicit to be set";37 }38 } else {39 if (!util.hasValue(jsonObj.type) || !util.hasValue(jsonObj.ms)) {40 return "MJSONWP protocol requires type and ms";41 }42 }43 },44 optional: ["type", "ms", "script", "pageLoad", "implicit"],45 },46 },47 },48 "/session/:sessionId/timeouts/async_script": {49 POST: { command: "asyncScriptTimeout", payloadParams: { required: ["ms"] } },50 },51 "/session/:sessionId/timeouts/implicit_wait": {52 POST: { command: "implicitWait", payloadParams: { required: ["ms"] } },53 },54 // JSONWP55 "/session/:sessionId/window_handle": {56 GET: { command: "getWindowHandle" },57 },58 // W3C59 "/session/:sessionId/window/handle": {60 GET: { command: "getWindowHandle" },61 },62 // JSONWP63 "/session/:sessionId/window_handles": {64 GET: { command: "getWindowHandles" },65 },66 // W3C67 "/session/:sessionId/window/handles": {68 GET: { command: "getWindowHandles" },69 },70 "/session/:sessionId/url": {71 GET: { command: "getUrl" },72 POST: { command: "setUrl", payloadParams: { required: ["url"] } },73 },74 "/session/:sessionId/forward": {75 POST: { command: "forward" },76 },77 "/session/:sessionId/back": {78 POST: { command: "back" },79 },80 "/session/:sessionId/refresh": {81 POST: { command: "refresh" },82 },83 "/session/:sessionId/execute": {84 POST: { command: "execute", payloadParams: { required: ["script", "args"] } },85 },86 "/session/:sessionId/execute_async": {87 POST: { command: "executeAsync", payloadParams: { required: ["script", "args"] } },88 },89 "/session/:sessionId/screenshot": {90 GET: { command: "getScreenshot" },91 },92 "/session/:sessionId/ime/available_engines": {93 GET: { command: "availableIMEEngines" },94 },95 "/session/:sessionId/ime/active_engine": {96 GET: { command: "getActiveIMEEngine" },97 },98 "/session/:sessionId/ime/activated": {99 GET: { command: "isIMEActivated" },100 },101 "/session/:sessionId/ime/deactivate": {102 POST: { command: "deactivateIMEEngine" },103 },104 "/session/:sessionId/ime/activate": {105 POST: { command: "activateIMEEngine", payloadParams: { required: ["engine"] } },106 },107 "/session/:sessionId/frame": {108 POST: { command: "setFrame", payloadParams: { required: ["id"] } },109 },110 "/session/:sessionId/frame/parent": {111 POST: {},112 },113 "/session/:sessionId/window": {114 GET: { command: "getWindowHandle" },115 POST: {116 command: "setWindow",117 },118 DELETE: { command: "closeWindow" },119 },120 "/session/:sessionId/window/:windowhandle/size": {121 GET: { command: "getWindowSize" },122 POST: {},123 },124 "/session/:sessionId/window/:windowhandle/position": {125 POST: {},126 GET: {},127 },128 "/session/:sessionId/window/:windowhandle/maximize": {129 POST: { command: "maximizeWindow" },130 },131 "/session/:sessionId/cookie": {132 GET: { command: "getCookies" },133 POST: { command: "setCookie", payloadParams: { required: ["cookie"] } },134 DELETE: { command: "deleteCookies" },135 },136 "/session/:sessionId/cookie/:name": {137 GET: { command: "getCookie" },138 DELETE: { command: "deleteCookie" },139 },140 "/session/:sessionId/source": {141 GET: { command: "getPageSource" },142 },143 "/session/:sessionId/title": {144 GET: { command: "title" },145 },146 "/session/:sessionId/element": {147 POST: { command: "findElement", payloadParams: { required: ["using", "value"] } },148 },149 "/session/:sessionId/elements": {150 POST: { command: "findElements", payloadParams: { required: ["using", "value"] } },151 },152 "/session/:sessionId/element/active": {153 GET: { command: "active" }, // W3C: https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-active-element154 POST: { command: "active" },155 },156 "/session/:sessionId/element/:elementId": {157 GET: {},158 },159 "/session/:sessionId/element/:elementId/element": {160 POST: { command: "findElementFromElement", payloadParams: { required: ["using", "value"] } },161 },162 "/session/:sessionId/element/:elementId/elements": {163 POST: { command: "findElementsFromElement", payloadParams: { required: ["using", "value"] } },164 },165 "/session/:sessionId/element/:elementId/click": {166 POST: { command: "click" },167 },168 "/session/:sessionId/element/:elementId/submit": {169 POST: { command: "submit" },170 },171 "/session/:sessionId/element/:elementId/text": {172 GET: { command: "getText" },173 },174 "/session/:sessionId/element/:elementId/value": {175 POST: {176 command: "setValue",177 },178 },179 "/session/:sessionId/keys": {180 POST: { command: "keys", payloadParams: { required: ["value"] } },181 },182 "/session/:sessionId/element/:elementId/name": {183 GET: { command: "getName" },184 },185 "/session/:sessionId/element/:elementId/clear": {186 POST: { command: "clear" },187 },188 "/session/:sessionId/element/:elementId/selected": {189 GET: { command: "elementSelected" },190 },191 "/session/:sessionId/element/:elementId/enabled": {192 GET: { command: "elementEnabled" },193 },194 "/session/:sessionId/element/:elementId/attribute/:name": {195 GET: { command: "getAttribute" },196 },197 "/session/:sessionId/element/:elementId/equals/:otherId": {198 GET: { command: "equalsElement" },199 },200 "/session/:sessionId/element/:elementId/displayed": {201 GET: { command: "elementDisplayed" },202 },203 "/session/:sessionId/element/:elementId/location": {204 GET: { command: "getLocation" },205 },206 "/session/:sessionId/element/:elementId/location_in_view": {207 GET: { command: "getLocationInView" },208 },209 "/session/:sessionId/element/:elementId/size": {210 GET: { command: "getSize" },211 },212 "/session/:sessionId/element/:elementId/css/:propertyName": {213 GET: { command: "getCssProperty" },214 },215 "/session/:sessionId/orientation": {216 GET: { command: "getOrientation" },217 POST: { command: "setOrientation", payloadParams: { required: ["orientation"] } },218 },219 "/session/:sessionId/rotation": {220 GET: { command: "getRotation" },221 POST: { command: "setRotation", payloadParams: { required: ["x", "y", "z"] } },222 },223 "/session/:sessionId/moveto": {224 POST: { command: "moveTo", payloadParams: { optional: ["element", "xoffset", "yoffset"] } },225 },226 "/session/:sessionId/click": {227 POST: { command: "clickCurrent", payloadParams: { optional: ["button"] } },228 },229 "/session/:sessionId/buttondown": {230 POST: { command: "buttonDown", payloadParams: { optional: ["button"] } },231 },232 "/session/:sessionId/buttonup": {233 POST: { command: "buttonUp", payloadParams: { optional: ["button"] } },234 },235 "/session/:sessionId/doubleclick": {236 POST: { command: "doubleClick" },237 },238 "/session/:sessionId/touch/click": {239 POST: { command: "click", payloadParams: { required: ["element"] } },240 },241 "/session/:sessionId/touch/down": {242 POST: { command: "touchDown", payloadParams: { required: ["x", "y"] } },243 },244 "/session/:sessionId/touch/up": {245 POST: { command: "touchUp", payloadParams: { required: ["x", "y"] } },246 },247 "/session/:sessionId/touch/move": {248 POST: { command: "touchMove", payloadParams: { required: ["x", "y"] } },249 },250 "/session/:sessionId/touch/scroll": {251 POST: {},252 },253 "/session/:sessionId/touch/doubleclick": {254 POST: {},255 },256 "/session/:sessionId/actions": {257 POST: { command: "performActions", payloadParams: { required: ["actions"] } },258 DELETE: { command: "releaseActions" },259 },260 "/session/:sessionId/touch/longclick": {261 POST: { command: "touchLongClick", payloadParams: { required: ["elements"] } },262 },263 "/session/:sessionId/touch/flick": {264 POST: {265 command: "flick",266 payloadParams: { optional: ["element", "xspeed", "yspeed", "xoffset", "yoffset", "speed"] },267 },268 },269 "/session/:sessionId/location": {270 GET: { command: "getGeoLocation" },271 POST: { command: "setGeoLocation", payloadParams: { required: ["location"] } },272 },273 "/session/:sessionId/local_storage": {274 GET: {},275 POST: {},276 DELETE: {},277 },278 "/session/:sessionId/local_storage/key/:key": {279 GET: {},280 DELETE: {},281 },282 "/session/:sessionId/local_storage/size": {283 GET: {},284 },285 "/session/:sessionId/session_storage": {286 GET: {},287 POST: {},288 DELETE: {},289 },290 "/session/:sessionId/session_storage/key/:key": {291 GET: {},292 DELETE: {},293 },294 "/session/:sessionId/session_storage/size": {295 GET: {},296 },297 // Selenium 4 clients298 "/session/:sessionId/se/log": {299 POST: { command: "getLog", payloadParams: { required: ["type"] } },300 },301 // Selenium 4 clients302 "/session/:sessionId/se/log/types": {303 GET: { command: "getLogTypes" },304 },305 // mjsonwire, appium clients306 "/session/:sessionId/log": {307 POST: { command: "getLog", payloadParams: { required: ["type"] } },308 },309 // mjsonwire, appium clients310 "/session/:sessionId/log/types": {311 GET: { command: "getLogTypes" },312 },313 "/session/:sessionId/application_cache/status": {314 GET: {},315 },316 //317 // mjsonwire318 //319 "/session/:sessionId/context": {320 GET: { command: "getCurrentContext" },321 POST: { command: "setContext", payloadParams: { required: ["name"] } },322 },323 "/session/:sessionId/contexts": {324 GET: { command: "getContexts" },325 },326 "/session/:sessionId/element/:elementId/pageIndex": {327 GET: { command: "getPageIndex" },328 },329 "/session/:sessionId/network_connection": {330 GET: { command: "getNetworkConnection" },331 POST: { command: "setNetworkConnection", payloadParams: { unwrap: "parameters", required: ["type"] } },332 },333 "/session/:sessionId/touch/perform": {334 POST: { command: "performTouch", payloadParams: { wrap: "actions", required: ["actions"] } },335 },336 "/session/:sessionId/touch/multi/perform": {337 POST: { command: "performMultiAction", payloadParams: { required: ["actions"], optional: ["elementId"] } },338 },339 "/session/:sessionId/receive_async_response": {340 POST: { command: "receiveAsyncResponse", payloadParams: { required: ["status", "value"] } },341 },342 "/session/:sessionId/appium/device/shake": {343 POST: { command: "mobileShake" },344 },345 "/session/:sessionId/appium/device/system_time": {346 GET: { command: "getDeviceTime", payloadParams: { optional: ["format"] } },347 POST: { command: "getDeviceTime", payloadParams: { optional: ["format"] } },348 },349 "/session/:sessionId/appium/device/lock": {350 POST: { command: "lock", payloadParams: { optional: ["seconds"] } },351 },352 "/session/:sessionId/appium/device/unlock": {353 POST: { command: "unlock" },354 },355 "/session/:sessionId/appium/device/is_locked": {356 POST: { command: "isLocked" },357 },358 "/session/:sessionId/appium/start_recording_screen": {359 POST: { command: "startRecordingScreen", payloadParams: { optional: ["options"] } },360 },361 "/session/:sessionId/appium/stop_recording_screen": {362 POST: { command: "stopRecordingScreen", payloadParams: { optional: ["options"] } },363 },364 "/session/:sessionId/appium/performanceData/types": {365 POST: { command: "getPerformanceDataTypes" },366 },367 "/session/:sessionId/appium/getPerformanceData": {368 POST: {369 command: "getPerformanceData",370 payloadParams: { required: ["packageName", "dataType"], optional: ["dataReadTimeout"] },371 },372 },373 "/session/:sessionId/appium/device/press_keycode": {374 POST: { command: "pressKeyCode", payloadParams: { required: ["keycode"], optional: ["metastate", "flags"] } },375 },376 "/session/:sessionId/appium/device/long_press_keycode": {377 POST: { command: "longPressKeyCode", payloadParams: { required: ["keycode"], optional: ["metastate", "flags"] } },378 },379 "/session/:sessionId/appium/device/finger_print": {380 POST: { command: "fingerprint", payloadParams: { required: ["fingerprintId"] } },381 },382 "/session/:sessionId/appium/device/send_sms": {383 POST: { command: "sendSMS", payloadParams: { required: ["phoneNumber", "message"] } },384 },385 "/session/:sessionId/appium/device/gsm_call": {386 POST: { command: "gsmCall", payloadParams: { required: ["phoneNumber", "action"] } },387 },388 "/session/:sessionId/appium/device/gsm_signal": {389 POST: {390 command: "gsmSignal",391 },392 },393 "/session/:sessionId/appium/device/gsm_voice": {394 POST: { command: "gsmVoice", payloadParams: { required: ["state"] } },395 },396 "/session/:sessionId/appium/device/power_capacity": {397 POST: { command: "powerCapacity", payloadParams: { required: ["percent"] } },398 },399 "/session/:sessionId/appium/device/power_ac": {400 POST: { command: "powerAC", payloadParams: { required: ["state"] } },401 },402 "/session/:sessionId/appium/device/network_speed": {403 POST: { command: "networkSpeed", payloadParams: { required: ["netspeed"] } },404 },405 "/session/:sessionId/appium/device/keyevent": {406 POST: { command: "keyevent", payloadParams: { required: ["keycode"], optional: ["metastate"] } },407 },408 "/session/:sessionId/appium/device/rotate": {409 POST: {410 command: "mobileRotation",411 payloadParams: {412 required: ["x", "y", "radius", "rotation", "touchCount", "duration"],413 optional: ["element"],414 },415 },416 },417 "/session/:sessionId/appium/device/current_activity": {418 GET: { command: "getCurrentActivity" },419 },420 "/session/:sessionId/appium/device/current_package": {421 GET: { command: "getCurrentPackage" },422 },423 //region Applications Management424 "/session/:sessionId/appium/device/install_app": {425 POST: {426 command: "installApp",427 payloadParams: {428 required: ["appPath"],429 optional: ["options"],430 },431 },432 },433 "/session/:sessionId/appium/device/activate_app": {434 POST: {435 command: "activateApp",436 payloadParams: {437 required: [["appId"], ["bundleId"]],438 optional: ["options"],439 },440 },441 },442 "/session/:sessionId/appium/device/remove_app": {443 POST: {444 command: "removeApp",445 payloadParams: {446 required: [["appId"], ["bundleId"]],447 optional: ["options"],448 },449 },450 },451 "/session/:sessionId/appium/device/terminate_app": {452 POST: {453 command: "terminateApp",454 payloadParams: {455 required: [["appId"], ["bundleId"]],456 optional: ["options"],457 },458 },459 },460 "/session/:sessionId/appium/device/app_installed": {461 POST: {462 command: "isAppInstalled",463 payloadParams: {464 required: [["appId"], ["bundleId"]],465 },466 },467 },468 "/session/:sessionId/appium/device/app_state": {469 GET: {470 command: "queryAppState",471 payloadParams: {472 required: [["appId"], ["bundleId"]],473 },474 },475 POST: {476 command: "queryAppState",477 payloadParams: {478 required: [["appId"], ["bundleId"]],479 },480 },481 },482 //endregion483 "/session/:sessionId/appium/device/hide_keyboard": {484 POST: { command: "hideKeyboard", payloadParams: { optional: ["strategy", "key", "keyCode", "keyName"] } },485 },486 "/session/:sessionId/appium/device/is_keyboard_shown": {487 GET: { command: "isKeyboardShown" },488 },489 "/session/:sessionId/appium/device/push_file": {490 POST: { command: "pushFile", payloadParams: { required: ["path", "data"] } },491 },492 "/session/:sessionId/appium/device/pull_file": {493 POST: { command: "pullFile", payloadParams: { required: ["path"] } },494 },495 "/session/:sessionId/appium/device/pull_folder": {496 POST: { command: "pullFolder", payloadParams: { required: ["path"] } },497 },498 "/session/:sessionId/appium/device/toggle_airplane_mode": {499 POST: { command: "toggleFlightMode" },500 },501 "/session/:sessionId/appium/device/toggle_data": {502 POST: { command: "toggleData" },503 },504 "/session/:sessionId/appium/device/toggle_wifi": {505 POST: { command: "toggleWiFi" },506 },507 "/session/:sessionId/appium/device/toggle_location_services": {508 POST: { command: "toggleLocationServices" },509 },510 "/session/:sessionId/appium/device/open_notifications": {511 POST: { command: "openNotifications" },512 },513 "/session/:sessionId/appium/device/start_activity": {514 POST: {515 command: "startActivity",516 payloadParams: {517 required: ["appPackage", "appActivity"],518 optional: [519 "appWaitPackage",520 "appWaitActivity",521 "intentAction",522 "intentCategory",523 "intentFlags",524 "optionalIntentArguments",525 "dontStopAppOnReset",526 ],527 },528 },529 },530 "/session/:sessionId/appium/device/system_bars": {531 GET: { command: "getSystemBars" },532 },533 "/session/:sessionId/appium/device/display_density": {534 GET: { command: "getDisplayDensity" },535 },536 "/session/:sessionId/appium/simulator/touch_id": {537 POST: { command: "touchId", payloadParams: { required: ["match"] } },538 },539 "/session/:sessionId/appium/simulator/toggle_touch_id_enrollment": {540 POST: { command: "toggleEnrollTouchId", payloadParams: { optional: ["enabled"] } },541 },542 "/session/:sessionId/appium/app/launch": {543 POST: { command: "launchApp" },544 },545 "/session/:sessionId/appium/app/close": {546 POST: { command: "closeApp" },547 },548 "/session/:sessionId/appium/app/reset": {549 POST: { command: "reset" },550 },551 "/session/:sessionId/appium/app/background": {552 POST: { command: "background", payloadParams: { required: ["seconds"] } },553 },554 "/session/:sessionId/appium/app/end_test_coverage": {555 POST: { command: "endCoverage", payloadParams: { required: ["intent", "path"] } },556 },557 "/session/:sessionId/appium/app/strings": {558 POST: { command: "getStrings", payloadParams: { optional: ["language", "stringFile"] } },559 },560 "/session/:sessionId/appium/element/:elementId/value": {561 POST: {562 command: "setValueImmediate",563 },564 },565 "/session/:sessionId/appium/element/:elementId/replace_value": {566 POST: {567 command: "replaceValue",568 },569 },570 "/session/:sessionId/appium/settings": {571 POST: { command: "updateSettings", payloadParams: { required: ["settings"] } },572 GET: { command: "getSettings" },573 },574 "/session/:sessionId/appium/receive_async_response": {575 POST: { command: "receiveAsyncResponse", payloadParams: { required: ["response"] } },576 },577 "/session/:sessionId/appium/execute_driver": {578 POST: { command: "executeDriverScript", payloadParams: { required: ["script"], optional: ["type", "timeout"] } },579 },580 "/session/:sessionId/appium/events": {581 POST: { command: "getLogEvents", payloadParams: { optional: ["type"] } },582 },583 "/session/:sessionId/appium/log_event": {584 POST: { command: "logCustomEvent", payloadParams: { required: ["vendor", "event"] } },585 },586 /*587 * The W3C spec has some changes to the wire protocol.588 * https://w3c.github.io/webdriver/webdriver-spec.html589 * Begin to add those changes here, keeping the old version590 * since clients still implement them.591 */592 // old alerts593 "/session/:sessionId/alert_text": {594 GET: { command: "getAlertText" },595 POST: {596 command: "setAlertText",597 },598 },599 "/session/:sessionId/accept_alert": {600 POST: { command: "postAcceptAlert" },601 },602 "/session/:sessionId/dismiss_alert": {603 POST: { command: "postDismissAlert" },604 },605 // https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts606 "/session/:sessionId/alert/text": {607 GET: { command: "getAlertText" },608 POST: {609 command: "setAlertText",610 },611 },612 "/session/:sessionId/alert/accept": {613 POST: { command: "postAcceptAlert" },614 },615 "/session/:sessionId/alert/dismiss": {616 POST: { command: "postDismissAlert" },617 },618 // https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect619 "/session/:sessionId/element/:elementId/rect": {620 GET: { command: "getElementRect" },621 },622 "/session/:sessionId/execute/sync": {623 POST: { command: "execute", payloadParams: { required: ["script", "args"] } },624 },625 "/session/:sessionId/execute/async": {626 POST: { command: "executeAsync", payloadParams: { required: ["script", "args"] } },627 },628 // Pre-W3C endpoint for element screenshot629 "/session/:sessionId/screenshot/:elementId": {630 GET: { command: "getElementScreenshot" },631 },632 "/session/:sessionId/element/:elementId/screenshot": {633 GET: { command: "getElementScreenshot" },634 },635 "/session/:sessionId/window/rect": {636 GET: { command: "getWindowRect" },637 POST: { command: "setWindowRect", payloadParams: { required: ["x", "y", "width", "height"] } },638 },639 "/session/:sessionId/window/maximize": {640 POST: { command: "maximizeWindow" },641 },642 "/session/:sessionId/window/minimize": {643 POST: { command: "minimizeWindow" },644 },645 "/session/:sessionId/window/fullscreen": {646 POST: { command: "fullScreenWindow" },647 },648 "/session/:sessionId/element/:elementId/property/:name": {649 GET: { command: "getProperty" },650 },651 "/session/:sessionId/appium/device/set_clipboard": {652 POST: {653 command: "setClipboard",654 payloadParams: {655 required: ["content"],656 optional: ["contentType", "label"],657 },658 },659 },660 "/session/:sessionId/appium/device/get_clipboard": {661 POST: {662 command: "getClipboard",663 payloadParams: {664 optional: ["contentType"],665 },666 },667 },668 "/session/:sessionId/appium/compare_images": {669 POST: {670 command: "compareImages",671 payloadParams: {672 required: ["mode", "firstImage", "secondImage"],673 optional: ["options"],674 },675 },676 },677 // chromium devtools678 // https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc679 "/session/:sessionId/:vendor/cdp/execute": {680 POST: { command: "executeCdp", payloadParams: { required: ["cmd", "params"] } },681 },682 //region Webauthn683 // https://www.w3.org/TR/webauthn-2/#sctn-automation-add-virtual-authenticator684 "/session/:sessionId/webauthn/authenticator": {685 POST: {686 command: "addVirtualAuthenticator",687 payloadParams: {688 required: ["protocol", "transport"],689 optional: ["hasResidentKey", "hasUserVerification", "isUserConsenting", "isUserVerified"],690 },691 },692 },693 "/session/:sessionId/webauthn/authenticator/:authenticatorId": {694 DELETE: {695 command: "removeVirtualAuthenticator",696 },697 },698 "/session/:sessionId/webauthn/authenticator/:authenticatorId/credential": {699 POST: {700 command: "addAuthCredential",701 payloadParams: {702 required: ["credentialId", "isResidentCredential", "rpId", "privateKey"],703 optional: ["userHandle", "signCount"],704 },705 },706 },707 "/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials": {708 GET: { command: "getAuthCredential" },709 DELETE: { command: "removeAllAuthCredentials" },710 },711 "/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials/:credentialId": {712 DELETE: { command: "removeAuthCredential" },713 },714 "/session/:sessionId/webauthn/authenticator/:authenticatorId/uv": {715 POST: {716 command: "setUserAuthVerified",717 payloadParams: {718 required: ["isUserVerified"],719 },720 },721 },722 //endregion...

Full Screen

Full Screen

test_routes.js

Source:test_routes.js Github

copy

Full Screen

1import _ from 'lodash';2// define the routes, mapping of HTTP methods to particular driver commands,3// and any parameters that are expected in a request4// parameters can be `required` or `optional`5const METHOD_MAP = {6 '/wd/hub/status': {7 GET: {command: 'getStatus'}8 },9 '/wd/hub/session': {10 POST: {command: 'createSession', payloadParams: {11 validate: (jsonObj) => (!jsonObj.capabilities && !jsonObj.desiredCapabilities) && 'we require one of "desiredCapabilities" or "capabilities" object',12 optional: ['desiredCapabilities', 'requiredCapabilities', 'capabilities']}}13 },14 '/wd/hub/sessions': {15 GET: {command: 'getSessions'}16},17'/wd/hub/session/:sessionId': {18 GET: {command: 'getSession'},19 DELETE: {command: 'deleteSession'}20},21'/wd/hub/session/:sessionId/timeouts': {22 POST: {command: 'timeouts', payloadParams: {required: ['type', 'ms']}}23},24'/wd/hub/session/:sessionId/timeouts/async_script': {25 POST: {command: 'asyncScriptTimeout', payloadParams: {required: ['ms']}}26},27'/wd/hub/session/:sessionId/timeouts/implicit_wait': {28 POST: {command: 'implicitWait', payloadParams: {required: ['ms']}}29},30'/wd/hub/session/:sessionId/window_handle': {31 GET: {command: 'getWindowHandle'}32},33'/wd/hub/session/:sessionId/window_handles': {34 GET: {command: 'getWindowHandles'}35},36'/wd/hub/session/:sessionId/url': {37 GET: {command: 'getUrl'},38 POST: {command: 'setUrl', payloadParams: {required: ['url']}}39},40'/wd/hub/session/:sessionId/forward': {41 POST: {command: 'forward'}42},43'/wd/hub/session/:sessionId/back': {44 POST: {command: 'back'}45},46'/wd/hub/session/:sessionId/refresh': {47 POST: {command: 'refresh'}48},49'/wd/hub/session/:sessionId/execute': {50 POST: {command: 'execute', payloadParams: {required: ['script', 'args']}}51},52'/wd/hub/session/:sessionId/execute_async': {53 POST: {command: 'executeAsync', payloadParams: {required: ['script', 'args']}}54},55'/wd/hub/session/:sessionId/screenshot': {56 GET: {command: 'getScreenshot'}57},58'/wd/hub/session/:sessionId/ime/available_engines': {59 GET: {command: 'availableIMEEngines'}60},61'/wd/hub/session/:sessionId/ime/active_engine': {62 GET: {command: 'getActiveIMEEngine'}63},64'/wd/hub/session/:sessionId/ime/activated': {65 GET: {command: 'isIMEActivated'}66},67'/wd/hub/session/:sessionId/ime/deactivate': {68 POST: {command: 'deactivateIMEEngine'}69},70'/wd/hub/session/:sessionId/ime/activate': {71 POST: {command: 'activateIMEEngine', payloadParams: {required: ['engine']}}72},73'/wd/hub/session/:sessionId/frame': {74 POST: {command: 'setFrame', payloadParams: {required: ['id']}}75},76'/wd/hub/session/:sessionId/frame/parent': {77 POST: {}78},79'/wd/hub/session/:sessionId/window': {80 POST: {command: 'setWindow', payloadParams: {required: ['name']}},81 DELETE: {command: 'closeWindow'}82},83'/wd/hub/session/:sessionId/window/:windowhandle/size': {84 GET: {command: 'getWindowSize'},85 POST: {}86},87'/wd/hub/session/:sessionId/window/:windowhandle/position': {88 POST: {},89 GET: {}90},91'/wd/hub/session/:sessionId/window/:windowhandle/maximize': {92 POST: {command: 'maximizeWindow'}93},94'/wd/hub/session/:sessionId/cookie': {95 GET: {command: 'getCookies'},96 POST: {command: 'setCookie', payloadParams: {required: ['cookie']}},97 DELETE: {command: 'deleteCookies'}98},99'/wd/hub/session/:sessionId/cookie/:name': {100 DELETE: {command: 'deleteCookie'}101},102'/wd/hub/session/:sessionId/source': {103 GET: {command: 'getPageSource'}104},105'/wd/hub/session/:sessionId/title': {106 GET: {command: 'title'}107},108'/wd/hub/session/:sessionId/element': {109 POST: {command: 'findElement', payloadParams: {required: ['using', 'value']}}110},111'/wd/hub/session/:sessionId/elements': {112 POST: {command: 'findElements', payloadParams: {required: ['using', 'value']}}113},114'/wd/hub/session/:sessionId/element/active': {115 POST: {command: 'active'}116},117'/wd/hub/session/:sessionId/element/:elementId': {118 GET: {}119},120'/wd/hub/session/:sessionId/element/:elementId/element': {121 POST: {command: 'findElementFromElement', payloadParams: {required: ['using', 'value']}}122},123'/wd/hub/session/:sessionId/element/:elementId/elements': {124 POST: {command: 'findElementsFromElement', payloadParams: {required: ['using', 'value']}}125},126'/wd/hub/session/:sessionId/element/:elementId/click': {127 POST: {command: 'click'}128},129'/wd/hub/session/:sessionId/element/:elementId/submit': {130 POST: {command: 'submit'}131},132'/wd/hub/session/:sessionId/element/:elementId/text': {133 GET: {command: 'getText'}134},135'/wd/hub/session/:sessionId/element/:elementId/value': {136 POST: {command: 'setValue', payloadParams: {137 validate: (jsonObj) => {138 return (!jsonObj.value && !jsonObj.text) &&139 'we require one of "text" or "value" params';140 },141 optional: ['value', 'text'],142 makeArgs: (jsonObj) => {143 // override the default argument constructor because of the special144 // logic here. Basically we want to accept either a value (old JSONWP)145 // or a text (new W3C) parameter, but only send one of them to the146 // command (not both). Prefer 'value' since it's more147 // backward-compatible.148 return [jsonObj.value || jsonObj.text];149 }150 }}151},152'/wd/hub/session/:sessionId/keys': {153 POST: {command: 'keys', payloadParams: {required: ['value']}}154},155'/wd/hub/session/:sessionId/element/:elementId/name': {156 GET: {command: 'getName'}157},158'/wd/hub/session/:sessionId/element/:elementId/clear': {159 POST: {command: 'clear'}160},161'/wd/hub/session/:sessionId/element/:elementId/selected': {162 GET: {command: 'elementSelected'}163},164'/wd/hub/session/:sessionId/element/:elementId/enabled': {165 GET: {command: 'elementEnabled'}166},167'/wd/hub/session/:sessionId/element/:elementId/attribute/:name': {168 GET: {command: 'getAttribute'}169},170'/wd/hub/session/:sessionId/element/:elementId/equals/:otherId': {171 GET: {command: 'equalsElement'}172},173'/wd/hub/session/:sessionId/element/:elementId/displayed': {174 GET: {command: 'elementDisplayed'}175},176'/wd/hub/session/:sessionId/element/:elementId/location': {177 GET: {command: 'getLocation'}178},179'/wd/hub/session/:sessionId/element/:elementId/location_in_view': {180 GET: {command: 'getLocationInView'}181},182'/wd/hub/session/:sessionId/element/:elementId/size': {183 GET: {command: 'getSize'}184},185'/wd/hub/session/:sessionId/element/:elementId/css/:propertyName': {186 GET: {command: 'getCssProperty'}187},188'/wd/hub/session/:sessionId/orientation': {189 GET: {command: 'getOrientation'},190 POST: {command: 'setOrientation', payloadParams: {required: ['orientation']}}191},192'/wd/hub/session/:sessionId/rotation': {193 GET: {command: 'getRotation'},194 POST: {command: 'setRotation', payloadParams: {required: ['x', 'y', 'z']}}195},196'/wd/hub/session/:sessionId/moveto': {197 POST: {command: 'moveTo', payloadParams: {optional: ['element', 'xoffset', 'yoffset']}}198},199'/wd/hub/session/:sessionId/click': {200 POST: {command: 'clickCurrent', payloadParams: {optional: ['button']}}201},202'/wd/hub/session/:sessionId/buttondown': {203 POST: {}204},205'/wd/hub/session/:sessionId/buttonup': {206 POST: {}207},208'/wd/hub/session/:sessionId/doubleclick': {209 POST: {}210},211'/wd/hub/session/:sessionId/touch/click': {212 POST: {command: 'click', payloadParams: {required: ['element']}}213},214'/wd/hub/session/:sessionId/touch/down': {215 POST: {command: 'touchDown', payloadParams: {required: ['x', 'y']}}216},217'/wd/hub/session/:sessionId/touch/up': {218 POST: {command: 'touchUp', payloadParams: {required: ['x', 'y']}}219},220'/wd/hub/session/:sessionId/touch/move': {221 POST: {command: 'touchMove', payloadParams: {required: ['x', 'y']}}222},223'/wd/hub/session/:sessionId/touch/scroll': {224 POST: {}225},226'/wd/hub/session/:sessionId/touch/doubleclick': {227 POST: {}228},229'/wd/hub/session/:sessionId/touch/longclick': {230 POST: {command: 'touchLongClick', payloadParams: {required: ['elements']}}231},232'/wd/hub/session/:sessionId/touch/flick': {233 POST: {command: 'flick', payloadParams: {optional: ['element', 'xspeed', 'yspeed', 'xoffset', 'yoffset', 'speed']}}234},235'/wd/hub/session/:sessionId/location': {236 GET: {command: 'getGeoLocation'},237 POST: {command: 'setGeoLocation', payloadParams: {required: ['location']}}238},239'/wd/hub/session/:sessionId/local_storage': {240 GET: {},241 POST: {},242 DELETE: {}243},244'/wd/hub/session/:sessionId/local_storage/key/:key': {245 GET: {},246 DELETE: {}247},248'/wd/hub/session/:sessionId/local_storage/size': {249 GET: {}250},251'/wd/hub/session/:sessionId/session_storage': {252 GET: {},253 POST: {},254 DELETE: {}255},256'/wd/hub/session/:sessionId/session_storage/key/:key': {257 GET: {},258 DELETE: {}259},260'/wd/hub/session/:sessionId/session_storage/size': {261 GET: {}262},263'/wd/hub/session/:sessionId/log': {264 POST: {command: 'getLog', payloadParams: {required: ['type']}}265},266'/wd/hub/session/:sessionId/log/types': {267 GET: {command: 'getLogTypes'}268},269'/wd/hub/session/:sessionId/application_cache/status': {270 GET: {}271},272//273// mjsonwire274//275'/wd/hub/session/:sessionId/context': {276 GET: {command: 'getCurrentContext'},277 POST: {command: 'setContext', payloadParams: {required: ['name']}}278},279'/wd/hub/session/:sessionId/contexts': {280 GET: {command: 'getContexts'}281},282'/wd/hub/session/:sessionId/element/:elementId/pageIndex': {283 GET: {command: 'getPageIndex'}284},285'/wd/hub/session/:sessionId/network_connection': {286 GET: {command: 'getNetworkConnection'},287 POST: {command: 'setNetworkConnection', payloadParams: {unwrap: 'parameters', required: ['type']}}288},289'/wd/hub/session/:sessionId/touch/perform': {290 POST: {command: 'performTouch', payloadParams: {wrap: 'actions', required: ['actions']}}291},292'/wd/hub/session/:sessionId/touch/multi/perform': {293 POST: {command: 'performMultiAction', payloadParams: {required: ['actions'], optional: ['elementId']}}294},295'/wd/hub/session/:sessionId/receive_async_response': {296 POST: {command: 'receiveAsyncResponse', payloadParams: {required: ['status', 'value']}}297},298'/wd/hub/session/:sessionId/appium/device/shake': {299 POST: {command: 'mobileShake'}300},301'/wd/hub/session/:sessionId/appium/device/system_time': {302 GET: {command: 'getDeviceTime'}303},304'/wd/hub/session/:sessionId/appium/device/lock': {305 POST: {command: 'lock', payloadParams: {optional: ['seconds']}}306},307'/wd/hub/session/:sessionId/appium/device/unlock': {308 POST: {command: 'unlock'}309},310'/wd/hub/session/:sessionId/appium/device/is_locked': {311 POST: {command: 'isLocked'}312},313'/wd/hub/session/:sessionId/appium/start_recording_screen': {314 POST: {command: 'startRecordingScreen', payloadParams: {required: ['filePath', 'videoSize', 'timeLimit', 'bitRate']}}315},316'/wd/hub/session/:sessionId/appium/stop_recording_screen': {317 POST: {command: 'stopRecordingScreen'}318},319'/wd/hub/session/:sessionId/appium/performanceData/types': {320 POST: {command: 'getPerformanceDataTypes'}321},322'/wd/hub/session/:sessionId/appium/getPerformanceData': {323 POST: {command: 'getPerformanceData', payloadParams: {required: ['packageName', 'dataType'], optional: ['dataReadTimeout']}}324},325'/wd/hub/session/:sessionId/appium/device/press_keycode': {326 POST: {command: 'pressKeyCode', payloadParams: {required: ['keycode'], optional: ['metastate']}}327},328'/wd/hub/session/:sessionId/appium/device/long_press_keycode': {329 POST: {command: 'longPressKeyCode', payloadParams: {required: ['keycode'], optional: ['metastate']}}330},331'/wd/hub/session/:sessionId/appium/device/finger_print': {332 POST: {command: 'fingerprint', payloadParams: {required: ['fingerprintId']}}333},334'/wd/hub/session/:sessionId/appium/device/send_sms': {335 POST: {command: 'sendSMS', payloadParams: {required: ['phoneNumber', 'message']}}336},337'/wd/hub/session/:sessionId/appium/device/gsm_call': {338 POST: {command: 'gsmCall', payloadParams: {required: ['phoneNumber', 'action']}}339},340'/wd/hub/session/:sessionId/appium/device/gsm_signal': {341 POST: {command: 'gsmSignal', payloadParams: {required: ['signalStrength']}}342},343'/wd/hub/session/:sessionId/appium/device/gsm_voice': {344 POST: {command: 'gsmVoice', payloadParams: {required: ['state']}}345},346'/wd/hub/session/:sessionId/appium/device/power_capacity': {347 POST: {command: 'powerCapacity', payloadParams: {required: ['percent']}}348},349'/wd/hub/session/:sessionId/appium/device/power_ac': {350 POST: {command: 'powerAC', payloadParams: {required: ['state']}}351},352'/wd/hub/session/:sessionId/appium/device/network_speed': {353 POST: {command: 'networkSpeed', payloadParams: {required: ['netspeed']}}354},355'/wd/hub/session/:sessionId/appium/device/keyevent': {356 POST: {command: 'keyevent', payloadParams: {required: ['keycode'], optional: ['metastate']}}357},358'/wd/hub/session/:sessionId/appium/device/rotate': {359 POST: {command: 'mobileRotation', payloadParams: {360 required: ['x', 'y', 'radius', 'rotation', 'touchCount', 'duration'],361 optional: ['element'] }}362},363'/wd/hub/session/:sessionId/appium/device/current_activity': {364 GET: {command: 'getCurrentActivity'}365},366'/wd/hub/session/:sessionId/appium/device/current_package': {367 GET: {command: 'getCurrentPackage'}368},369'/wd/hub/session/:sessionId/appium/device/install_app': {370 POST: {command: 'installApp', payloadParams: {required: ['appPath']}}371},372'/wd/hub/session/:sessionId/appium/device/remove_app': {373 POST: {command: 'removeApp', payloadParams: {required: [['appId'], ['bundleId']]}}374},375'/wd/hub/session/:sessionId/appium/device/app_installed': {376 POST: {command: 'isAppInstalled', payloadParams: {required: ['bundleId']}}377},378'/wd/hub/session/:sessionId/appium/device/hide_keyboard': {379 POST: {command: 'hideKeyboard', payloadParams: {optional: ['strategy', 'key', 'keyCode', 'keyName']}}380},381'/wd/hub/session/:sessionId/appium/device/is_keyboard_shown': {382 GET: {command: 'isKeyboardShown'}383},384'/wd/hub/session/:sessionId/appium/device/push_file': {385 POST: {command: 'pushFile', payloadParams: {required: ['path', 'data']}}386},387'/wd/hub/session/:sessionId/appium/device/pull_file': {388 POST: {command: 'pullFile', payloadParams: {required: ['path']}}389},390'/wd/hub/session/:sessionId/appium/device/pull_folder': {391 POST: {command: 'pullFolder', payloadParams: {required: ['path']}}392},393'/wd/hub/session/:sessionId/appium/device/toggle_airplane_mode': {394 POST: {command: 'toggleFlightMode'}395},396'/wd/hub/session/:sessionId/appium/device/toggle_data': {397 POST: {command: 'toggleData'}398},399'/wd/hub/session/:sessionId/appium/device/toggle_wifi': {400 POST: {command: 'toggleWiFi'}401},402'/wd/hub/session/:sessionId/appium/device/toggle_location_services': {403 POST: {command: 'toggleLocationServices'}404},405'/wd/hub/session/:sessionId/appium/device/open_notifications': {406 POST: {command: 'openNotifications'}407},408'/wd/hub/session/:sessionId/appium/device/start_activity': {409 POST: {command: 'startActivity', payloadParams: {required: ['appPackage', 'appActivity'],410 optional: ['appWaitPackage', 'appWaitActivity',411 'intentAction', 'intentCategory',412 'intentFlags', 'optionalIntentArguments',413 'dontStopAppOnReset']}}414},415'/wd/hub/session/:sessionId/appium/device/system_bars': {416 GET: {command: 'getSystemBars'}417},418'/wd/hub/session/:sessionId/appium/device/display_density': {419 GET: {command: 'getDisplayDensity'}420},421'/wd/hub/session/:sessionId/appium/simulator/touch_id': {422 POST: {command: 'touchId', payloadParams: {required: ['match']}}423},424'/wd/hub/session/:sessionId/appium/simulator/toggle_touch_id_enrollment': {425 POST: {command: 'toggleEnrollTouchId', payloadParams: {optional: ['enabled']}}426},427'/wd/hub/session/:sessionId/appium/app/launch': {428 POST: {command: 'launchApp'}429},430'/wd/hub/session/:sessionId/appium/app/close': {431 POST: {command: 'closeApp'}432},433'/wd/hub/session/:sessionId/appium/app/reset': {434 POST: {command: 'reset'}435},436'/wd/hub/session/:sessionId/appium/app/background': {437 POST: {command: 'background', payloadParams: {required: ['seconds']}}438},439'/wd/hub/session/:sessionId/appium/app/end_test_coverage': {440 POST: {command: 'endCoverage', payloadParams: {required: ['intent', 'path']}}441},442'/wd/hub/session/:sessionId/appium/app/strings': {443 POST: {command: 'getStrings', payloadParams: {optional: ['language', 'stringFile']}}444},445'/wd/hub/session/:sessionId/appium/element/:elementId/value': {446 POST: {command: 'setValueImmediate', payloadParams: {required: ['value']}}447},448'/wd/hub/session/:sessionId/appium/element/:elementId/replace_value': {449 POST: {command: 'replaceValue', payloadParams: {required: ['value']}}450},451'/wd/hub/session/:sessionId/appium/settings': {452 POST: {command: 'updateSettings', payloadParams: {required: ['settings']}},453 GET: {command: 'getSettings'}454},455'/wd/hub/session/:sessionId/appium/receive_async_response': {456 POST: {command: 'receiveAsyncResponse', payloadParams: {required: ['response']}}457},458/*459 * The W3C spec has some changes to the wire protocol.460 * https://w3c.github.io/webdriver/webdriver-spec.html461 * Begin to add those changes here, keeping the old version462 * since clients still implement them.463 */464// old alerts465'/wd/hub/session/:sessionId/alert_text': {466 GET: {command: 'getAlertText'},467 POST: {command: 'setAlertText', payloadParams: {required: ['text']}}468},469'/wd/hub/session/:sessionId/accept_alert': {470 POST: {command: 'postAcceptAlert'}471},472'/wd/hub/session/:sessionId/dismiss_alert': {473 POST: {command: 'postDismissAlert'}474},475// https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts476'/wd/hub/session/:sessionId/alert/text': {477 GET: {command: 'getAlertText'},478 POST: {command: 'setAlertText', payloadParams: {required: ['text']}}479},480'/wd/hub/session/:sessionId/alert/accept': {481 POST: {command: 'postAcceptAlert'}482},483'/wd/hub/session/:sessionId/alert/dismiss': {484 POST: {command: 'postDismissAlert'}485},486// https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect487'/wd/hub/session/:sessionId/element/:elementId/rect': {488 GET: {command: 'getElementRect'}489},490};491// driver command names492let ALL_COMMANDS = [];493for (let v of _.values(METHOD_MAP)) {494 for (let m of _.values(v)) {495 if (m.command) {496 ALL_COMMANDS.push(m.command);497 }498 }499}500const RE_ESCAPE = /[\-\[\]{}()+?.,\\\^$|#\s]/g;501const RE_PARAM = /([:*])(\w+)/g;502class Route {503 constructor (route) {504 this.paramNames = [];505 let reStr = route.replace(RE_ESCAPE, "\\$&");506 reStr = reStr.replace(RE_PARAM, (_, mode, name) => {507 this.paramNames.push(name);508 return mode === ":" ? "([^/]*)" : "(.*)";509 });510 this.routeRegexp = new RegExp(`^${reStr}$`);511 }512 parse (url) {513 let matches = url.match(this.routeRegexp);514 if (!matches) return; // eslint-disable-line curly515 let i = 0;516 let params = {};517 while (i < this.paramNames.length) {518 const paramName = this.paramNames[i++];519 params[paramName] = matches[i];520 }521 return params;522 }523}524function routeToCommandName (endpoint, method) {525 let dstRoute = null;526 const actualEndpoint = _.startsWith(endpoint, '/') ? endpoint : `/${endpoint}`;527 for (let currentRoute of _.keys(METHOD_MAP)) {528 const route = new Route(currentRoute);529 // we don't care about the actual session id for matching530 if (route.parse(`/wd/hub/session/ignored-session-id${actualEndpoint}`) ||531 route.parse(`/wd/hub${actualEndpoint}`) || route.parse(actualEndpoint)) {532 dstRoute = currentRoute;533 break;534 }535 }536 if (!dstRoute) return; // eslint-disable-line curly537 const methods = _.get(METHOD_MAP, dstRoute);538 if (_.has(methods, method)) {539 const dstMethod = _.get(methods, method);540 if (dstMethod.command) {541 return dstMethod.command;542 }543 }544}545// driver commands that do not require a session to already exist546const NO_SESSION_ID_COMMANDS = ['createSession', 'getStatus', 'getSessions'];...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...184 }185 async executeCommand (cmd, ...args) {186 if (cmd === 'receiveAsyncResponse') {187 logger.debug(`Executing YouiEngineDriver response '${cmd}'`);188 return await this.receiveAsyncResponse(...args);189 }190 if (this.ready) {191 if (this.driverShouldDoProxyCmd(cmd)) {192 logger.debug(`Executing proxied WebDriver command '${cmd}'`);193 // Manually handle our own YOUI_APP context194 if (cmd === 'setContext' && args[0] === 'YOUI_APP') {195 this.proxyAll = false;196 return await this.executeCommand(cmd, ...args);197 }198 // There are 2 CommandTimeout (YouiEngineDriver and proxy)199 // Only YouiEngineDriver CommandTimeout is used; Proxy is disabled200 // All proxy commands needs to reset the YouiEngineDriver CommandTimeout201 // Here we manually reset the YouiEngineDriver CommandTimeout for commands that goe to proxy.202 this.clearNewCommandTimeout();...

Full Screen

Full Screen

routes.js

Source:routes.js Github

copy

Full Screen

1import _ from 'lodash';2// define the routes, mapping of HTTP methods to particular driver commands,3// and any parameters that are expected in a request4// parameters can be `required` or `optional`5const METHOD_MAP = {6 '/wd/hub/status': {7 GET: {command: 'getStatus'}8 },9 '/wd/hub/session': {10 POST: {command: 'createSession', payloadParams: {required: ['desiredCapabilities'], optional: ['requiredCapabilities']}}11 },12 '/wd/hub/sessions': {13 GET: {command: 'getSessions'}14 },15 '/wd/hub/session/:sessionId': {16 GET: {command: 'getSession'},17 DELETE: {command: 'deleteSession'}18 },19 '/wd/hub/session/:sessionId/timeouts': {20 POST: {command: 'timeouts', payloadParams: {required: ['type', 'ms']}}21 },22 '/wd/hub/session/:sessionId/timeouts/async_script': {23 POST: {command: 'asyncScriptTimeout', payloadParams: {required: ['ms']}}24 },25 '/wd/hub/session/:sessionId/timeouts/implicit_wait': {26 POST: {command: 'implicitWait', payloadParams: {required: ['ms']}}27 },28 '/wd/hub/session/:sessionId/window_handle': {29 GET: {command: 'getWindowHandle'}30 },31 '/wd/hub/session/:sessionId/window_handles': {32 GET: {command: 'getWindowHandles'}33 },34 '/wd/hub/session/:sessionId/url': {35 GET: {command: 'getUrl'},36 POST: {command: 'setUrl', payloadParams: {required: ['url']}}37 },38 '/wd/hub/session/:sessionId/forward': {39 POST: {command: 'forward'}40 },41 '/wd/hub/session/:sessionId/back': {42 POST: {command: 'back'}43 },44 '/wd/hub/session/:sessionId/refresh': {45 POST: {command: 'refresh'}46 },47 '/wd/hub/session/:sessionId/execute': {48 POST: {command: 'execute', payloadParams: {required: ['script', 'args']}}49 },50 '/wd/hub/session/:sessionId/execute_async': {51 POST: {command: 'executeAsync', payloadParams: {required: ['script', 'args']}}52 },53 '/wd/hub/session/:sessionId/screenshot': {54 GET: {command: 'getScreenshot'}55 },56 '/wd/hub/session/:sessionId/ime/available_engines': {57 GET: {command: 'availableIMEEngines'}58 },59 '/wd/hub/session/:sessionId/ime/active_engine': {60 GET: {command: 'getActiveIMEEngine'}61 },62 '/wd/hub/session/:sessionId/ime/activated': {63 GET: {command: 'isIMEActivated'}64 },65 '/wd/hub/session/:sessionId/ime/deactivate': {66 POST: {command: 'deactivateIMEEngine'}67 },68 '/wd/hub/session/:sessionId/ime/activate': {69 POST: {command: 'activateIMEEngine', payloadParams: {required: ['engine']}}70 },71 '/wd/hub/session/:sessionId/frame': {72 POST: {command: 'setFrame', payloadParams: {required: ['id']}}73 },74 '/wd/hub/session/:sessionId/frame/parent': {75 POST: {}76 },77 '/wd/hub/session/:sessionId/window': {78 POST: {command: 'setWindow', payloadParams: {required: ['name']}},79 DELETE: {command: 'closeWindow'}80 },81 '/wd/hub/session/:sessionId/window/:windowhandle/size': {82 GET: {command: 'getWindowSize'},83 POST: {}84 },85 '/wd/hub/session/:sessionId/window/:windowhandle/position': {86 POST: {},87 GET: {}88 },89 '/wd/hub/session/:sessionId/window/:windowhandle/maximize': {90 POST: {command: 'maximizeWindow'}91 },92 '/wd/hub/session/:sessionId/cookie': {93 GET: {command: 'getCookies'},94 POST: {command: 'setCookie', payloadParams: {required: ['cookie']}},95 DELETE: {command: 'deleteCookies'}96 },97 '/wd/hub/session/:sessionId/cookie/:name': {98 DELETE: {command: 'deleteCookie'}99 },100 '/wd/hub/session/:sessionId/source': {101 GET: {command: 'getPageSource'}102 },103 '/wd/hub/session/:sessionId/title': {104 GET: {command: 'title'}105 },106 '/wd/hub/session/:sessionId/element': {107 POST: {command: 'findElement', payloadParams: {required: ['using', 'value']}}108 },109 '/wd/hub/session/:sessionId/elements': {110 POST: {command: 'findElements', payloadParams: {required: ['using', 'value']}}111 },112 '/wd/hub/session/:sessionId/element/active': {113 POST: {command: 'active'}114 },115 '/wd/hub/session/:sessionId/element/:elementId': {116 GET: {}117 },118 '/wd/hub/session/:sessionId/element/:elementId/element': {119 POST: {command: 'findElementFromElement', payloadParams: {required: ['using', 'value']}}120 },121 '/wd/hub/session/:sessionId/element/:elementId/elements': {122 POST: {command: 'findElementsFromElement', payloadParams: {required: ['using', 'value']}}123 },124 '/wd/hub/session/:sessionId/element/:elementId/click': {125 POST: {command: 'click'}126 },127 '/wd/hub/session/:sessionId/element/:elementId/submit': {128 POST: {command: 'submit'}129 },130 '/wd/hub/session/:sessionId/element/:elementId/text': {131 GET: {command: 'getText'}132 },133 '/wd/hub/session/:sessionId/element/:elementId/value': {134 POST: {command: 'setValue', payloadParams: {required: ['value']}}135 },136 '/wd/hub/session/:sessionId/keys': {137 POST: {command: 'keys', payloadParams: {required: ['value']}}138 },139 '/wd/hub/session/:sessionId/element/:elementId/name': {140 GET: {command: 'getName'}141 },142 '/wd/hub/session/:sessionId/element/:elementId/clear': {143 POST: {command: 'clear'}144 },145 '/wd/hub/session/:sessionId/element/:elementId/selected': {146 GET: {command: 'elementSelected'}147 },148 '/wd/hub/session/:sessionId/element/:elementId/enabled': {149 GET: {command: 'elementEnabled'}150 },151 '/wd/hub/session/:sessionId/element/:elementId/attribute/:name': {152 GET: {command: 'getAttribute'}153 },154 '/wd/hub/session/:sessionId/element/:elementId/equals/:otherId': {155 GET: {command: 'equalsElement'}156 },157 '/wd/hub/session/:sessionId/element/:elementId/displayed': {158 GET: {command: 'elementDisplayed'}159 },160 '/wd/hub/session/:sessionId/element/:elementId/location': {161 GET: {command: 'getLocation'}162 },163 '/wd/hub/session/:sessionId/element/:elementId/location_in_view': {164 GET: {command: 'getLocationInView'}165 },166 '/wd/hub/session/:sessionId/element/:elementId/size': {167 GET: {command: 'getSize'}168 },169 '/wd/hub/session/:sessionId/element/:elementId/css/:propertyName': {170 GET: {command: 'getCssProperty'}171 },172 '/wd/hub/session/:sessionId/orientation': {173 GET: {command: 'getOrientation'},174 POST: {command: 'setOrientation', payloadParams: {required: ['orientation']}}175 },176 '/wd/hub/session/:sessionId/alert_text': {177 GET: {command: 'getAlertText'},178 POST: {command: 'setAlertText', payloadParams: {required: ['text']}}179 },180 '/wd/hub/session/:sessionId/accept_alert': {181 POST: {command: 'postAcceptAlert'}182 },183 '/wd/hub/session/:sessionId/dismiss_alert': {184 POST: {command: 'postDismissAlert'}185 },186 '/wd/hub/session/:sessionId/moveto': {187 POST: {command: 'moveTo', payloadParams: {optional: ['element', 'xoffset', 'yoffset']}}188 },189 '/wd/hub/session/:sessionId/click': {190 POST: {command: 'clickCurrent', payloadParams: {optional: ['button']}}191 },192 '/wd/hub/session/:sessionId/buttondown': {193 POST: {}194 },195 '/wd/hub/session/:sessionId/buttonup': {196 POST: {}197 },198 '/wd/hub/session/:sessionId/doubleclick': {199 POST: {}200 },201 '/wd/hub/session/:sessionId/touch/click': {202 POST: {command: 'click', payloadParams: {required: ['element']}}203 },204 '/wd/hub/session/:sessionId/touch/down': {205 POST: {command: 'touchDown', payloadParams: {required: ['x', 'y']}}206 },207 '/wd/hub/session/:sessionId/touch/up': {208 POST: {command: 'touchUp', payloadParams: {required: ['x', 'y']}}209 },210 '/wd/hub/session/:sessionId/touch/move': {211 POST: {command: 'touchMove', payloadParams: {required: ['x', 'y']}}212 },213 '/wd/hub/session/:sessionId/touch/scroll': {214 POST: {}215 },216 '/wd/hub/session/:sessionId/touch/doubleclick': {217 POST: {}218 },219 '/wd/hub/session/:sessionId/touch/longclick': {220 POST: {command: 'touchLongClick', payloadParams: {required: ['elements']}}221 },222 '/wd/hub/session/:sessionId/touch/flick': {223 POST: {command: 'flick', payloadParams: {optional: ['element', 'xspeed', 'yspeed', 'xoffset', 'yoffset', 'speed']}}224 },225 '/wd/hub/session/:sessionId/location': {226 GET: {command: 'getGeoLocation'},227 POST: {command: 'setGeoLocation', payloadParams: {required: ['location']}}228 },229 '/wd/hub/session/:sessionId/local_storage': {230 GET: {},231 POST: {},232 DELETE: {}233 },234 '/wd/hub/session/:sessionId/local_storage/key/:key': {235 GET: {},236 DELETE: {}237 },238 '/wd/hub/session/:sessionId/local_storage/size': {239 GET: {}240 },241 '/wd/hub/session/:sessionId/session_storage': {242 GET: {},243 POST: {},244 DELETE: {}245 },246 '/wd/hub/session/:sessionId/session_storage/key/:key': {247 GET: {},248 DELETE: {}249 },250 '/wd/hub/session/:sessionId/session_storage/size': {251 GET: {}252 },253 '/wd/hub/session/:sessionId/log': {254 POST: {command: 'getLog', payloadParams: {required: ['type']}}255 },256 '/wd/hub/session/:sessionId/log/types': {257 GET: {command: 'getLogTypes'}258 },259 '/wd/hub/session/:sessionId/application_cache/status': {260 GET: {}261 },262 //263 // mjsonwire264 //265 '/wd/hub/session/:sessionId/context': {266 GET: {command: 'getCurrentContext'},267 POST: {command: 'setContext', payloadParams: {required: ['name']}}268 },269 '/wd/hub/session/:sessionId/contexts': {270 GET: {command: 'getContexts'}271 },272 '/wd/hub/session/:sessionId/element/:elementId/pageIndex': {273 GET: {command: 'getPageIndex'}274 },275 '/wd/hub/session/:sessionId/network_connection': {276 GET: {command: 'getNetworkConnection'},277 POST: {command: 'setNetworkConnection', payloadParams: {unwrap: 'parameters', required: ['type']}}278 },279 '/wd/hub/session/:sessionId/touch/perform': {280 POST: {command: 'performTouch', payloadParams: {wrap: 'actions', required: ['actions']}}281 },282 '/wd/hub/session/:sessionId/touch/multi/perform': {283 POST: {command: 'performMultiAction', payloadParams: {required: ['actions'], optional: ['elementId']}}284 },285 '/wd/hub/session/:sessionId/receive_async_response': {286 POST: {command: 'receiveAsyncResponse', payloadParams: {required: ['status', 'value']}}287 },288 '/wd/hub/session/:sessionId/appium/device/shake': {289 POST: {command: 'mobileShake'}290 },291 '/wd/hub/session/:sessionId/appium/device/system_time': {292 GET: {command: 'getDeviceTime'}293 },294 '/wd/hub/session/:sessionId/appium/device/lock': {295 POST: {command: 'lock', payloadParams: {optional: ['seconds']}}296 },297 '/wd/hub/session/:sessionId/appium/device/unlock': {298 POST: {command: 'unlock'}299 },300 '/wd/hub/session/:sessionId/appium/device/is_locked': {301 POST: {command: 'isLocked'}302 },303 '/wd/hub/session/:sessionId/appium/device/press_keycode': {304 POST: {command: 'pressKeyCode', payloadParams: {required: ['keycode'], optional: ['metastate']}}305 },306 '/wd/hub/session/:sessionId/appium/device/long_press_keycode': {307 POST: {command: 'longPressKeyCode', payloadParams: {required: ['keycode'], optional: ['metastate']}}308 },309 '/wd/hub/session/:sessionId/appium/device/keyevent': {310 POST: {command: 'keyevent', payloadParams: {required: ['keycode'], optional: ['metastate']}}311 },312 '/wd/hub/session/:sessionId/appium/device/rotate': {313 POST: {command: 'mobileRotation', payloadParams: {314 required: ['x', 'y', 'radius', 'rotation', 'touchCount', 'duration'],315 optional: ['element'] }}316 },317 '/wd/hub/session/:sessionId/appium/device/current_activity': {318 GET: {command: 'getCurrentActivity'}319 },320 '/wd/hub/session/:sessionId/appium/device/install_app': {321 POST: {command: 'installApp', payloadParams: {required: ['appPath']}}322 },323 '/wd/hub/session/:sessionId/appium/device/remove_app': {324 POST: {command: 'removeApp', payloadParams: {required: [['appId'], ['bundleId']]}}325 },326 '/wd/hub/session/:sessionId/appium/device/app_installed': {327 POST: {command: 'isAppInstalled', payloadParams: {required: ['bundleId']}}328 },329 '/wd/hub/session/:sessionId/appium/device/hide_keyboard': {330 POST: {command: 'hideKeyboard', payloadParams: {optional: ['strategy', 'key', 'keyCode', 'keyName']}}331 },332 '/wd/hub/session/:sessionId/appium/device/push_file': {333 POST: {command: 'pushFile', payloadParams: {required: ['path', 'data']}}334 },335 '/wd/hub/session/:sessionId/appium/device/pull_file': {336 POST: {command: 'pullFile', payloadParams: {required: ['path']}}337 },338 '/wd/hub/session/:sessionId/appium/device/pull_folder': {339 POST: {command: 'pullFolder', payloadParams: {required: ['path']}}340 },341 '/wd/hub/session/:sessionId/appium/device/toggle_airplane_mode': {342 POST: {command: 'toggleFlightMode'}343 },344 '/wd/hub/session/:sessionId/appium/device/toggle_data': {345 POST: {command: 'toggleData'}346 },347 '/wd/hub/session/:sessionId/appium/device/toggle_wifi': {348 POST: {command: 'toggleWiFi'}349 },350 '/wd/hub/session/:sessionId/appium/device/toggle_location_services': {351 POST: {command: 'toggleLocationServices'}352 },353 '/wd/hub/session/:sessionId/appium/device/open_notifications': {354 POST: {command: 'openNotifications'}355 },356 '/wd/hub/session/:sessionId/appium/device/start_activity': {357 POST: {command: 'startActivity', payloadParams: {required: ['appPackage', 'appActivity'],358 optional: ['appWaitPackage', 'appWaitActivity',359 'intentAction', 'intentCategory',360 'intentFlags', 'optionalIntentArguments',361 'dontStopAppOnReset']}}362 },363 '/wd/hub/session/:sessionId/appium/simulator/touch_id': {364 POST: {command: 'touchId', payloadParams: {required: ['match']}}365 },366 '/wd/hub/session/:sessionId/appium/app/launch': {367 POST: {command: 'launchApp'}368 },369 '/wd/hub/session/:sessionId/appium/app/close': {370 POST: {command: 'closeApp'}371 },372 '/wd/hub/session/:sessionId/appium/app/reset': {373 POST: {command: 'reset'}374 },375 '/wd/hub/session/:sessionId/appium/app/background': {376 POST: {command: 'background', payloadParams: {required: ['seconds']}}377 },378 '/wd/hub/session/:sessionId/appium/app/end_test_coverage': {379 POST: {command: 'endCoverage', payloadParams: {required: ['intent', 'path']}}380 },381 '/wd/hub/session/:sessionId/appium/app/strings': {382 POST: {command: 'getStrings', payloadParams: {optional: ['language', 'stringFile']}}383 },384 '/wd/hub/session/:sessionId/appium/element/:elementId/value': {385 POST: {command: 'setValueImmediate', payloadParams: {required: ['value']}}386 },387 '/wd/hub/session/:sessionId/appium/element/:elementId/replace_value': {388 POST: {command: 'replaceValue', payloadParams: {required: ['value']}}389 },390 '/wd/hub/session/:sessionId/appium/settings': {391 POST: {command: 'updateSettings', payloadParams: {required: ['settings']}},392 GET: {command: 'getSettings'}393 },394 '/wd/hub/session/:sessionId/appium/receive_async_response': {395 POST: {command: 'receiveAsyncResponse', payloadParams: {required: ['response']}}396 }397};398// driver command names399let ALL_COMMANDS = [];400for (let v of _.values(METHOD_MAP)) {401 for(let m of _.values(v)) {402 if(m.command) {403 ALL_COMMANDS.push(m.command);404 }405 }406}407// driver commands that do not require a session to already exist408const NO_SESSION_ID_COMMANDS = ['createSession', 'getStatus', 'getSessions'];...

Full Screen

Full Screen

firefoxos.js

Source:firefoxos.js Github

copy

Full Screen

1"use strict";2var errors = require('../../server/errors.js')3 , _ = require('underscore')4 , Device = require('../device.js')5 , logger = require('../../server/logger.js').get('appium')6 , net = require('net')7 , deviceCommon = require('../common.js')8 , status = require("../../server/status.js")9 , getAtomSrc = require('./firefoxos-atoms.js').get10 , async = require('async')11 , NotYetImplementedError = errors.NotYetImplementedError;12var Firefox = function () {13 this.init();14};15_.extend(Firefox.prototype, Device.prototype);16Firefox.prototype._deviceInit = Device.prototype.init;17Firefox.prototype.init = function () {18 this._deviceInit();19 this.capabilities = {20 platform: 'LINUX'21 , browserName: 'FirefoxOS'22 , platformVersion: '18.0'23 , webStorageEnabled: false24 , takesScreenshot: true25 , javascriptEnabled: true26 , databaseEnabled: false27 };28 this.queue = [];29 this.progress = 0;30 this.onStop = function () {};31 this.implicitWaitMs = 0;32 this.commandTimeoutMs = 60 * 1000;33 this.origCommandTimeoutMs = this.commandTimeoutMs;34 this.commandTimeout = null;35 this.asyncWaitMs = 0;36 this.onConnect = null;37 this.hasConnected = false;38 this.fromActor = null;39 this.socket = null;40 this.receiveStream = null;41 this.expectedRcvBytes = null;42 this.lastCmd = null;43 this.initCommandMap();44};45Firefox.prototype._deviceConfigure = Device.prototype.configure;46Firefox.prototype.configure = function (args, caps, cb) {47 this._deviceConfigure(args, caps);48 this.args.systemPort = 2828;49 cb();50};51Firefox.prototype.start = function (cb, onDie) {52 this.socket = new net.Socket();53 this.socket.on('close', function () {54 onDie(0);55 });56 this.socket.on('data', this.receive.bind(this));57 this.socket.connect(this.args.systemPort, 'localhost', function () { });58 this.onConnect = function () {59 logger.debug("Firefox OS socket connected");60 var mainCb = cb;61 async.waterfall([62 function (cb) { this.getMarionetteId(cb); }.bind(this),63 function (cb) { this.createSession(cb); }.bind(this),64 function (cb) { this.launchAppByName(cb); }.bind(this),65 function (frameId, cb) { this.frame(frameId, cb); }.bind(this)66 ], function () { mainCb(null, this.sessionId); }.bind(this));67 };68};69Firefox.prototype.stop = function (cb) {70 logger.debug("Stopping firefoxOs connection");71 this.proxy({type: 'deleteSession'}, function (err) {72 if (err) return cb(err);73 this.socket.destroy();74 cb(0);75 }.bind(this));76};77Firefox.prototype.getMarionetteId = function (cb) {78 logger.debug("Getting marionette id");79 this.proxy({type: 'getMarionetteID'}, function (err, res) {80 if (err) return cb(err);81 this.fromActor = res.id;82 cb(null);83 }.bind(this));84};85Firefox.prototype.createSession = function (cb) {86 logger.debug("Creating firefox os session");87 this.proxy({type: 'newSession'}, function (err, res) {88 if (err) return cb(err);89 this.sessionId = res.value;90 cb(null);91 }.bind(this));92};93Firefox.prototype.launchAppByName = function (cb) {94 logger.debug("Launching our app by its name");95 var atomSrc = getAtomSrc('gaia_apps');96 var wrappedScript = atomSrc +97 ";GaiaApps.launchWithName('" + this.args.app + "');";98 var cmd = {99 type: 'executeAsyncScript'100 , args: []101 , newSandbox: true102 , specialPowers: false103 , value: wrappedScript104 };105 this.proxy(cmd, function (err, res) {106 if (err) return cb(err);107 cb(null, res.value.frame.ELEMENT);108 });109};110Firefox.prototype.receive = function (data) {111 var parts, bytes, jsonData;112 if (this.receiveStream) {113 this.receiveStream += data.toString();114 logger.debug(data.length + " b more data received, adding to stream (" + this.receiveStream.length + " b)");115 try {116 data = JSON.parse(this.receiveStream);117 this.receiveStream = null;118 } catch (e) {119 logger.debug("Stream still not complete, waiting");120 return;121 }122 } else {123 parts = data.toString().split(":");124 bytes = parseInt(parts[0], 10);125 logger.debug("Data received, looking for " + bytes + " bytes");126 jsonData = parts.slice(1).join(":");127 try {128 data = JSON.parse(jsonData);129 } catch (e) {130 logger.debug("Data did not parse, waiting for more");131 this.receiveStream = jsonData;132 return;133 }134 }135 logger.debug(JSON.stringify(data));136 if (!this.hasConnected) {137 this.hasConnected = true;138 this.fromActor = data.from;139 this.onConnect();140 } else if (this.cbForCurrentCmd) {141 var cb = this.cbForCurrentCmd;142 this.progress--;143 this.cbForCurrentCmd = null;144 if (typeof cb === 'function') {145 this.respond(data, cb);146 }147 this.executeNextCommand();148 }149};150Firefox.prototype.proxy = deviceCommon.proxy;151Firefox.prototype.getSettings = deviceCommon.getSettings;152Firefox.prototype.updateSettings = deviceCommon.updateSettings;153Firefox.prototype.push = function (elem) {154 this.queue.push(elem);155 this.executeNextCommand();156};157Firefox.prototype.respond = function (data, cb) {158 if (typeof data.error !== "undefined") {159 cb(new Error(data.error.message));160 } else if (typeof data.id !== "undefined") {161 cb(null, data);162 } else {163 cb(null, {164 status: status.codes.Success.code165 , value: data.value166 });167 }168};169Firefox.prototype.executeNextCommand = function () {170 if (this.queue.length <= 0 || this.progress > 0) {171 return;172 }173 var target = this.queue.shift()174 , command = target[0]175 , cb = target[1];176 this.cbForCurrentCmd = cb;177 this.progress++;178 command.to = this.fromActor;179 var cmdStr = JSON.stringify(command);180 cmdStr = cmdStr.length + ':' + cmdStr;181 logger.debug("Sending command to firefoxOs: " + cmdStr);182 this.socket.write(cmdStr);183};184Firefox.prototype.cmdMap = function () {185 var elFn = function (elId) { return {element: elId }; };186 return {187 implicitWait: ['setSearchTimeout']188 , getUrl: ['getUrl']189 , findElement: ['findElement', function (strategy, selector) {190 return {191 using: strategy,192 value: selector193 };194 }, function (err, res, cb) {195 if (err) return cb(err);196 res.value = {ELEMENT: res.value};197 cb(null, res);198 }]199 , click: ['clickElement', elFn]200 , setValue: ['sendKeysToElement', function (elId, val) {201 return {202 element: elId203 , value: val.split("")204 };205 }]206 , getText: ['getElementText', elFn]207 , getPageSource: ['getPageSource']208 , execute: ['executeScript', function (script, params) {209 return {210 value: script211 , args: params212 };213 }]214 , frame: ['switchToFrame', elFn]215 };216};217Firefox.prototype.notImplementedCmds = function () {218 return [219 'equalsWebElement'220 , 'findElements'221 , 'findElementFromElement'222 , 'findElementsFromElement'223 , 'complexTap'224 , 'flick'225 , 'touchLongClick'226 , 'touchDown'227 , 'touchUp'228 , 'touchMove'229 , 'swipe'230 , 'hideKeyboard'231 , 'clear'232 , 'getName'233 , 'getAttribute'234 , 'getCssProperty'235 , 'getLocation'236 , 'getSize'237 , 'getWindowSize'238 , 'getPageIndex'239 , 'pressKeyCode'240 , 'longPressKeyCode'241 , 'keyevent'242 , 'back'243 , 'forward'244 , 'refresh'245 , 'keys'246 , 'leaveWebView'247 , 'elementDisplayed'248 , 'elementEnabled'249 , 'elementSelected'250 , 'getAlertText'251 , 'setAlertText'252 , 'postAcceptAlert'253 , 'postDismissAlert'254 , 'asyncScriptTimeout'255 , 'setOrientation'256 , 'getOrientation'257 , 'moveTo'258 , 'clickCurrent'259 , 'fakeFlickElement'260 , 'executeAsync'261 , 'title'262 , 'submit'263 , 'url'264 , 'active'265 , 'getWindowHandle'266 , 'setWindow'267 , 'closeWindow'268 , 'getWindowHandles'269 , 'receiveAsyncResponse'270 , 'setValueImmediate'271 , 'getCookies'272 , 'setCookie'273 , 'deleteCookie'274 , 'deleteCookies'275 , 'getCurrentActivity'276 ];277};278Firefox.prototype.initCommandMap = function () {279 var nyiCmds = this.notImplementedCmds();280 // create controller functions dynamically for implemented commands281 _.each(this.cmdMap(), function (cmdInfo, controller) {282 if (_.contains(nyiCmds, controller)) {283 throw new Error("Controller " + controller + " is listed in both " +284 "implemented and not-yet-implemented lists. Fix this " +285 "before moving on!");286 }287 this[controller] = function () {288 var args = Array.prototype.slice.call(arguments, 0);289 var cb;290 var outerCb = args[args.length - 1];291 if (typeof cmdInfo[2] === 'function') {292 cb = function (err, res) {293 cmdInfo[2](err, res, outerCb);294 };295 } else {296 cb = outerCb;297 }298 args = args.slice(0, args.length - 1);299 var cmd = {300 type: cmdInfo[0]301 };302 if (typeof cmdInfo[1] === 'function') {303 cmd = _.extend(cmd, cmdInfo[1].apply(this, args));304 } else if (typeof cmdInfo[1] === "undefined" && args.length > 0) {305 cmd = _.extend(cmd, {value: args[0]});306 }307 this.proxy(cmd, cb);308 }.bind(this);309 }.bind(this));310 // throw not yet implemented for any command in nyi list311 _.each(nyiCmds, function (controller) {312 this[controller] = function () {313 var args = Array.prototype.slice.call(arguments, 0);314 var cb = args[args.length - 1];315 cb(new NotYetImplementedError(), null);316 }.bind(this);317 }.bind(this));318};...

Full Screen

Full Screen

execute.js

Source:execute.js Github

copy

Full Screen

1import { errors, errorFromCode, errorFromW3CJsonCode } from 'appium-base-driver';2import _ from 'lodash';3import url from 'url';4import { util } from 'appium-support';5import logger from '../logger';6import { installSSLCert, uninstallSSLCert } from 'appium-ios-simulator';7import { startHttpsServer } from '../server';8let commands = {}, helpers = {}, extensions = {};9commands.execute = async function execute (script, args) {10 if (script.match(/^mobile:/)) {11 script = script.replace(/^mobile:/, '').trim();12 return await this.executeMobile(script, _.isArray(args) ? args[0] : args);13 } else {14 if (this.isWebContext()) {15 args = this.convertElementsForAtoms(args);16 return await this.executeAtom('execute_script', [script, args]);17 } else {18 return await this.uiAutoClient.sendCommand(script);19 }20 }21};22commands.executeAsync = async function executeAsync (script, args, sessionId) {23 if (!this.isWebContext()) {24 return await this.uiAutoClient.sendCommand(script);25 }26 let address = this.opts.callbackAddress || this.opts.address;27 let port = this.opts.callbackPort || this.opts.port;28 sessionId = sessionId || this.sessionId;29 // https sites need to reply to an https endpoint, in Safari30 let protocol = 'http:';31 try {32 let currentUrl = url.parse(await this.getUrl());33 if (currentUrl.protocol === 'https:' && this.opts.httpsCallbackPort && this.opts.httpsCallbackAddress) {34 protocol = currentUrl.protocol;35 port = this.opts.httpsCallbackPort;36 address = this.opts.httpsCallbackAddress;37 }38 } catch (ign) {}39 let responseUrl = `${protocol}//${address}:${port}/wd/hub/session/${sessionId}/receive_async_response`;40 if (this.isRealDevice()) {41 let defaultHost = this.opts.address;42 let urlObject = url.parse(responseUrl);43 if (urlObject.hostname === defaultHost) {44 logger.debug('Real device safari test and no custom callback address ' +45 'set, changing callback address to local ip.');46 urlObject.hostname = util.localIp();47 urlObject.host = null; // set to null, otherwise hostname is ignored48 responseUrl = url.format(urlObject);49 } else {50 logger.debug('Custom callback address set, leaving as is.');51 }52 }53 logger.debug(`Response url for executeAsync: ${responseUrl}`);54 args = this.convertElementsForAtoms(args);55 this.asyncWaitMs = this.asyncWaitMs || 0;56 return await this.executeAtomAsync('execute_async_script', [script, args, this.asyncWaitMs], responseUrl);57};58commands.receiveAsyncResponse = async function receiveAsyncResponse (status, value) { // eslint-disable-line require-await59 logger.debug(`Received async response: ${JSON.stringify(value)}`);60 if (!util.hasValue(this.asyncPromise)) {61 logger.warn(`Received async response when we were not expecting one! ` +62 `Response was: ${JSON.stringify(value)}`);63 return;64 }65 if (util.hasValue(status) && status !== 0) {66 // MJSONWP67 return this.asyncPromise.reject(errorFromCode(status, value.message));68 }69 if (!util.hasValue(status) && value && _.isString(value.error)) {70 // W3C71 return this.asyncPromise.reject(errorFromW3CJsonCode(value.error, value.message, value.stacktrace));72 }73 return this.asyncPromise.resolve(value);74};75helpers.startHttpsAsyncServer = async function startHttpsAsyncServer () {76 logger.debug('Starting https server for async responses');77 let address = this.opts.callbackAddress || this.opts.address;78 let port = this.opts.callbackPort || this.opts.port;79 let {sslServer, pemCertificate, httpsPort} = await startHttpsServer(port, address);80 this.opts.sslServer = sslServer;81 this.opts.httpsServerCertificate = pemCertificate;82 this.opts.httpsCallbackPort = httpsPort;83 this.opts.httpsCallbackAddress = 'localhost';84 let udid;85 if (this.sim) {86 // ios driver87 udid = this.sim.udid;88 } else {89 // xcuitest driver90 udid = this.opts.udid;91 }92 await installSSLCert(this.opts.httpsServerCertificate, udid);93};94helpers.stopHttpsAsyncServer = async function stopHttpsAsyncServer () {95 logger.debug('Stopping https server for async responses');96 if (this.opts.sslServer) {97 await this.opts.sslServer.close();98 }99 await uninstallSSLCert(this.opts.httpsServerCertificate, this.opts.udid);100};101commands.executeMobile = async function executeMobile (mobileCommand, opts = {}) {102 // we only support mobile: scroll103 if (mobileCommand === 'scroll') {104 await this.mobileScroll(opts);105 } else if (mobileCommand === 'viewportScreenshot') {106 return await this.getViewportScreenshot();107 } else {108 throw new errors.UnknownCommandError('Unknown command, all the mobile commands except scroll have been removed.');109 }110};111Object.assign(extensions, commands, helpers);112export { commands, helpers };...

Full Screen

Full Screen

search_actions.js

Source:search_actions.js Github

copy

Full Screen

...64 dispatch({ type: 'START_ASYNC_FETCH' });65 const state = getState();66 const qp = queryString.parse(state.router.location.search);67 function onResponse(results) {68 dispatch(receiveAsyncResponse(results));69 };70 function onComplete(results) {71 dispatch(finishAsync());72 }73 fetchPaginated(qp, onResponse, onComplete);74 };75};76// on the first time, does NOT fetch, just uses global bootstrappedSearchResults77export function fetchSearchResults() {78 return function (dispatch, getState) {79 // format the API request from quer params80 const state = getState();81 const searchState = state.searchResults;82 // if not isHydrated and global bootstrappedSearchResults, use that as result, don't fetch anything, set isHydrated to false83 if (!searchState.isHydrated && typeof bootstrappedSearchResults === 'object') {84 dispatch(hydrateSearch());85 return dispatch(receiveSearchResponse(bootstrappedSearchResults));86 }87 const qp = queryString.parse(state.router.location.search);88 // from page and results per page, add limit and offset to API request89 const _offset = searchState.currentPage * searchState.resultsPerPage;90 const _limit = searchState.resultsPerPage;91 const newQp = _.clone(qp);92 newQp.offset = _offset;93 newQp.limit = _limit;94 /*if(state.searchResults.downloadsFlag){95 newQp.status = 'Active';96 }*/97 const url = createPath({ pathname: RESULTS_URL, search: newQp });98 fetchFromApi(url)99 .then(response => {100 if (!response) return;101 dispatch(setApiError(false));102 return dispatch(receiveSearchResponse(response));103 })104 // .catch(function(err) {105 // return dispatch(setApiError(true));106 // });107 };108};109export function receiveSearchResponse(_response) {110 console.log(_response);111 return {112 type: 'SEARCH_RESPONSE',113 response: _response114 };115};116export function receiveAsyncResponse(_results) {117 return {118 type: 'ASYNC_SEARCH_RESPONSE',119 results: _results120 };121};122export function finishAsync() {123 return {124 type: 'FINISH_ASYNC',125 };126};127export function setApiError(isError) {128 return {129 type: 'SEARCH_API_ERROR',130 value: isError...

Full Screen

Full Screen

fake-driver.js

Source:fake-driver.js Github

copy

Full Screen

1/* eslint-disable require-await */2import { errors, BaseDriver, determineProtocol } from '../..';3import { PROTOCOLS } from '../../lib/constants';4import _ from 'lodash';5import { util } from 'appium-support';6class FakeDriver extends BaseDriver {7 constructor () {8 super();9 this.protocol = PROTOCOLS.MJSONWP;10 this.sessionId = null;11 this.jwpProxyActive = false;12 }13 sessionExists (sessionId) {14 if (!sessionId) {15 return false;16 }17 return sessionId === this.sessionId;18 }19 driverForSession (/*sessionId*/) {20 return this;21 }22 async createSession (desiredCapabilities, requiredCapabilities, capabilities) {23 // Use a counter to make sure each session has a unique id24 this.sessionId = `fakeSession_${util.uuidV4()}`;25 if (capabilities) {26 return [this.sessionId, capabilities];27 } else {28 this.desiredCapabilities = desiredCapabilities;29 this.requiredCapabilities = requiredCapabilities || {};30 return [this.sessionId, _.extend({}, desiredCapabilities, requiredCapabilities)];31 }32 }33 async executeCommand (cmd, ...args) {34 if (!this[cmd]) {35 throw new errors.NotYetImplementedError();36 }37 if (cmd === 'createSession') {38 this.protocol = determineProtocol(...args);39 }40 return await this[cmd](...args);41 }42 async deleteSession () {43 this.jwpProxyActive = false;44 this.sessionId = null;45 }46 async getStatus () {47 return "I'm fine";48 }49 async setUrl (url) {50 return `Navigated to: ${url}`;51 }52 async getUrl () {53 return 'http://foobar.com';54 }55 async back (sessionId) {56 return sessionId;57 }58 async forward () {}59 async refresh () {60 throw new Error('Too Fresh!');61 }62 async getSession () {63 throw new errors.NoSuchDriverError();64 }65 async click (elementId, sessionId) {66 return [elementId, sessionId];67 }68 async implicitWait (ms) {69 return ms;70 }71 async clickCurrent (button) {72 return button;73 }74 async setNetworkConnection (type) {75 return type;76 }77 async moveTo (element, xOffset, yOffset) {78 return [element, xOffset, yOffset];79 }80 async getText () {81 return '';82 }83 async getAttribute (attr, elementId, sessionId) {84 return [attr, elementId, sessionId];85 }86 async setValue (value, elementId) {87 return [value, elementId];88 }89 async performTouch (...args) {90 return args;91 }92 async setFrame (frameId) {93 return frameId;94 }95 async removeApp (app) {96 return app;97 }98 async receiveAsyncResponse () {99 // this is here to test a failing command that does not throw an error100 return {status: 13, value: 'Mishandled Driver Error'};101 }102 proxyActive (/*sessionId*/) {103 return false;104 }105 getProxyAvoidList (/*sessionId*/) {106 return [];107 }108 canProxy (/*sessionId*/) {109 return false;110 }111}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2driver.init({3}).then(function() {4 return driver.receiveAsyncResponse();5});6var wd = require('wd');7driver.init({8}).then(function() {9 return driver.sendAsyncResponse("response");10});11var wd = require('wd');12driver.init({13}).then(function() {14 return driver.receiveAsyncResponse();15});16var wd = require('wd');17driver.init({18}).then(function() {19 return driver.sendAsyncResponse("response");20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium-base-driver');2var driver = new AppiumDriver();3driver.receiveAsyncResponse('my response');4var BaseDriver = require('appium-base-driver').BaseDriver;5var driver = new BaseDriver();6driver.sendAsyncResponse('my response');

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumBaseDriver = require('appium-base-driver')2var adb = new AppiumBaseDriver.ADB()3adb.receiveAsyncResponse(adb.getDeviceId(), function (err, data) {4 console.log(data)5})6ADB.prototype.receiveAsyncResponse = async function (deviceId, cb) {7 this.exec(cmd, {deviceId: deviceId}, cb)8}9{ stdout: '',10 cmd: 'adb -P 5037 -s emulator-5554 shell am broadcast -a io.appium.settings.async.response --es msg Hello World' }11var AppiumBaseDriver = require('appium-base-driver')12var adb = new AppiumBaseDriver.ADB()13adb.receiveAsyncResponse(adb.getDeviceId(), function (err, data) {14 console.log(data)15})16ADB.prototype.receiveAsyncResponse = async function (deviceId, cb) {17 this.exec(cmd, {deviceId: deviceId}, cb)18}19{ stdout: '',20 cmd: 'adb -P 5037 -s emulator-5554 shell am broadcast -a io.appium.settings.async.response --es msg Hello World' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new AppiumDriver();2driver.receiveAsyncResponse('response');3receiveAsyncResponse(response) {4 this.asyncResponse = response;5 this.asyncResponseReceived = true;6}7handleAsyncCommand(command, cb) {8 if (command !== 'receiveAsyncResponse') {9 return cb(new Error(`Invalid command ${command}`));10 }11 if (!this.asyncResponseReceived) {12 return cb(new Error('No async response received'));13 }14 cb(this.asyncResponse);15}16executeAsync(script, args, cb) {17 this.asyncResponseReceived = false;18 this.asyncResponse = null;19 this.execute(script, args, (err, res) => {20 if (err) {21 return cb(err);22 }23 if (!this.asyncResponseReceived) {24 return cb(new Error('No async response received'));25 }26 cb(null, this.asyncResponse);27 });28}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful