question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Execute two (or more) protractor scripts with different features & specs in paralell

See original GitHub issue

I have several tests that make a regression test set. The tests are not dependent from each other, but they take a long time to execute sequentially. I thought I could execute them in parallel, probably in 2 or 3 threads or instances.

Spec files are protractor-cucumber-jscript and features are gherkin.

Is this possible to set up using the protractor configuration file?

I tried the following, unsuccessfully:

var featsLocation = 'features/';
var stepsLocation = 'steps/';

exports.config = {
		rootElement: 'html',
		chromeDriver: './srv/build/applications/chromedriver/chromedriver_win32/chromedriver.exe',
		seleniumServerJar: './node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone.jar',
		params:{
			authURL:'',	
			login:{
				email:'',
				passw:''
			}
		},
		resultJsonOutputFile:'',
		getPageTimeout: 60000,
		allScriptsTimeout: 60000,
		maxSessions: 2,
		framework: 'custom',
		frameworkPath: require.resolve('protractor-cucumber-framework'),
		multiCapabilities:[
		     {	
		    	 browserName: 'chrome',
		    	 chromeOptions:{
		    		 args:["--headless"]
		    	 },
		    	 name: 'CAPABILITY_1',
		    	 logName: 'LOGNAME1_USERNAME1_A',
		    	 shardTestFiles: false,
		    	 maxInstances: 1,
		    	 count: 1,
		    	 specs: [   featsLocation+'authenticateCSM.feature'
		    	            , featsLocation+'locationSearch.feature'
		    	        ]
		     },{                  
		    	 browserName: 'chrome',
		    	 chromeOptions:{
		    		 args:["--headless"]
		    	 },
		    	 name: 'CAPABILITY_2',
		    	 logName: 'LOGNAME1_USERNAME2_B',
		    	 shardTestFiles: false,
		    	 maxInstances: 1,
		    	 count: 1,
		    	 specs: [   featsLocation+'authenticateCSM.feature'
		    	            , featsLocation+'shipmentErrors.feature'
		    	        ]
		     }],

		onPrepare: function(){
			global.EC = protractor.ExpectedConditions;
		},		
		baseUrl: '',
		cucumberOpts: {
			tags: '',
			require: [
			            './support/*.js'
			          , stepsLocation+'shipmentErrors/shipmentErrors.spec.js'
			          , stepsLocation+'locationSearch/locationSearch.spec.js'
			         ],
			monochrome: true,
			strict: true,
			plugin: "json"
		},
};

URL and other parameters are passed using package.json.

When executed, I do get tow instances of the selenium driver each one executing a cucumber feature, but then I get a warning message telling me that the *.spec.js files are not defined, but they are placed as it’s defined in the cucumberOptions section of the config file. Right HERE ----> steps/shipmentErrors/shipmentErrors.spec.js and HERE ------> steps/locationSearch/locationSearch.spec.js.

This is the warning message:

[LOGNAME1_USERNAME1_A] Warnings: [LOGNAME1_USERNAME1_A] [LOGNAME1_USERNAME1_A] 1) Scenario: CSM FinalMile: Get authenticated to test Werner CSM Finalmile (SMOKE) - features\authenticateCSM.feature:11 [LOGNAME1_USERNAME1_A] Step: Given CSM FinalMile: Navigate to the Werner SSO initial page - features\authenticateCSM.feature:12 [LOGNAME1_USERNAME1_A] Message: [LOGNAME1_USERNAME1_A] Undefined. Implement with the following snippet: [LOGNAME1_USERNAME1_A] [LOGNAME1_USERNAME1_A] Given(‘CSM FinalMile: Navigate to the Werner SSO initial page’, function (callback) { [LOGNAME1_USERNAME1_A] // Write code here that turns the phrase above into concrete actions [LOGNAME1_USERNAME1_A] callback(null, ‘pending’); [LOGNAME1_USERNAME1_A] });

Is there something I’m doing wrong with the config file syntax… any clues how I should build it?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
ReactiveThingscommented, May 31, 2018

Currently there is no way to execute tests in parallel in only two instances of web browser. I have created an Pull Request that solves this issue. https://github.com/angular/protractor/pull/4836. To enable this feature you have to create custom spec scheduler and add it to the configuration. Here is an example:

function shardScheduler(specs, capabilities) {
  const numberOfShards = capabilities.maxInstances;
  if(numberOfShards > 1) {
      const bucketSize = Math.ceil(specs.length/numberOfShards);
      const shards = [];
      let start = 0
      while (start < specs.length) {
          let end = start + bucketSize;
          if ( end > specs.length) {
              end = specs.length
          }
          shards.push(specs.slice(start,end));
          start = end;
      }
      return shards;
  }
  return [specs];
}

exports.config = {
  ........
  capabilities: {
    shardTestFiles: shardScheduler,
    'browserName': 'chrome',
    maxInstances: 2
  },
........
}
0reactions
IgorSasovetscommented, May 9, 2018

Did you try to run tests from my example? For me all works as expected. Concerning your errors, it seems that there are problems with paths. You can use glob to specify spec file path.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run multiple protractor specs in parallel - Selenium Easy
When you want to run protractor scripts by opening a browser instance for each test, you should add two capabilities shardTestFiles and ...
Read more >
Execute several protractor scripts with different features ...
I have several tests that make a regression test set. The tests are not dependent from each other, but they take a long...
Read more >
Protractor parallel execution - Perfecto Help
Protractor parallel execution · Run multiple specs simultaneously · Run the same spec against different browsers/devices in parallel.
Read more >
Sequential & Parallel Execution | Protractor Tutorial | LetCode
Hey! In this video, we'll learn how to run our multiple test script in sequential & parallel execution. Trust me, it's very easy...
Read more >
Run parallel Selenium tests with Protractor | BrowserStack Docs
On BrowserStack, you can run multiple Protractor tests at the same time across various browser, device and OS combinations. This is called Parallel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found