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

I.waitNumberOfVisibleElements('locator', 0) always fails #1172

Closed
lubosek opened this issue Jul 31, 2018 · 4 comments · Fixed by #4274
Closed

I.waitNumberOfVisibleElements('locator', 0) always fails #1172

lubosek opened this issue Jul 31, 2018 · 4 comments · Fixed by #4274

Comments

@lubosek
Copy link

lubosek commented Jul 31, 2018

What are you trying to achieve?

Wait until number of elements on a page goes down to zero (as a workaround to non-working waitForInvisible ) expecting that I.waitNumberOfVisibleElements('div.slds-spinner_container', 0); passes.

What do you get instead?

Number of elements is zero as evidenced by previous call to grabNumberOfVisibleElements but the assertion I.waitNumberOfVisibleElements('div.slds-spinner_container', 0); is false anyway causing the test to fail.

Provide console output if related. Use --verbose mode for more details.

...
   I wait 5
   I grab number of visible elements "div.slds-spinner_container"
0
   I wait number of visible elements "div.slds-spinner_container", 0
  ✖ FAILED in 58165ms
-- FAILURES:

  1) Walkthrough
       Routing and navigation:
     The number of elements (div.slds-spinner_container) is not 0 after 10 sec

Details

  • CodeceptJS version: 1.3.2
  • NodeJS Version: 8.9.2
  • Operating System: Mac OS 10.13.4 (17E202)
  • WebDriverIO
  • Configuration file:
{
  "output": "./output",
  "helpers": {
    "WebDriverIO": {
      "url": "https://e2e.pricefx.eu/unity/develop/",
      "browser": "chrome",
      "smartWait": 10000,
      "host": "selenium",
      "waitForTimeout": 10000
    }
  },
  "include": {
    "I": "./steps_file.js",
    "loginPage": "./pages/login-page.js",
    "quotesPage": "./pages/quotes-page.js",
    "contractsPage": "./pages/contracts-page.js",
    "pendingApprovalsPage": "./pages/pendingApprovals-page.js",
    "dashboardsPage": "./pages/dashboards-page.js",
    "configurationPage": "./pages/configuration-page.js",
    "view": "./steps/view.js"
  },
  "mocha": {},
  "bootstrap": false,
  "teardown": null,
  "hooks": [],
  "gherkin": {},
  "tests": "./tests/*-test.js",
  "timeout": 10000,
  "name": "e2e-tests"
}
@kobenguyent
Copy link
Collaborator

Please reopen if you encounter this with latest version.

@danielrentz
Copy link
Contributor

It happens to me in codeceptjs@3.5.15 and playwright-core@1.42.0

I.seeNumberOfVisibleElements(selector, 0);    // works
I.waitNumberOfVisibleElements(selector, 0);   // <== fails!

@kobenguyent @lubosek Please reopen, cannot do that by myself.

@kobenguyent kobenguyent reopened this Mar 20, 2024
@kobenguyent
Copy link
Collaborator

  async waitNumberOfVisibleElements(locator, num, sec) {
    const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
    locator = new Locator(locator, 'css');
    await this.context;

    try {
      const context = await this._getContext();
      const visibleFn = function ([locator, num]) {
        const els = document.querySelectorAll(locator);
        if (!els || els.length === 0) {
          return num === 0;
        }
        return Array.prototype.filter.call(els, el => el.offsetParent !== null).length === num;
      };

      const waiter = context.waitForFunction(visibleFn, [locator.value, num], { timeout: waitTimeout });
      await waiter;
    } catch (error) {
      throw new Error(`The number of elements (${locator.toString()}) is not ${num} after ${waitTimeout / 1000} sec\n${error.message}`);
    }
  }

hey @danielrentz may you try to alter your local codeceptjs code in node_modules to see if this approach works for you?

@danielrentz
Copy link
Contributor

@kobenguyent I can confirm that this change works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants