1
votes

I have a test case in Protractor which loads the home page and then clicks a button that redirects to another page. In that other page I want to grab the value of an element.

describe('todo list', function() {

   it('should find the contact phone number from the home page', function() {

    browser.get('http://homepage...');   

    element(by.id('re_direct_to_contact_page')).click();

    var number = element(by.id('phonenumber')).getText();
    expect(number).toEqual('412-....-...');
  });
});

However although it loads the page it does not check the element value and the test case fails.

How can Protractor load another page to check a value?

NOTE: - I made up this example but in my real test case I am sending data from one page to another so I cannot load the page I want directly.


EDIT: STACK TRACE

protractor conf.js Using the selenium server at http://localhost:4444/wd/hub [launcher] Running 1 instances of WebDriver

Error: Error while waiting for Protractor to sync with the page: "[ng:test] http://errors.angularjs.or/1.4.0/ng/test"

StackTrace: undefined

1 test, 1 assertion, 1 failure

1
How does the test case fail now? Provide the stack trace please.alecxe
@alecxe Updated stack trace.Jebathon
Correct me if I'm wrong, the contact page is a non-angular page?alecxe
thanks, and both has ng-app defined on html or body?alecxe
html - plus I made a change to the conf.js to put rootElement: "[ng-app]"Jebathon

1 Answers

1
votes

It's possible that you might be facing a timing issue. Try re-structuring your test from this:

var number = element(by.id('phonenumber')).getText();
    expect(number).toEqual('412-....-...');

To this:

expect(element(by.id('phonenumber')).getText()).toEqual('412-....-...');

While Jasmine and Protractor try to resolve every promise before moving on, sometimes it doesn't happen as quickly as you would like. Putting the entire promise chain into the expect helps to enforce the resolution of all of them before going through the matcher.