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

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

Open
JaspreetBamrah opened this issue Nov 1, 2017 · 2 comments

Comments

@JaspreetBamrah
Copy link

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

@davidlinse
Copy link

davidlinse commented Feb 6, 2018

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

@dominik-bln
Copy link

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')

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

3 participants