Sanjani Gunathilaka
Sanjani Gunathilaka

Reputation: 249

How to navigate to a page in website rather than home page using protractor and test operations in it?

I want to navigate to users page on my website using the protractor and I made 2 navigation functions and tried to run it, but it just tested only login part then stopped without navigating to the required page.

describe('users', () => {
    let page: UsersPage;
    let pageLogin: LoginPage;

    beforeEach(() => {
        pageLogin = new LoginPage();
        pageLogin.navigateTo();
        pageLogin.getEmailLogin().sendKeys(browser.params.login.user);
    pageLogin.getPasswordLogin().sendKeys(browser.params.login.password);
        pageLogin.getSubmitLogin().click();
        page = new UsersPage();
        page.navigateToM();
    });

    it('Should display text box', () => {
        page.textBox().sendKeys('j');
    });
});

And :

    navigateToM() {
        return browser.get('/users');
    }

    textBox() {
        return element(by.css('input[placeholder="Type a text"]'));
    }

Upvotes: 0

Views: 530

Answers (1)

quirimmo
quirimmo

Reputation: 9988

Be careful that protractor code is always async.

Your code should look something like the following:

page.navigateToM().then(() => {
  browser.waitForAngular().then(() => {
    page.textBox().sendKeys('j');
  });
});

Upvotes: 1

Related Questions