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

Custom Command with .execute expects "selector" object, cannot provide Array or Object #2018

Closed
thaddeusreid opened this issue Feb 4, 2019 · 4 comments

Comments

@thaddeusreid
Copy link

thaddeusreid commented Feb 4, 2019

I'm upgrading from 0.9.x to 1.x.x and have hit a roadblock. Looking for other's experience with my failure led me to #1237, #1882, and #1969 , however what I'm documenting hasn't been shared yet.

Sample Test

// myPage.js
module.exports = {
  elements: {
    myElement: '#selector'
  }
};
// customCommand.js
exports.command = function(list) {
  this.execute(
    function(data) {
      return data;
    },
    [list],
    function(result) {
      console.log(result);
    }
  );
  return this;
};
// test.js
module.exports = {
  'Demo test': function (browser) {
    const dataForCommand = ['foo'];
    browser.page.myPage()
      .navigate(browser.launchUrl)
      .customCommand(dataForCommand)
      .api.end();
  }
};

Run the test. I'm using nightwatch@1.0.18, node@10.14.1, chromedriver@2.41.0, macOS 10.14.2

Expected Behavior

I can provide Arrays and Objects to a custom command -> .execute function and the test should run without any errors.

Actual Behavior

The test fails with the following error:

➜  nightwatch-bug-report git:(master) ✗ npm run test:9999

> nightwatch-bug-report@1.0.0 test:9999 /Users/thaddeusreid/nightwatch-bug-report
> nightwatch --config tests/9999/nightwatch.conf.js


[Test] Test Suite
=================
Running:  Demo test

   No selector property for selector object. Instead found properties: 0
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)

FAILED: 1 errors (10ms)
   No selector property for selector object. Instead found properties: 0
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)
_________________________________________________

TEST FAILURE: 1 error during execution 0 tests failed, 1 passed. 1.759s

 ✖ test
 – Demo test (10ms)
   Error: No selector property for selector object. Instead found properties: 0
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)

  No selector property for selector object. Instead found properties: 0
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)


npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! nightwatch-bug-report@1.0.0 test:9999: `nightwatch --config tests/9999/nightwatch.conf.js`
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the nightwatch-bug-report@1.0.0 test:9999 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/thaddeusreid/.npm/_logs/2019-02-04T23_54_50_257Z-debug.log

I added a PR to https://github.com/aberonni/nightwatch-bug-report that includes a reproducible test of this bug: aberonni/nightwatch-bug-report#3

@thaddeusreid
Copy link
Author

thaddeusreid commented Feb 4, 2019

I can modify dataForCommand to be an object, and we still fail:

// when dataForCommand = { foo: 'bar', wiz: true };
[Test] Test Suite
=================
Running:  Demo test

   No selector property for selector object. Instead found properties: foo, wiz
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)

FAILED: 1 errors (11ms)
   No selector property for selector object. Instead found properties: foo, wiz
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)
_________________________________________________

TEST FAILURE: 1 error during execution 0 tests failed, 1 passed. 1.607s

 ✖ test
 – Demo test (11ms)
   Error: No selector property for selector object. Instead found properties: foo, wiz
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)

  No selector property for selector object. Instead found properties: foo, wiz
       at Object.Demo test (/Users/thaddeusreid/nightwatch-bug-report/tests/9999/src/test.js:8:8)

Yet, when I make dataForCommand = 'a string';:

[Test] Test Suite
=================
Running:  Demo test

{ sessionId: 'b3fe44972a14ab2aef0301b7c076f32d',
  status: 0,
  value: 'a string' }
No assertions ran.

@thaddeusreid thaddeusreid changed the title Custom Command with .execute expects "selector" object Custom Command with .execute expects "selector" object, cannot provide Array or Object Feb 5, 2019
@thaddeusreid
Copy link
Author

To clarify, this error can be reproduced by running yarn test:2018 in the latest https://github.com/aberonni/nightwatch-bug-report

The test shows that the error only occurs when the custom command is called from a page object.

@beatfactor
Copy link
Member

@thaddeusreid yes, it looks like this same issue reported in #1969 and there will be a fix for that soon.

@thaddeusreid
Copy link
Author

I added a PR to the nightwatch-website-tests repo.

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

No branches or pull requests

2 participants