Can common carrier test scenarios run?
Is there a way to implement a protractor test case, say a login script, once, rather than for each test that requires a user to login? I know using page objects makes it easier to check the login, but it would be nice to just register a user and then run all my tests and then log the user out once, then do that for each test block.
+3
source to share
1 answer
// if you want to login and logout before every 'it' statement:
var loginPage = require('./login.js');
describe('this test spec', function() {
beforeEach(function() {
loginPage.login();
});
afterEach(function() {
loginPage.logout();
});
it('should log in and out with the first test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
it('should log in and out with the second test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
});
OR
// if you want to login before every 'spec' file and stay logged in:
// in protractor.conf.js
// in exports.config
onPrepare: function() {
var blahBlah = require('./login.js');
blahBlah.login();
}
describe('this test spec', function() {
it('should log in before the first test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
it('and stay logged in for the second test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
});
+1
source to share