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

setValue error does not provide a stackTrace #2001

Closed
hcmec opened this issue Jan 23, 2019 · 2 comments · Fixed by #2658
Closed

setValue error does not provide a stackTrace #2001

hcmec opened this issue Jan 23, 2019 · 2 comments · Fixed by #2658

Comments

@hcmec
Copy link
Contributor

hcmec commented Jan 23, 2019

If I try to .setValue on an element that does not exist, I do not get a stackTrace this breaks at. This is more irritating if the .setValue call is in a pageObject
See the #purposelyBroken and setPurposelyBroken() lines below

// Filename: examples/tests/googlePageObject.js
module.exports = {
  'Demo Google search test using page objects' : function (client) {
    var homePage = client.page.home();
    homePage.navigate();
    homePage.expect.element('@searchBar').to.be.enabled;

    homePage.setValue('@searchBar', 'Nightwatch.js');
    homePage.submit();
    homePage.setValue('#purposelyBroken', "Purposely Broken");   
    homePage.setPurposelyBroken(); // calls setValue from a pageObject

    var resultsPage = client.page.searchResults();
    resultsPage.expect.element('@results').to.be.present.after(2000);
    resultsPage.expect.element('@results').to.contain.text('Nightwatch.js');
    resultsPage.expect.section('@menu').to.be.visible;

    var menuSection = resultsPage.section.menu;
    menuSection.expect.element('@web').to.be.visible;
    menuSection.expect.element('@video').to.be.visible;
    menuSection.expect.element('@images').to.be.visible;
    menuSection.expect.element('@shopping').to.be.visible;

    menuSection.productIsSelected('@web', function(result) {
      this.assert.ok(result, 'Web results are shown by default on search results page');
    });

    client.end();
  }
};
// Filename: examples/pages/home.js
const searchCommands = {
  submit() {
    this.waitForElementVisible('@submitButton', 1000)
      .click('@submitButton')
      .api.pause(1000);

    return this; // Return page object for chaining
  },
  setPurposelyBroken() {
    this.setValue('@searchBarPurposelyBroken', "Purposely Broken");
    return this; // Return page object for chaining
  }
};

module.exports = {
  url: 'http://google.com',
  commands: [searchCommands],
  elements: {
    searchBar: {selector: 'input[name=q]'},
    searchBarPurposelyBroken: {selector: '#purposelyBroken'},
    submitButton: {selector: 'input[value="Google Search"]'}
  }
};

actual output:

/Users/hench/git/nightwatch$ bin/nightwatch examples/tests/googlePageObject.js

[Tests/Google Page Object] Test Suite
=====================================
Running:  Demo Google search test using page objects

✔ Expected element <Element [name=@searchBar]> to be enabled - condition was met in 24ms
  Warning: More than one element (2) found for <Element [name=@submitButton]> with selector: "input[value="Google Search"]". Only the first one will be used.
✔ Element <input[value="Google Search"]> was visible after 541 milliseconds.
 Error while running .locateSingleElement() protocol action: no such element: Unable to locate element: {"method":"css selector","selector":"#purposelyBroken"}

 Error while running .locateSingleElement() protocol action: no such element: Unable to locate element: {"method":"css selector","selector":"#purposelyBroken"}

✔ Expected element <Element [name=@results]> to be present after 2000ms - element was present in 12ms
✔ Expected element <Element [name=@results]> text to contain: "Nightwatch.js" - condition was met in 172ms
✔ Expected element <Element [name=@menu]> to be visible - condition was met in 25ms
✔ Expected element <Section [name=menu],Element [name=@web[0]]> to be visible - condition was met in 38ms
✔ Expected element <Section [name=menu],Element [name=@video[0]]> to be visible - condition was met in 27ms
✔ Expected element <Section [name=menu],Element [name=@images[0]]> to be visible - condition was met in 26ms
✔ Expected element <Section [name=menu],Element [name=@shopping[0]]> to be visible - condition was met in 26ms
✔ Passed [ok]: Web results are shown by default on search results page

OK. 10 assertions passed. (5.198s)

expected output:

/Users/hench/git/nightwatch$ bin/nightwatch examples/tests/googlePageObject.js

[Tests/Google Page Object] Test Suite
=====================================
Running:  Demo Google search test using page objects

✔ Expected element <Element [name=@searchBar]> to be enabled - condition was met in 24ms
  Warning: More than one element (2) found for <Element [name=@submitButton]> with selector: "input[value="Google Search"]". Only the first one will be used.
✔ Element <input[value="Google Search"]> was visible after 537 milliseconds.
 Error while running .locateSingleElement() protocol action: no such element: Unable to locate element: {"method":"css selector","selector":"#purposelyBroken"}
 Error
    at Command.executeCommand (/Users/hench/git/nightwatch/lib/page-object/command-wrapper.js:149:22)
    at Page.setValue (/Users/hench/git/nightwatch/lib/page-object/command-wrapper.js:36:25)
    at Object.Demo Google search test using page objects (/Users/hench/git/nightwatch/examples/tests/googlePageObject.js:9:14)
    at Context.call (/Users/hench/git/nightwatch/lib/testsuite/context.js:203:32)
    at TestCase.run (/Users/hench/git/nightwatch/lib/testsuite/testcase.js:49:31)
    at Runnable.handleRunnable [as __runFn] (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:349:32)
    at Runnable.run (/Users/hench/git/nightwatch/lib/testsuite/runnable.js:123:21)
    at TestSuite.createRunnable (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:416:33)
    at TestSuite.handleRunnable (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:420:17)
    at createSession.then.then._ (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:348:21)
 Error while running .locateSingleElement() protocol action: no such element: Unable to locate element: {"method":"css selector","selector":"#purposelyBroken"}
 Error
    at Command.executeCommand (/Users/hench/git/nightwatch/lib/page-object/command-wrapper.js:149:22)
    at Page.setValue (/Users/hench/git/nightwatch/lib/page-object/command-wrapper.js:36:25)
    at Page.setPurposelyBroken (/Users/hench/git/nightwatch/examples/pages/home.js:10:10)
    at Object.Demo Google search test using page objects (/Users/hench/git/nightwatch/examples/tests/googlePageObject.js:10:14)
    at Context.call (/Users/hench/git/nightwatch/lib/testsuite/context.js:203:32)
    at TestCase.run (/Users/hench/git/nightwatch/lib/testsuite/testcase.js:49:31)
    at Runnable.handleRunnable [as __runFn] (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:349:32)
    at Runnable.run (/Users/hench/git/nightwatch/lib/testsuite/runnable.js:123:21)
    at TestSuite.createRunnable (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:416:33)
    at TestSuite.handleRunnable (/Users/hench/git/nightwatch/lib/testsuite/testsuite.js:420:17)
✔ Expected element <Element [name=@results]> to be present after 2000ms - element was present in 15ms
✔ Expected element <Element [name=@results]> text to contain: "Nightwatch.js" - condition was met in 216ms
✔ Expected element <Element [name=@menu]> to be visible - condition was met in 25ms
✔ Expected element <Section [name=menu],Element [name=@web[0]]> to be visible - condition was met in 41ms
✔ Expected element <Section [name=menu],Element [name=@video[0]]> to be visible - condition was met in 27ms
✔ Expected element <Section [name=menu],Element [name=@images[0]]> to be visible - condition was met in 28ms
✔ Expected element <Section [name=menu],Element [name=@shopping[0]]> to be visible - condition was met in 29ms
✔ Passed [ok]: Web results are shown by default on search results page

OK. 10 assertions passed. (5.154s)
@beatfactor beatfactor added this to Needs triage in Nightwatch v1.0/v1.1 via automation Jan 24, 2019
@beatfactor beatfactor moved this from Needs triage to Low priority in Nightwatch v1.0/v1.1 Jan 24, 2019
@hcmec
Copy link
Contributor Author

hcmec commented Jan 24, 2019

Most likely a duplicate to https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/nightwatchjs/Q_REauTClF8/0R7GsEGXDAAJ
PR #2002

@cskubatz
Copy link

I have pre-tested the current nightwatch version (1.0.19) with this PR and it works correctly.

afterPatch

Thanks and best regards
Chris

@beatfactor beatfactor added this to Needs triage in Nightwatch 1.2 via automation Aug 25, 2019
@beatfactor beatfactor removed this from Low priority in Nightwatch v1.0/v1.1 Aug 25, 2019
@beatfactor beatfactor moved this from Needs triage to Low priority in Nightwatch 1.2 Aug 25, 2019
@beatfactor beatfactor added this to Needs triage in Nightwatch 1.7 via automation Mar 15, 2021
@beatfactor beatfactor removed this from Low priority in Nightwatch 1.2 Mar 15, 2021
@beatfactor beatfactor moved this from Needs triage to Low priority in Nightwatch 1.7 Mar 15, 2021
gravityvi pushed a commit to gravityvi/nightwatch that referenced this issue Apr 17, 2021
gravityvi pushed a commit to gravityvi/nightwatch that referenced this issue Apr 17, 2021
Nightwatch 1.7 automation moved this from Low priority to Closed Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment