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?
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.
Most helpful comment
You could put the
beforeEachinto theonPrepareblock. Alternatively, make a helper file and use node'srequireon it at the start of each file.Closing as an answered question.