Question

I'm running E2E tests against an AngularJS site, using Karma and angular-scenario.

I'm executing some login code in a beforeEach function before every it block.

My login function has a timeout delay in it to ensure that the login completes correctly. This is time-consuming and inefficient (not to mention inelegant). In addition, the user would only login once during a session, so this would more accurately model my scenario.

What I'm looking for is a before function that executes the login only once for a collection of it blocks contained within a describe block, but this facility doesn't seem to exist (I've checked the docs and the source code).

Seems like an obvious requirement for a testing library! Has anybody solved this problem?

Was it helpful?

Solution

could you use a variable flag? for example:

var bdone = false;
describe('Search POC', function() {
    beforeEach(function() {
        if (!bdone) {
            browser().navigateTo('login');
            console.log('navigated once');
            bdone = true;
        }
    });

     it ('should have an img link on the login results', function() {
         expect(element('a:last').html()).toMatch(/jpg/);
     });

    it ('should redirect to user details when clicked', function() {
        element('#UserThumbImage:first').click();
        expect(browser().window().href()).toMatch(/user/);
    });


});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top