0
votes

I am newbie to protractor and javascript. I am trying to execute several tests in parallel using multiCapabilities. However when I do this onPrepare or beforeAll are all executing once per every spec. Is there a way to execute onPrepare and onComplete only once for all tests?

I am facing this issue in two situations. 1. Different browsers. 2. Same browser with multiple instance i.e., as follows. capabilities : { browserName : 'chrome', shardTestFiles : true, maxInstances : 2 }, In both cases my code under onPrepare is executing twice. I have a requirement to write the test result of each test to a Json file and I am creating new file in onPrepare and it is getting over written when I use maxinstances > 1

1
Doing so would defeat the purpose of a beforeAll(). What different capabilities are you testing against? Just different browsers? - Obsidian Age
I am facing this issue in two situations. 1. Different browsers. 2. Same browser with multiple instance i.e., as follows. capabilities : { browserName : 'chrome', shardTestFiles : true, maxInstances : 2 }, In both cases my code under onPrepare is executing twice. I have a requirement to write the test result of each test to a Json file and I am creating new file in onPrepare and it is getting over written when I use maxinstances > 1. I tried this with onPrepare and beforeAll() and same result - Nagesh Nagaraja

1 Answers

0
votes

When you are running your protractor test cases with multi capability option, Then the onPrepare method will be executed for each set of capability you have mentioned in multi capabilities object (i.e) Sharded tests run in a different process.

In you case, you need to create your test report file in beforeLaunch method. This method will execute only once before initializing protractor global objects.

Kindly refer https://github.com/angular/protractor/blob/master/lib/config.ts#L404 for additional details on beforeLaunch method.