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.

Some commands are not chainable with pageObjects.

See original GitHub issue

some functions like ‘getHTML’, ‘selectByIndex’ are not working with PageObject. [v4 with wdio]

File: pageobjects/registration.page.js

...
var registrationPage = Object.create(page, {
    textBox_email: { get: function() { return browser.element('#email'); } },
    dropDown_sex : { get: function() { return browser.element('select[name=sex]'); } }

...

file: tests/example.js

var RegistrationPage = require ('../pageobjects/client/registration.page');
...
RegistrationPage.textBox_email.setValue(suiteData.email); // works 
browser.selectByIndex('select[name=sex]',1);    // works

RegistrationPage.dropDown_sex.selectByIndex(1); // error: number or type of arguments don't agree with selectByIndex commandcode

RegistrationPage.dropDown_sex.selectByIndex errors out with message

“number or type of arguments don’t agree with selectByIndex commandcode”

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
christian-bromanncommented, Mar 22, 2016

number or type of arguments don’t agree with selectByIndex command

I have to fix that for couple of commands which do parameter checks

when the element doesn’t exist

In your page object I would recommend to always use the elements commands to query elements. This way you don’t get these errors and getText returns [] which is assertable

1reaction
patthielcommented, Mar 22, 2016

this might be a little hacky, but you could do this for your page object…

textBox_email: { get:  
    try { 
        return browser.element('#email'); 
    }
    catch(err) { 
        return false;
    } 
},

This will try the command, and if it finds the element return true, if it doesn’t find the element and returns any error, it’ll return false.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chaining commands breaks page api · Issue #884
Here's a sample page object that chains commands: const myCommands = { someCommand: function() { return this.navigate('/some-page') .
Read more >
Cypress JS using multiple page objects in one method
How to do it with Custom Commands instead of pageObject. Chaining is a natural code pattern for Cypress commands, so using Custom Commands....
Read more >
Stop using Page Objects and Start using App Actions
They use selectors to find elements, which is NOT checked by any linter ... Returns chain so you can attach more Cypress commands...
Read more >
What is Page Object Pattern in Cypress? How to Implement ...
To achieve this, create a new folder with the name 'Page Objects' under cypress/support directory and then under that, create files which will ......
Read more >
Abstract away! Page Objects vs Custom Commands in ...
So, if some structural change happens on the web page, it will just impact the page object and will not have any impact...
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