question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using element selectors in callback function fail

See original GitHub issue

This is what I have to make it work but if I try to use the @userName instead of #email css selector it will fail. Note im just using the callback function on the login page as an example.

  login: function(userName, password) {
    if (typeof username || password == "undefined")
    {
      userName = 'nouser@blah.com';
      password = '1234lkjlkj'
    }
    this.getText('h2', function(result){
    if(result.value == 'Sign in')
      {
        this.waitForElementVisible( '#email', 3000, 'Login Page Loaded')
          .setValue( '#email', userName)
          .setValue( '#password', password)
          .waitForElementVisible('input[type=submit]', 3000, 'Submit Button Was Visible')
          .click('input[type=submit]');
        return this; // Return page object for chaining
      }
   } )
  }
};

module.exports = {
  url: 'http://whateveraddress.com',
  commands: [loginCommands],
  elements: {
    userName: '#email',
    password: '#password',
    submitButton: 'input[type=submit]'
  }
};```

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
senocularcommented, Nov 7, 2016

You can use this, you just have to do so with the understanding that it won’t be your page object. You can, however, force it to be your page object by using bind()

    this.getText('h2', function(result){
    if(result.value == 'Sign in')
      {
        this.waitForElementVisible( '#email', 3000, 'Login Page Loaded')
          .setValue( '#email', userName)
          .setValue( '#password', password)
          .waitForElementVisible('input[type=submit]', 3000, 'Submit Button Was Visible')
          .click('input[type=submit]');
      }
   }.bind(this)) // bind this in callback to be the surrounding context this (the page object)
0reactions
dgocodercommented, Nov 10, 2016

Nvm I figured it out. Was having 0,0 as part of moveToElement. having it as undefined fixed the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to bind a callback by passing in the function throws an ...
I just want to fire an event when an input changes value using jQuery 1.7.2 and Backbone.js.
Read more >
Changed error handling: Test always fails when click returns ...
We have a custom command that attempts to click on a element, but sometimes the element is not clickable. In previous versions of...
Read more >
Cypress should callback - Gleb Bahmutov
Cypress should callback. Use any assertion inside "should(cb)" function to have Cypress auto-retry its command with your assertion function.
Read more >
Select Page Elements | Basic Guides - TestCafe
TestCafe outputs information about failed selectors to test run reports. When you try to use a selector that does not match any DOM...
Read more >
click | API Reference - Nightwatch.js
If the element is not found, an error is thrown which will cause the test to fail. You can suppress element not found...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found