Protractor: Have a shared beforeEach/afterEach running tests with "shardTestFiles:true"

Created on 7 Apr 2015  路  2Comments  路  Source: angular/protractor

If we want a shared beforeEach function to run on all test specs of our test suite, we just need to create a file with a beforeEach function and make it execute at the beginning of the suite and "voil谩".. we now have a shared beforeEach function. (This is also valid for afterEach function)

But... When we start running our tests with shardTestFiles:true this doesn't work, because each instance runs specific test-specs and we cannot guarantee that the file with the beforeEach function will run before each test-spec. Anyone knows a way to make it work?

A good way to make it work is having two more configurations on the "protractor.conf.js" file named: afterEach and beforeEach. Similar to what we have now for onPrepare. What do you guys think?

question

Most helpful comment

You could put the beforeEach into the onPrepare block. Alternatively, make a helper file and use node's require on it at the start of each file.

Closing as an answered question.

All 2 comments

You could put the beforeEach into the onPrepare block. Alternatively, make a helper file and use node's require on it at the start of each file.

Closing as an answered question.

Thanks for the reply @juliemr! We were doing the alternative that you've suggested (sort of). Although, we started to have a lot of repeated code and now, we want to have a common afterEach function and we don't like the idea of doing it that way.

So... We will put the beforeEach/afterEach function on the onPrepare() function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smarts picture smarts  路  3Comments

nt3rp picture nt3rp  路  3Comments

davidkarlsen picture davidkarlsen  路  3Comments

rafalf picture rafalf  路  3Comments

luakri picture luakri  路  3Comments