JavaScript: Choosing dropdown list items using Page Objects for Protractor testing

So I can't figure this one out.

My test calls for choosing a list item as part of a form to create a new user. However, when I run the test it does not choose an item from the list. And Protractor doesn't return any errors, it thinks the test was a success.

The function I was using previously worked, but in an effort to reduce code repetition, and increase fluidity and flexibility I have started converting the test to incorporate Page Objects.

Below is my test document which shows the functions being called in from two different page objects:

it('Should create first new User.', function() {
    var users_page = require('../page/users_page.js');
    var addUser_page = require('../page/addUser_page.js');;
    addUser_page.addUser('Test', 'Smith', '[email protected]', 'Password', 'Password', '0');

Everything works here apart from line 6 - choosing a list item.

Below is the snippet from the page object I refer to when calling the .userRole function:

this.userRole = function (index) {

NOTE: There is NOT a problem with the Page Objects talking to the test as there are multiple other functions that DO work.

Let me know if you need any more information, cheers.



I ran into this problem a few times; if you want to click the object you'll need to write something like this in your Page Object:

this.clickUserRoleByIndex = function (index) {

OR what I think you want to do...

You can do something like this to get that object:

this.getUserRoleByIndex = function (index) {
    return this.element(by.model('tes.userRole')).$('[value="'+index+'"]');

Note the return gives you that object to then interact with in the full test - I got bitten by it before I realised that of course it'll be undefined unless I return something in that function!

Hope that helps! :D


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.