Reputation: 1214
I am new in the Protractor testing for Angular 6 application. I am trying to write the spec test for login page as below.
describe('Protractor Login checing ', function() {
it('should add one and two', function() {
browser.get('http://localhost:4041/login');
element(by.model('username')).sendKeys('admin');
element(by.model('password')).sendKeys('admin');
element(by.id('login')).click();
// Here, What should I check whether authentication has been done or not..
// expect().toEqual('');
});
});
Actually, In My application, once logic is a success, then I will show a success message in snackBar (Angular material) and redirect into dashboard page.
// Angular 6 application
this.snackBar.open(res.message, '', {
duration: 6000,
});
Here, how should I check in protractor? Anyone help me to do this?
Upvotes: 1
Views: 1128
Reputation: 5927
You should check the url
has changed or not -
describe('Protractor Login checing ', function() {
it('should add one and two', function() {
browser.get('http://localhost:4041/login');
element(by.model('username')).sendKeys('admin');
element(by.model('password')).sendKeys('admin');
element(by.id('login')).click();
browser.wait(waitForUrlChange("http://localhost:4041/dashboard"), 8000, function(){
browser.getCurrentUrl().then(function (currentUrl) {
expect(currentUrl.toEqual("http://localhost:4041/dashboard"));
});
}));
});
function waitForUrlChange(url) {
return function () {
return browser.getCurrentUrl().then(function (currentUrl) {
console.log(currentUrl);
return url === currentUrl;
});
}
}
Upvotes: 1