Abhas Arya
Abhas Arya

Reputation: 470

AngularJS E2E test in protractor failing

I'm basically trying to write tests for this webpage: http://www.talklocal.com/mobile/#/step1

I want to fill out the information in the form, and click the next button. While the test should redirect me to step 2 (check the url) of the form, it does not and instead fails. Code for the tests:

describe('going from step1 to step 2', function() {

        //fill out step 1 form
        beforeEach(function() {
            browser.get('index.html');

            element(by.model('Request.categoryID')).click();
            element(by.css('option[value=0]')).click();
            element(by.class('where-text ng-pristine ng-valid').sendKeys('20902'));

            element(by.class('btn action-button')).click();
        });

        it('should be on the step2 page', function() {

            browser.getLocationAbsUrl().then(function(url) {
                expect(url.split('#')[1]).toBe('/step2');
            });
        });
    });

Error messages in terminal:

  1) myApp going from step1 to step 2 should be on the step2 page
   Message:
     TypeError: Object [object Object] has no method 'class'
  2) myApp going from step1 to step 2 should be on the step2 page
      Message:
      Expected '/step1' to be '/step2'.
  3 tests, 5 assertions, 2 failures

I've googled the errors, and have been trying to plug in different classes and attributes for the element(by.attribute) method but to no avail.

I would appreciate any and all feedback on this issue. Thanks!

Upvotes: 2

Views: 261

Answers (2)

alecxe
alecxe

Reputation: 473763

There is no by.class locator, if you want to rely on classes - use by.css instead:

element(by.css('.where-text.ng-pristine.ng-valid').sendKeys('20902'));
element(by.css('.btn.action-button')).click();

FYI, there is also by.className selector:

element(by.className('action-button')).click();

Upvotes: 2

user2388556
user2388556

Reputation: 299

Check protractor API doc
by.class is invalid. You can use model or button text for button.

element(by.model('User.zipcode').sendKeys('20902'));
element(by.buttonText('Next')).click();

Upvotes: 0

Related Questions