I have an angular app working with a non angular login page. The angular app is loaded only if user is logged in.
I have e2e-tested my non-angular login page with protractor&jasmine by following this post, running my test-code located in e2e/login.spec.js
and using browser.ignoreSynchronization = true
to prevent that there is no angular loaded.
I would like now to run some test against my angular app but I can't because the backend redirect to the login page. That's means I need to log a testingUser for each angular view test. Not really effective if there is a lot of test.
I know there is a solution when the login page is in the angular side by mocking my backend API (see same post) but can't work with what I have.
Is there a way to keep the user logged in? What is it? Or any other work around? Do I need to implement a dev login page inside the angular app just for testing?
In my config file I have an onPrepare object with lots of variables. this includes a login function, as so:
global.loginFn = function loginFn() {
usernameInput.sendKeys(username);
passwordInput.sendKeys(password);
login.click();
};
you can add the browser.ignoreSynchronization if needed, as so:
global.loginFn = function loginFn() {
browser.ignoreSynchronization = true;
usernameInput.sendKeys(username);
passwordInput.sendKeys(password);
login.click();
};
then in my spec.js files I can do this:
beforeAll(function () {
browser.get('myUrl');
loginFn();
};
in your it blocks you can then add the
browser.ignoreSynchronization = false;
so it knows to wait for angular again. you could even try putting
beforeAll(function () {
browser.get('myUrl');
loginFn();
browser.ignoreSynchronization = false;
};
so you don't have to repeat yourself, I haven't personally had to do it that way, but it should work.
this way any tests you need to run in that spec file, the user will be logged in, and it doesn't have to log them in before each test, just before all the tests in that specific test suite.
or if all your tests need the user logged in, you can just log the user in using the onPrepare, instead of just creating a function to be called at a specific time.
I have exactly the same use case, there several possible ways which I went through:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With