I have an application on which I want to implement multiple E2E testing scenarios, each specific to a section of the application. The problem is that my application requires a login. I have created a login scenario, it all works fine. For describing a different scenario, I need to be able to reuse the code for the login one. How can I do that?
describe('login page flow', function () {
it('should open the login page', function () {
browser().navigateTo('/#/login');
sleep(1);
expect(browser().window().hash()).toBe('/login');
});
it('should have login elements', function () {
expect(element('#username').count()).toBe(1);
expect(element('#password').count()).toBe(1);
});
it('should be able to login successfully', function () {
input('ui.username').enter('user');
input('ui.password').enter('pass');
element('#signin').click();
sleep(1);
expect(browser().window().hash()).toBe('/welcome/');
});
});
The only thing that I could think of was to write this in a beforeEach, but I don't think that's quite a clean solution. Any ideas?