webdriverio / webdriverio

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

[🐛 Bug]: Different behaviour of handling getText() inside of call back function for v8 and v7.27/v7.26 #9388

Closed 7artur7 closed 1 year ago

7artur7 commented 1 year ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.0.9

Node.js Version

18.12.1 (OS X 12.5)

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [{
        maxInstances: 1,
        browserName: 'chrome',
    }],

What happened?

After update to v8.0.9, I faced unexpected behaviour while using getText() inside of callback functions of e.g. find(), map() methods. Method isn't executed or registered as pending promise.

Example:

const contributeLink = await $$('a.navbar__item.navbar__link').find(async function(link) {
            const text = await link.getText()
            return text === 'Contribute'})

Wouldn't click on Contribute but stay on Docs. If debug this code execution is jumped out on first call to const text = await link.getText()

Or

get tagsListItems () { return this.$$tagsListItems.map($tag => $tag.getText()); }

Would return set of pending promises for each $tag.getText().

In wdio 7.27.0. Both methods works correctly. Contribute tab is clicked. Tag text being returned.

What is your expected behavior?

getText() and other element async methods work the same as in v7 or it is documented that v8 behaviour is a correct one.

How to reproduce the bug.

Dependencies are

  "dependencies": {
    "@wdio/cli": "^8.0.9",
    "chromedriver": "^108.0.0",
    "wdio-chromedriver-service": "^8.0.1"
  },
  "devDependencies": {
    "@wdio/local-runner": "^8.0.9",
    "@wdio/mocha-framework": "^8.0.9",
    "@wdio/selenium-standalone-service": "^8.0.9",
    "@wdio/spec-reporter": "8.0.8"
  }
}

Run next simple test in Wdio testrunner

describe('webdriver.io page', () => {
    it('click on Contribute', async function() {
        await browser.url('https://webdriver.io');
        const contributeLink = await $$('a.navbar__item.navbar__link').find(async function(link) {
            const text = await link.getText()
            return text === 'Contribute'})
        await contributeLink.click();
        await expect(browser).toHaveTitle(
          'Contribute | WebdriverIO'
        )
    });
});

Relevant log output

2022-12-12T11:43:44.669Z INFO chromedriver: Starting ChromeDriver 108.0.5359.71 (1e0e3868ee06e91ad636a874420e3ca3ae3756ac-refs/branch-heads/5359@{#1016}) on port 9515
2022-12-12T11:43:44.670Z INFO chromedriver: Only local connections are allowed.
2022-12-12T11:43:44.670Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2022-12-12T11:43:44.670Z INFO chromedriver: ChromeDriver was started successfully.
2022-12-12T11:43:44.767Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2022-12-12T11:43:44.768Z INFO @wdio/local-runner: Start worker 0-0 with arg: --spec,test/specs/navigation.js
[0-0] 2022-12-12T11:43:45.359Z INFO @wdio/local-runner: Run worker command: run
[0-0] ChanceJS Seed: 0.8522445097890721 - Pass in using 'SEED=0.8522445097890721'
[0-0] RUNNING in chrome - file:///test/specs/navigation.js
[0-0] 2022-12-12T11:43:45.545Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2022-12-12T11:43:45.641Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2022-12-12T11:43:45.641Z INFO webdriver: DATA {
[0-0]   capabilities: { alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
[0-0]   desiredCapabilities: { browserName: 'chrome' }
[0-0] }
[0-0] 2022-12-12T11:43:46.734Z INFO webdriver: COMMAND navigateTo("https://webdriver.io/")
[0-0] 2022-12-12T11:43:46.734Z INFO webdriver: [POST] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/url
[0-0] 2022-12-12T11:43:46.734Z INFO webdriver: DATA { url: 'https://webdriver.io/' }
[0-0] 2022-12-12T11:43:48.376Z INFO webdriver: COMMAND findElements("css selector", "a.navbar__item.navbar__link")
[0-0] 2022-12-12T11:43:48.377Z INFO webdriver: [POST] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/elements
[0-0] 2022-12-12T11:43:48.377Z INFO webdriver: DATA { using: 'css selector', value: 'a.navbar__item.navbar__link' }
[0-0] 2022-12-12T11:43:48.387Z INFO webdriver: RESULT [
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': '25f72f30-1e0d-4fae-b489-5f00b0eb3c43'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': 'a7fc1b75-d1c5-4104-bf78-b669a8381c06'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': 'bf226239-1962-49cb-8e07-bb58a82aacee'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': '40f2e959-e7d4-419c-939b-d60a35c595be'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': '405c2fa0-f003-4a0e-973f-8f58ac76e7d4'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': 'c9c9294f-c135-48f7-9a9e-7f6703f2d99b'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': '7ea2d57f-4978-49db-8f78-9271b8facff1'
[0-0]   },
[0-0]   {
[0-0]     'element-6066-11e4-a52e-4f735466cecf': '0e06315e-d5e7-470b-98c7-79559010774b'
[0-0]   }
[0-0] ]
[0-0] 2022-12-12T11:43:48.396Z INFO webdriver: COMMAND elementClick("25f72f30-1e0d-4fae-b489-5f00b0eb3c43")
[0-0] 2022-12-12T11:43:48.396Z INFO webdriver: COMMAND getElementText("25f72f30-1e0d-4fae-b489-5f00b0eb3c43")
[0-0] 2022-12-12T11:43:48.397Z INFO webdriver: [POST] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/element/25f72f30-1e0d-4fae-b489-5f00b0eb3c43/click
[0-0] 2022-12-12T11:43:48.397Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/element/25f72f30-1e0d-4fae-b489-5f00b0eb3c43/text
[0-0] 2022-12-12T11:43:48.450Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:48.450Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:48.463Z INFO webdriver: RESULT Docs
[0-0] 2022-12-12T11:43:48.465Z INFO webdriver: RESULT WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO
[0-0] 2022-12-12T11:43:48.966Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:48.966Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:48.971Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:49.473Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:49.473Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:49.479Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:49.980Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:49.980Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:49.986Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:50.486Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:50.487Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:50.494Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:50.996Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:50.996Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:51.001Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:51.503Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:51.503Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:51.510Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:52.012Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:52.013Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:52.018Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:52.519Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:52.520Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:52.526Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:53.027Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:53.028Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:53.032Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:53.533Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:53.533Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:53.537Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:54.039Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:54.040Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:54.046Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:54.547Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:54.548Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:54.554Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:55.056Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:55.057Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:55.062Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:55.563Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:55.564Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:55.568Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:56.070Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:56.070Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:56.075Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:56.577Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:56.577Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:56.582Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:57.083Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:57.083Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:57.089Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:57.590Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:57.590Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:57.595Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] 2022-12-12T11:43:58.096Z INFO webdriver: COMMAND getTitle()
[0-0] 2022-12-12T11:43:58.096Z INFO webdriver: [GET] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748/title
[0-0] 2022-12-12T11:43:58.101Z INFO webdriver: RESULT Getting Started | WebdriverIO
[0-0] Error in "webdriver.io page.click on Contribute"
Error: Expect window to have title

Expected: "Contribute | WebdriverIO"
Received: "Getting Started | WebdriverIO"
    at Context.<anonymous> (/path/navigation.js:8:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0-0] 2022-12-12T11:43:58.609Z INFO webdriver: COMMAND deleteSession()
[0-0] 2022-12-12T11:43:58.610Z INFO webdriver: [DELETE] http://localhost:9515/session/c97511a8ffae4cb3ef6e3de08dcf8748
[0-0] FAILED in chrome - file:///test/specs/navigation.js
2022-12-12T11:43:58.776Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2022-12-12T11:43:58.776Z INFO @wdio/cli:launcher: Run onComplete hook

Code of Conduct

Is there an existing issue for this?

christian-bromann commented 1 year ago

Thanks for reporting!

I can reproduce this problem and it seems that the package we use to make array operation async/await aware is not working anymore. The file to look at first would be packages/wdio-utils/src/shim.ts.

Any contributions that resolves the bug are highly appreciated. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!