webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.04k stars 2.5k forks source link

[🐛 Bug]: Instead of moving to next action, wdio automatically delete session #8028

Closed vagisha-nidhi195 closed 2 years ago

vagisha-nidhi195 commented 2 years ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

"^5.23.0"

Node.js Version

node@10

Mode

WDIO Testrunner

Which capabilities are you using?

{ 
      platformName: 'windows',
      'deviceName': 'WindowsPC',
      'app': 'AmazonVideo.PrimeVideo_pwbj9vvecjh7j!App',
      'ms:experimental-webdriver': true,
}

What happened?

When I run the test using mocha framework, the wdio sends a DELETE session before any action is completed. I am using aync behaviour in my tests. I am running the test on a remote machine with winappdriver.exe running on the machine.

services: [
        ['winappdriver', {
            args: ['x.x.x.x, '4723/wd/hub']
        }]
    ]

Searched this issue https://github.com/webdriverio/webdriverio/issues/4307 but I am not using sync behaviour in my tests.

What is your expected behavior?

Expected behaviour is that it should perform the actions before sending a delete session.

How to reproduce the bug.

To reproduce the bug create a mocha test file

const login =  async () => {   
    const element  = await $('.//*//ComboBox') 
    element.click()
}

suite ('random test', () => {
    login()
})

Use the versions of packages as defined below: package.json file: I am not using the latest frameworks, as I need to integrate this with another package.

 "devDependencies": {
    "@types/mocha": "^5.2.7",
    "@types/node": "^12.7.5",
    "@wdio/appium-service": "^5.12.1",
    "@wdio/cli": "^5.23.0",
    "@wdio/dot-reporter": "5.13.2",
    "@wdio/jasmine-framework": "^5.23.0",
    "@wdio/mocha-framework": "^5.23.0",
    "@wdio/junit-reporter": "^5.12.1",
    "@wdio/local-runner": "^5.23.0",
    "@wdio/spec-reporter": "^7.16.14",
    "appium": "1.15.0",
    "chromedriver": "^98.0.0",
    "prettier": "^1.18.2",
    "rimraf": "3.0.0",
    "ts-node": "^10.5.0",
    "tsconfig-paths": "^3.8.0",
    "typescript": "^4.5.5",
    "wdio-chromedriver-service": "^7.2.8",
    "wdio-winappdriver-service": "^0.1.1",
    "webdriver": "git+https://github.com/react-native-windows/webdriver.git",
    "webdriverio": "^5.23.0"
  }

Connect to a machine running winppdriver.exe (or localhost) (Provide the ip address and port in services in wdio config file.

Run the test with wdio.

Relevant log output

Here are the logs from wdio

[0-0] 2022-02-18T20:30:07.860Z INFO webdriver: [POST] http://x.x.x.x:4723/wd/hub/session
[0-0] 2022-02-18T20:30:07.860Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      platformName: 'windows',
      deviceName: 'WindowsPC',
      app: 'AmazonVideo.PrimeVideo_pwbj9vvecjh7j!App',
      'ms:experimental-webdriver': true
    },
    firstMatch: [ {} ]
  },
  desiredCapabilities: {
    platformName: 'windows',
    deviceName: 'WindowsPC',
    app: 'AmazonVideo.PrimeVideo_pwbj9vvecjh7j!App',
    'ms:experimental-webdriver': true
  }
}
[0-0] 2022-02-18T20:30:17.194Z INFO webdriver: COMMAND findElement("xpath", ".//*//ComboBox")
[0-0] 2022-02-18T20:30:17.195Z INFO webdriver: [POST] http://x.x.x.x:4723/wd/hub/session/697514E0-70C2-4445-95E1-C667D1E0C73F/element
[0-0] 2022-02-18T20:30:17.195Z INFO webdriver: DATA { using: 'xpath', value: './/*//ComboBox' }
[0-0] 2022-02-18T20:30:17.197Z INFO webdriver: COMMAND deleteSession()
[0-0] 2022-02-18T20:30:17.197Z INFO webdriver: [DELETE] http://x.x.x.x:4723/wd/hub/session/697514E0-70C2-4445-95E1-C667D1E0C73F
[0-0] 2022-02-18T20:30:17.647Z INFO webdriver: RESULT 1
[0-0] 2022-02-18T20:30:17.737Z INFO webdriver: RESULT {
  error: 'no such element',
  message: 'An element could not be located on the page using the given search parameters.'
}
[0-0] 2022-02-18T20:30:17.747Z DEBUG webdriverio: command click was called on an element (".//*//ComboBox") that wasn't found, waiting for it...
[0-0] 2022-02-18T20:30:17.749Z INFO webdriver: COMMAND findElements("xpath", ".//*//ComboBox")
2022-02-18T20:30:17.780Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 0
[0-0] PASSED in MultiRemote - /test/mochasample.ts
2022-02-18T20:30:17.781Z INFO @wdio/cli:launcher: Run onComplete hook


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Is there an existing issue for this?

- [X] I have searched the existing issues
WillBrock commented 2 years ago

I would start by updating to a more recent version of WebdriverIO and Node to see if it resolves your issue. Version 5 is a couple years old and version 7 is the latest.

vagisha-nidhi195 commented 2 years ago

Tried updating the version. I am getting the following error. Tried the same thing with global $.

2022-02-19T09:18:35.889Z INFO @wdio/cli:launcher: Run onPrepare hook
2022-02-19T09:18:35.892Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2022-02-19T09:18:35.893Z INFO @wdio/local-runner: Start worker 0-0 with arg: 
[0-0] 2022-02-19T09:18:36.225Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2022-02-19T09:18:36.365Z DEBUG @wdio/config:utils: Found 'ts-node' package, auto-compiling TypeScript files
[0-0] 2022-02-19T09:18:36.366Z DEBUG @wdio/local-runner:utils: init multiremote session
[0-0] (node:887) UnhandledPromiseRejectionWarning: TypeError: browser.$ is not a function
[0-0]     at /Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:4:36
[0-0]     at Generator.next (<anonymous>)
[0-0]     at /Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:8:71
[0-0]     at new Promise (<anonymous>)
[0-0]     at __awaiter (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:4:12)
[0-0]     at loginToWindowsPVApp (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:3:41)
[0-0]     at Suite.<anonymous> (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:12:5)
[0-0]     at Object.create (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/node_modules/mocha/lib/interfaces/common.js:148:19)
[0-0]     at context.suite (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/node_modules/mocha/lib/interfaces/tdd.js:49:27)
[0-0]     at Object.<anonymous> (/Users/vagishn/WinAppDriver/Samples/JavaScript/packages/webdriverio/test/mochasample.ts:11:1)
[0-0] (node:887) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
[0-0] (node:887) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2022-02-19T09:18:36.742Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 0
2022-02-19T09:18:36.743Z INFO @wdio/cli: [0-0] SKIPPED in MultiRemote - /test/mochasample.ts
2022-02-19T09:18:36.743Z INFO @wdio/cli:launcher: Run onComplete hook

My tsconfig file

{
    "compilerOptions": {
      "baseUrl": ".",
      "target": "es6",
      "module": "commonjs",
      "jsx": "react",
      "outDir": "dist",
      "declaration": true,
      "sourceMap": true,
      "noEmitOnError": true,
      "skipLibCheck": true,
      "moduleResolution": "node",
      "noEmit": false,
      "noUnusedLocals": true,
      "strict": true,
      "rootDir": ".",
      "esModuleInterop": true,
      "types": [
        "node",
        "webdriverio/async",
        "@wdio/mocha-framework"
      ]
    },
    "include": [
      "pages",
      "test",
      "./**/*.ts"
    ],
    "exclude": [
    ]
  }
christian-bromann commented 2 years ago

[0-0] 2022-02-19T09:18:36.366Z DEBUG @wdio/local-runner:utils: init multiremote session [0-0] (node:887) UnhandledPromiseRejectionWarning: TypeError: browser.$ is not a function

Are you sure you want to run a multiremote session? Can you provide a minimal reproducible example?

vagisha-nidhi195 commented 2 years ago

I am finally able to run commands when running mocha in bdd mode. Getting the same issue with tdd mode. Yes, I want to run in a multiremote session as I want to control the app as well as the windows 'root' desktop to manage some things.

Now the problem I am having is that the multi remote configuration is not running properly. I am running appium server on my remote machine.

Appium server logs: https://github.com/vagisha-nidhi195/demo-webdriverio-mocha/blob/master/src/appium_server_logs.txt Here are the logs

[0-0] RUNNING in MultiRemote - /dist/src/test/e2e/specs/Winapp.spec.js
[0-0] (node:38723) [DEP0016] DeprecationWarning: 'root' is deprecated, use 'global'
[0-0] unknown error in "Winapppppppp Winapp test"
unknown error: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to WinAppDriver server because its process is not running (probably crashed). Check the Appium log for more details
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Array.map (<anonymous>)
    at global.$ (/Users/vagishn/demo-webdriverio-mocha-master/node_modules/@wdio/runner/build/index.js:181:42)
    at Context.<anonymous> (/Users/vagishn/demo-webdriverio-mocha-master/dist/src/test/e2e/specs/Winapp.spec.js:5:31)
    at Context.executeAsync (/Users/vagishn/demo-webdriverio-mocha-master/node_modules/@wdio/utils/build/shim.js:137:25)
    at Context.exports.testFrameworkFnWrapper (/Users/vagishn/demo-webdriverio-mocha-master/node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:44:32)

Reproducible example: https://github.com/vagisha-nidhi195/demo-webdriverio-mocha/

christian-bromann commented 2 years ago

Thanks for providing a reproducible example. I don't have a Windows machine so I won't be able to look into this anytime soon by any hints that lead to the origin of this problem or PRs that solve it are highly appreciated. Cheers!

praveendvd commented 2 years ago
const login =  async () => {   
    const element  = await $('.//*//ComboBox') 
    element.click()
}

suite ('random test',async () => {
   await login()
})
praveendvd commented 2 years ago

You should add await as the function is async one , u should suite async I believe

christian-bromann commented 2 years ago

Thanks for investigating @praveendvd , I looked into the test case as well:

describe('Winapppppppp', () => {
    before(() => {      
    });

    it('Winapp test', async () => {
        const element  = await $('.//*//ComboBox') 

        element.click()
        browser.pause(10000)

        browser.refresh()
        const pageSource = await browser.getPageSource()
        console.log(pageSource)
        const elem = await $('[name="United Kingdom"]')
        elem.click()
    });
});

As you pointed out async/await is not used correctly, the correct way of writing the test would be:

describe('Winapppppppp', () => {
    before(() => {      
    });

    it('Winapp test', async () => {
        const element  = await $('.//*//ComboBox') 

        await element.click()
        await browser.pause(10000)

        await browser.refresh()
        const pageSource = await browser.getPageSource()
        console.log(pageSource)
        const elem = await $('[name="United Kingdom"]')
        await elem.click()
    });
});

Closing the issue as it doesn't seem to be a problem with WebdriverIO.