nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.83k stars 1.32k forks source link

Nightwatch retries doesn't run custom commands in next run #1421

Closed thakareshweta closed 5 years ago

thakareshweta commented 7 years ago

I am using a custom command to clear input fields (and many other custom commands for other functionalities) When I run a simple login function, the custom commands work as desired but when I use --retries the same custom command fails to find the element in retry logic. This is my custom command:

exports.command = function (inputFields) {
  let field;
  for (field of inputFields) {
    this
      .waitForElementVisible(field)
      .clearText(field);
  }
  return this;
};

it fails at .waitForElementVisible(field), but I wonder why it works in the first run?

More on tests:

  1. Log in by inputting email and password 1.1 send [email, password] to clearText custom commands to clear any input
  2. After logging in, the tests fail on purpose (just to try --retries)
  3. The next iteration start but it fails to .waitForElementVisible(field) from custom command which earlier worked just fine on the very first run.
beatfactor commented 7 years ago

Can you provide a sample test that reproduces the problem? Do you think it's a bug in Nightwatch?

thakareshweta commented 7 years ago

I am not sure if it's a nightwatch bug.

feature.js


export default {
  'User logs in': (client) => {
const loginPage = client.page.loginPage();
    const landingPage = client.page.landingPage();

    loginPage
      .navigate()
      .login(process.env.USER_EMAIL, process.env.USER_PASSWORD);
    landingPage
      .waitForElementVisible('@openTransactionButton');
    client.end();
  }
};

loginPage.js

const loginCommands = {
  login(email, pass) {
    return this
      .waitForElementVisible('@emailInput')
      .clearInputFields([this.elements.emailInput.selector,
                        this.elements.passwordInput.selector])
      .setValue('@emailInput', email)
      .setValue('@passwordInput', pass)
      .waitForElementVisible('@loginButton')
      .click('@loginButton');
  }
};

export default {
  url: function() {
    return this.api.launchUrl + '/#/login';
  },
  commands: [loginCommands],
  elements: {
    emailInput: {
      selector: '#login-email'
    },
    passwordInput: {
      selector: 'input[type=password]'
    },
    loginButton: {
      selector: 'input[type=submit]'
    },
  }
};

custom command clearInputFields.js

exports.command = function (inputFields) {
  let field;
  for (field of inputFields) {
    this
      .waitForElementVisible(field)
      .clearText(field);
  }
};

custom Command clearText.js

exports.command = function (textElement) {
    return this
    .waitForElementVisible(textElement)
    .getValue(textElement, (result) => {
      for (var char of result.value) {
        this.setValue(textElement, '\u0008');
      }
    });
};

below is the output

[Logout] Test Suite
=======================

Running:  User Logs out
 ✔ Element <#login-email> was visible after 45 milliseconds.
 ✔ Element <#login-email> was visible after 17 milliseconds.
 ✔ Element <#login-email> was visible after 22 milliseconds.
 ✔ Element <input[type=password]> was visible after 32 milliseconds.
 ✔ Element <input[type=password]> was visible after 18 milliseconds.
 ✔ Element <input[type=submit]> was visible after 44 milliseconds.
 ✖ Timed out while waiting for element <//button/span[contains(text(),"Open TTransaction")]> to be present for 1000 milliseconds.  - expected "visible" but got: "not found"
    at Object.UserLogsOut [as User Logs out] (/Users/shwetathakare/work/powersell/tests/features/logout.js:11:8)

Retrying (1/2):  User Logs out
 ✔ Element <#login-email> was visible after 34 milliseconds.
 ✖ Timed out while waiting for element <#login-email> to be present for 1000 milliseconds.  - expected "visible" but got: "not found"
    at Object.exports.command (/Users/shwetathakare/work/powersell/tests/customCommands/clearInputFields.js:5:8)

Retrying (2/2):  User Logs out
 ✔ Element <#login-email> was visible after 37 milliseconds.
 ✖ Timed out while waiting for element <#login-email> to be present for 1000 milliseconds.  - expected "visible" but got: "not found"
    at Object.exports.command (/Users/shwetathakare/work/powersell/tests/customCommands/clearInputFields.js:5:8)

FAILED:  1 assertions failed and 1 passed (3.409s)

 _________________________________________________

 TEST FAILURE:  1 assertions failed, 1 passed. (11.557s)

 ✖ logout

   - User Logs out (3.409s)
   Timed out while waiting for element <#login-email> to be present for 1000 milliseconds.  - expected "visible" but got: "not found"
       at Object.exports.command (/Users/shwetathakare/work/powersell/tests/customCommands/clearInputFields.js:5:8)
thakareshweta commented 7 years ago

When in custom commands I write ,

this
      .elements(selector, field, function (elementsArray) {
      console.log(elementsArray.value.length);
});

the length is 1, but waitForElementVisible fails.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.