Reputation: 763
I'm currently testing end-to-end functionality for an Angular 2+ project using Protractor.
My issue comes when the user have to login with an external provider. In the APP there is a button that redirects the user to a external login and if the user logged in successfully the provider returns the user to the APP with a token and angular handles the session.
Example:
I want to skip that external login and "mock" it so I can check if my App redirects to the external and handles the token properly. This way my App tests are independent from the external login provider.
In some way I want to intercept the navigation so I can tell Angular: If the user is being redirected to "http://authproviderexample.com/login" instead redirect him to "http://example.com/login?token=ABCDEFG123456789". I will store a permanent token so I can login without lying in the external service.
Upvotes: 1
Views: 109
Reputation: 8948
why don't you do something simple like this
async function login(username, password) {
await loginButton.click();
if (await browser.getCurrentUrl() === "http://authproviderexample.com/login") {
await browser.get("http://example.com/login?token=ABCDEFG123456789")
return
} else {
// else logic
}
}
Upvotes: 2