mucsi96 / nightwatch-api

[DEPRECATED] Cross-runner API for Nightwatch.js
https://nightwatch-api.netlify.com/
MIT License
84 stars 64 forks source link

_nightwatchApi.client.expect.elements is not a function #524

Closed sam3k closed 5 years ago

sam3k commented 5 years ago

Your issue may already be reported! Please search on the issue track before creating one.

Expected Behavior

I'm trying to use .elements().count as described here: https://nightwatchjs.org/api#expect-elements-

Current Behavior

Cucumber/Nightwatch fails step with: _nightwatchApi.client.expect.elements is not a function

Steps to Reproduce (for bugs)

step.js

Then('I expect to see the list populated', async () => {
  await client
    .expect
    .elements('.my-ul-selector .my-li-selector').count.to.be.above(0);
});

package.json

{
  ...
  "dependencies": {
    ...
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "bourbon": "^5.1.0",
    "bulma": "^0.7.2",
    "chromedriver": "^74.0.0",
    "classnames": "^2.2.6",
    "cucumber-html-reporter": "^5.0.0",
    "cucumber-pretty": "^1.5.0",
    "env-cmd": "^8.0.2",
    "file-saver": "^2.0.1",
    "hoist-non-react-statics": "^3.2.1",
    "lodash": "^4.17.11",
    "mkdirp": "^0.5.1",
    "mobx": "^5.8.0",
    "mobx-react": "^5.4.3",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.23",
    "node-sass": "^4.11.0",
    "query-string": "^6.2.0",
    "react": "^16.6.3",
    "react-content-loader": "^4.2.1",
    "react-device-detect": "^1.6.2",
    "react-dom": "^16.6.3",
    "react-livechat": "^1.1.1",
    "react-lottie": "^1.2.3",
    "react-responsive": "^6.1.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.1",
    "react-transition-group": "^2.6.0",
    "react-virtualized": "^9.21.0",
    "vcards-js": "^2.10.0"
  },
  "scripts": {
    ...
    "e2e:testchrome": "cross-env NIGHTWATCH_ENV=chrome npm e2e:test",
    "e2e:test": "mkdirp report && cucumber-js --require-module babel-core/register --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty --format json:report/cucumber_report.json",
    "e2e-report": "node create-html-report.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "devDependencies": {
    ...
    "cross-env": "^5.2.0",
    "cucumber": "^5.1.0",
    "nightwatch": "^1.0.19",
    "nightwatch-api": "^2.2.1",
    "typescript": "^3.2.2"
  }
}

Context

I cannot write any test that uses "expect". Only "assert". I am trying to find if there is more than 0 elements in a list. Meaning, if a list is empty or not by checking the className of the list item.

Your Environment

mucsi96 commented 5 years ago

Thanks for reporting this. During next few days I will have no time to check this. But later I can. We are happy to receive a pull request fixing this.

spnraju commented 5 years ago

Hi @sam3k , could you please try as below.

https://github.com/nightwatchjs/nightwatch/blob/0f9ca807d023a8316e040651d93eff7cd7b7b9dd/test/src/api/expect/testExpectCount.js#L21

Please let us know if it works.

sam3k commented 5 years ago

Hi @spnraju I've just tried:

let expect = await client.api.expect.elements...
let expect = await expect.elements.....
let expect = await client.expect.elements...

In all cases always got "Cannot read property 'elements' of undefined". Not sure if this is due to me using Cucumber+Nightwatch.

@mucsi96, I'm going to clone the repo and see if I can debug; but it almost sounds like I have a typo in my code.

Btw, these are my imports and original step definition that fails:

import { client } from 'nightwatch-api';
import { Given, Then } from 'cucumber';

Then('I expect to see the Org Hierarchy section on this profile', async () => {
  await client
    .expect
    .elements('.list .card').count.to.be.above(0);

  /* This didn't work either
  await client.pause(3000);
  expect.elements('.list .card').count.to.be.above(0);
  */
});

Btw, I'm basing my cucumber+nightwatch implementation off of the cucumber example: https://github.com/mucsi96/nightwatch-api/tree/master/packages/cucumber-example

sam3k commented 5 years ago

I've found the issue. Somehow I ended up with an older version of Nightwatch. Upgrading to "nightwatch": "^1.1.11" fixed the issue. Closing this. Thank you all.