Sergey
Sergey

Reputation: 7692

Protractor test redirect

I've got an Angular application which I want to test. It has login section and I need to know somehow whether it worked fine (it sent login data, opened a socket connection, redirected to the apps depth and a route guard didn't prevent that redirection).

I've tried

import { AppPage } from './app.po';
import { browser, by, element, until } from "protractor";
import urlContains = until.urlContains;

...

it('should log in', () => {
        page.navigateTo();
        page.fillInputs();
        page.logIn();

        browser.waitForAngular();
        browser.wait(() => {
            return urlContains('dashboard');
        }, 2000);
    });

And it succeeds even if I do fill field with incorrect data and the app doesn't do any redirects. How do I achieve this redirect await and then checking the url?

I'm using Angular 6 if it's important.

Yes, I've seen a similar topic with answer that I don't understand.

Upvotes: 1

Views: 1873

Answers (1)

Ashish Ranjan
Ashish Ranjan

Reputation: 12960

It seems I may have an old version of protractor, I could not find urlContains method the until namespace. I work with ExpectedConditions and it works fine for me.

So using Expected Conditions, you can have a code like:

expect(
  browser.wait(
    protractor.ExpectedConditions.urlContains("dashboard"), 5000
  )
    .catch(() => {return false})
).toBeTruthy(`Url match could not succced`);

I like using a catch so that the script doesn't stop in between whenever an error comes. Also an expect() will mark one test case(useful in reading generated reports).

Upvotes: 6

Related Questions