Skip to content

waitForClickable: Timeout doesn't work, method call fails immediately #2166

Closed

Description

@mirao

What are you trying to achieve?

The following call I.waitForClickable() should fail after 10 sec.
Note: The test page contains disabled button.

What do you get instead?

CodeceptJS logs "element button still not clickable after 10 sec", however it's not true, because the test fails immediately.

$ npx codeceptjs run buttondisabled_test.js --verbose
CodeceptJS v2.4.1
Using test root "/home/mirao/workspace/mycodeceptjs/tests/my"
Helpers: WebDriver
Plugins: screenshotOnFail, retryFailedStep

ButtonDisabled --
    [1] Starting recording promises
    Emitted | suite.before ([object Object])
  Test that button is enabled
    Emitted | test.before ([object Object])
    Emitted | test.start ([object Object])
    Emitted | step.before (I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html")
    Emitted | step.after (I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html")
    Emitted | step.before (I wait for clickable "button", 10)
    Emitted | step.after (I wait for clickable "button", 10)
    Emitted | step.start (I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html")
    I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html"
    Emitted | step.passed (I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html")
    Emitted | step.finish (I am on page "https://design-system.service.gov.uk/components/button/disabled/index.html")
    Emitted | step.start (I wait for clickable "button", 10)
    I wait for clickable "button", 10
    [1] Error | Error: element button still not clickable after 10 sec
    Emitted | step.failed (I wait for clickable "button", 10)
    Emitted | step.finish (I wait for clickable "button", 10)
    [1] Error | Error: element button still not clickable after 10 sec
    [1] Starting <teardown> session
    Emitted | test.failed ([object Object])
    Emitted | test.finish ([object Object])
    [1] <teardown> Stopping recording promises
 › <screenshotOnFail> Test failed, saving screenshot
 › Screenshot has been saved to /home/mirao/workspace/mycodeceptjs/tests/my/output/Test_that_button_is_enabled.failed.png
  ✖ FAILED in 1082ms

    [2] Starting recording promises
    Emitted | test.after ([object Object])
    Emitted | suite.after ([object Object])

-- FAILURES:

  1) ButtonDisabled
       Test that button is enabled:
     element button still not clickable after 10 sec
  
  Scenario Steps:
  
  - I.waitForClickable("button", 10) at Test.Scenario (buttondisabled_test.js:5:7)
  - I.amOnPage("https://design-system.service.gov.uk/components/button/disabled/index.html") at Test.Scenario (buttondisabled_test.js:4:7)
  
  Error: element button still not clickable after 10 sec
      at timer.catch.e (/home/mirao/workspace/mycodeceptjs/node_modules/webdriverio/build/commands/browser/waitUntil.js:30:15)
      at process._tickCallback (internal/process/next_tick.js:68:7)


  FAIL  | 0 passed, 1 failed   // 6s
    Emitted | global.result ([object Object])
    Emitted | global.after ([object Object])

Provide test source code if related

Feature("ButtonDisabled");

Scenario("Test that button is enabled", (I) => {
    I.amOnPage("https://design-system.service.gov.uk/components/button/disabled/index.html");
    I.waitForClickable("button", 10);
});

Details

  • CodeceptJS version: 2.4.1
  • NodeJS Version: v10.18.1
  • Operating System: Ubuntu 19.10
  • webdriverio 5.18.6
  • Configuration file:
exports.config = {
    tests: "./*_test.js",
    output: "./output",
    helpers: {
        WebDriver: {
            url: "http://localhost",
            browser: "chrome"
        }
    },
    include: {
        I: "./steps_file.js"
    },
    bootstrap: null,
    mocha: {},
    name: "my",
    plugins: {
        retryFailedStep: {
            enabled: true
        },
        screenshotOnFail: {
            enabled: true
        }
    }
};

Activity

  1. changed the title [-]waitForClickable: Timeout doesn't work, method fails immediately[/-] [+]waitForClickable: Timeout doesn't work, method call fails immediately[/+] on Jan 26, 2020
  2. mirao commented on Jan 26, 2020

    @mirao
    ContributorAuthor

    The fix seems to be easy.
    WebDriverIO's method waitForClickable requires timeout in ms. So just multiply CodeceptJS timeout in sec by 1000:

    node_modules/codeceptjs/lib/helper/WebDriver.js

      async waitForClickable(locator, waitTimeout) {
        waitTimeout = waitTimeout || this.options.waitForTimeout;
        let res = await this._locate(locator);
        res = usingFirstElement(res);
        assertElementExists(res, locator);
    
        return res.waitForClickable({
          timeout: waitTimeout * 1000, // This is the bug fix
          timeoutMsg: `element ${res.selector} still not clickable after ${waitTimeout} sec`,
        });
      }
  3. mirao commented on Jan 26, 2020

    @mirao
    ContributorAuthor

    I'll try to open pull request.

  4. kobenguyent commented on Jan 26, 2020

    @kobenguyent
    Collaborator

    That’s good! 😊

  5. added a commit that references this issue on Jan 27, 2020
  6. javierfuentesm commented on Nov 17, 2021

    @javierfuentesm

    the same error is happening with the helper of Puppeteer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions