nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Nightwatch v2 iOS xcuitest #2990

Closed JacquesN16 closed 2 years ago

JacquesN16 commented 2 years ago

Describe the bug

I have recently switched to Nightwatch v2.0 beta for a test on iOS Simulator Device. In my test, I used the method moveToElement() after an assert.visible(). The assertion has passed perfectly, but there is a problem when it executed the moveToElement() method to the same element.

Sample test

sampleTest.js

```js client .url(url) .assert.visible('.ScratchCard__Canvas') .execute('mobile: swipe', {direction: 'up', velocity: 5000}) .pause(2000) .click('#w-cta') .pause(TIMEOUT_LOADER) .assert.visible('.ScratchCard__Canvas') <= received a code : 200 .moveToElement('.ScratchCard__Canvas',100,100) <= received a code: 404 ? ```

appium.log

```txt [debug] [WD Proxy] Matched '/actions' to command name 'performActions' [debug] [WD Proxy] Proxying [POST /actions] to [POST http://127.0.0.1:8100/session/D6DEEC45-F6E4-4BAF-A868-3FE24729D61F/actions] with body: {"actions":[{"actions":[{"type":"po interMove","origin":{"ELEMENT":":wdc:1640875612655","element-6066-11e4-a52e-4f735466cecf":":wdc:1640875612655"},"duration":100,"x":100,"y":100}],"parameters":{"pointerType":"t ouch"},"type":"pointer","id":"default mouse"}]} [WD Proxy] Got response with status 404: {"value":{"error":"stale element reference","message":"The element identified by \":wdc:1640875612655\" is either not present or it ha s expired from the internal cache. Try to find it again","traceback":"(\n\t0 CoreFoundation 0x00007fff20422fba __exceptionPreprocess + 242\n\t1 libobj c.A.dylib 0x00007fff20193ff5 objc_exception_throw + 48\n\t2 WebDriverAgentLib 0x000000010e8681cc -[FBElementCache elementForUUID:resolv eForAdditionalAttributes:andMaxDepth:] + 668\n\t3 WebDriverAgentLib 0x000000010e867eff -[FBElementCache elementForUUID:] + 79\n\t4 WebDriverAgentLib 0x000000010e7e6389 -[FBW3CActionsSynthesizer preprocessedActionItemsWith:] + 1337\n\t5 WebDriverAgentLib 0x000000010e7e78e6 -[FBW3CActionsSyn thesizer eventPathsWithGestureAction:forActionId:error:] + 1334\n\t6 WebDriverAgentLib 0x000000010e7e8696 -[FBW3CActionsSynthesizer eventPathsWithActionDes cription:for... [debug] [W3C] Matched W3C error code 'stale element reference' to StaleElementReferenceError [debug] [W3C (1b0bacfe)] Encountered internal error running command: StaleElementReferenceError: The element identified by ":wdc:1640875612655" is either not present or it has expired from the internal cache. Try to find it again ```

Configuration

nightwatch.json

```js { live_output: false, globals_path: "nightwatch.globals.js", test_settings: { default: { launch_url: 'https://nightwatchjs.org', selenium_port: 4723, selenium_host: "127.0.0.1", silent: true, selenium_start_process: false, }, ios : { desiredCapabilities : { automationName: "XCUITest", browserName : "safari", platformName : "iOS", platformVersion : "14.5", deviceName : "iPhone 12 Pro Max", real_mobile : false, connectHardwareKeyboard: false } }, } } ```

Your Environment

Executable Version
nightwatch --version 2.0.0-beta.2
npm --version 6.14.6
yarn --version 1.22.10
node --version 12.18.3
appium ^1.22.1
OS Version
macOS 11.6.1
JacquesN16 commented 2 years ago

The reason for this problem is because the Apple's XCTest test driver's framework is different from the test driver used for Android Virtual Device and it does not natively support W3C standards for TouchAction interface implementation. So some of commands that we can find on NighwatchJS official documentations may not work properly. For that reason, we can use the gestures set that goes with XCtest driver (the list of all the gestures here ). To apply the gesture to Nightwatch test, use browser.execute('mobile: gesture', {arguments})