nightwatch-cucumber icon indicating copy to clipboard operation
nightwatch-cucumber copied to clipboard

Not able to click a link on a page using the Nightwatch Page Object model with Cucumber.

Open JaspreetBamrah opened this issue 7 years ago • 2 comments

I have setup my project using cucumber [feature, step definitions and page object classes]. My feature looks like: Feature: Login Scenario: Login Functionality Given I launch home page Then I click on Sign In And the login page is launched

My Step Definition file:

const { client } = require('nightwatch-cucumber');
const { defineSupportCode } = require('cucumber');
const homePage = client.page.home();
const loginPage = client.page.login();
defineSupportCode(({ Given, Then, When }) => {
  Given('I launch home page', async () => {
    // Write code here that turns the phrase above into concrete actions
    await homePage
     .navigate()
     .waitForElementVisible('@body', 1000);
  });
  Then('I click on Sign In', async () => {
    // Write code here that turns the phrase above into concrete actions
    homePage
     .submit();
  });
  Then('the login page is launched', async () => {
    // Write code here that turns the phrase above into concrete actions
 });
});

My home page object class is like:

module.exports = {  
    url: 'https://www.homeimprovementpages.com.au',
    elements: {
      body: 'body',
      signInLink: {
        selector: "a[title='Sign in']",
      }
    },
    commands: [{
        submit: function(){          
             function callback () {
                console.log('is client: yesssss ');
           }
           console.log('in submit ----- ');
           this
            .waitForElementVisible('@signInLink',1000)
            .click('@signInLink',callback());
          }
      }]
  };

The result looks like: Starting selenium server... started - PID: 63132 ✔ Element was visible after 311 milliseconds. .in submit ----- is client: yesssss .. 1 scenario (1 passed) 3 steps (3 passed) 0m05.928s

However the login element doesn't gets clicked. What am I missing here? Can you guide please? I am new to this node and nightwatch. Please help!

Regards Jas

JaspreetBamrah avatar Nov 01 '17 05:11 JaspreetBamrah

At a quick glance..

.click('@signInLink', callback());

should be

.click('@signInLink', callback);

Further you could add some error handling in the (optional callback) of the .click command, like..

...
submit: function() {
  function callback(result) {
    if (result.status !== 0) {
      throw new Error('Could not click "@signInLink"')
    }
  }
  // ...
  this.click('@signInLink', callback);
}

regards

davidlinse avatar Feb 06 '18 15:02 davidlinse

We have the same issue on 0.9.

This fails ~90% of the time:

await creatives.waitForElementVisible('@newPortfolioItemDialogSubmit', 5000)
    .click('@newPortfolioItemDialogSubmit')

While this works:

await creatives.waitForElementVisible('@newPortfolioItemDialogSubmit', 5000)
    .click('.creative-new-portfolio-item__dialog-submit')

dominik-bln avatar Jun 04 '18 15:06 dominik-bln