Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls to browser.anyKindOfFunction() inside beforeCommand/afterCommand leads to infinite loop #4601

Closed
sveint opened this issue Oct 10, 2019 · 3 comments · Fixed by #4610

Comments

@sveint
Copy link

commented Oct 10, 2019

Environment:

  • WebdriverIO version: 5.14.5
  • Mode: WDIO Testrunner
  • If WDIO Testrunner, running sync/async: sync
  • Node.js version: 10.16.3
  • NPM version: yarn v1.19.1
  • Browser name and version: Not relevant
  • Platform name and version: Docker container on ubuntu:18.04, running on Ubuntu 18.04
  • Additional wdio packages used (if applicable): @wdio/cli, @wdio/jasmine-framework, @wdio/local-runner, @wdio/spec-reporter, @wdio/sync

Config of WebdriverIO

var defaultCapabilities = [
    {
        'goog:chromeOptions': {
            args: ['headless', 'disable-gpu', '--no-sandbox', '--window-size=1440,1080']
        },
        maxInstances: 1,
        browserName: 'chrome'
    }
]

exports.config = {
    specs: process.env.SPEC,
    maxInstances: 1,
    capabilities: defaultCapabilities,
    sync: true,
    logLevel: 'debug',
    coloredLogs: true,
    bail: 0,
    screenshotPath: './errorShots/',
    waitforTimeout: 10000,
    waitForInterval: 100,
    connectionRetryTimeout: 90000,
    connectionRetryCount: 3,
    framework: 'jasmine',
    reporters: ['spec'],
    jasmineNodeOpts: {
        defaultTimeoutInterval: 300000
    },
    afterCommand: function() {
        console.log('afterCommand')
        browser.pause(1000)
    }

Describe the bug
Using wdio v4 we use browser.executeAsync inside beforeCommand in order to check something in the web browser (whether state framework is done processing our triggers) to simplify writing tests. It basically sleeps until the state framework is done processing all triggers, then returns for further processing.

This works really well in v4. In v5, any call to browser.anyKindOfFunction(), will re-trigger the beforeCommand(), leading to an infinite loop.

This applies to both beforeCommand and afterCommand.

To Reproduce
Steps to reproduce the behavior:

  1. Create a dummy test:
describe('Dummy', function() {
    it('test 1', function() {
        console.log('testing!')
        browser.url('/')
        browser.pause(1)
    })
})
  1. Launch test using example config above
  2. Observe infinite loop in log:
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand

If not using browser.pause(), node will eventually run out of memory due to infinite loop.

Expected behavior

I expect only browser commands in actual tests to trigger beforeCommand/afterCommand hooks, like in v4. Otherwise, the functionality you can perform in these hooks are severely limited.

Log

Execution of 1 spec files started at 2019-10-10T11:45:53.745Z

2019-10-10T11:45:53.795Z INFO @wdio/cli:launcher: Run onPrepare hook
2019-10-10T11:45:53.799Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,wdio-bug.conf.js,--baseUrl,127.0.0.1:5000,--hostname,172.17.0.1,--port,4444,--path,/,--spec,/src/webui/tests/e2e/tests/dummy-test.js
[0-0] RUNNING in chrome - /src/webui/tests/e2e/tests/dummy-test.js
[0-0] 2019-10-10T11:45:54.357Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2019-10-10T11:45:54.371Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2019-10-10T11:45:54.374Z INFO webdriverio: Initiate new session using the webdriver protocol
[0-0] 2019-10-10T11:45:54.378Z INFO webdriver: [POST] http://172.17.0.1:4444/session
[0-0] 2019-10-10T11:45:54.378Z INFO webdriver: DATA { capabilities:
   { alwaysMatch: { 'goog:chromeOptions': [Object], browserName: 'chrome' },
     firstMatch: [ {} ] },
  desiredCapabilities:
   { 'goog:chromeOptions': { args: [Array] },
     browserName: 'chrome' } }
[0-0] testing!
[0-0] 2019-10-10T11:45:54.754Z INFO webdriver: COMMAND navigateTo("http://127.0.0.1/")
[0-0] 2019-10-10T11:45:54.754Z INFO webdriver: [POST] http://172.17.0.1:4444/session/799437b6837fdae0db6e55597d8b0549/url
[0-0] 2019-10-10T11:45:54.754Z INFO webdriver: DATA { url: 'http://127.0.0.1/' }
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand
[0-0] afterCommand
...

Additional context

@pmerwin

This comment has been minimized.

Copy link

commented Oct 10, 2019

Hmm we use browser.call() in our after hook and it does not have this issue. Can you see if that, also, loops in your scenario?

@sveint

This comment has been minimized.

Copy link
Author

commented Oct 11, 2019

Hmm we use browser.call() in our after hook and it does not have this issue. Can you see if that, also, loops in your scenario?

That also loops here, so I wonder what's going on. What version of webdriver are you running? Can you use the other commands as well without issues?

@mgrybyk

This comment has been minimized.

Copy link
Member

commented Oct 11, 2019

will be fixed with the PR

@mgrybyk mgrybyk closed this Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.