How to run it blocks in parallel in protractor? - npm

My spec file covers 50 different test cases for a specific test scenario. Each test case is covered in individual it block. The spec file takes 2 hrs to execute. I want to categorize it blocks in a way so that they run in parallel in multiple browser instances. For e.g. it should run like (5 it blocks * 10 browser instances) in parallel. I don't want to divide the spec file in different parts. Is there any alternate solution?

When you decide to execute your test cases, use any configuration listed below. Please refer a typical conf.js file and choose any of the configuration in conf.js file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
specs: ['spec1.js','spec2.js']
};
Type-1: Single browser instance : start one browser instance at a
time.
example configuration in the conf.js file.
capabilities: {
browserName: 'chrome',
},
specs: ['spec1.js','spec2.js']
The above configuration will launch chrome browser instance and executes all specs one by one
sequestial --> [chrome] --> spec1.js --> spec2.js
Type-2: Different browser instance will launch in parallel and all the
specs which is mensioned in the spec:[] tag will execute in each
browser's instance separately.
example configuration in the conf.js file.
multiCapabilities: [
{ browserName: 'chrome', },
{ browserName: 'firefox', },
],
specs: ['spec1.js','spec2.js','spec3.js']
The above configuration will launch chrome, firefox browsers and executes all specs in each browser instance parallel.
--> [chrome] ---|--> spec1.js --> spec2.js --> spec3.js
|
parallel
|
--> [firefox] ---|--> spec1.js --> spec2.js --> spec3.js
Type - 3: The below configuration will help you to execute different
set of specs in different browser instances.
example configuration in the conf.js file.
multiCapabilities: [
{
browserName: 'chrome',
specs:['spec1.js']
},
{
browserName: 'firefox',
specs:['spec2.js']
},
],
The above configuration will launch chrome, firefox browsers and executes spec1.js in chrome and spec2.js in firefox instances
--> [chrome] ---|--> spec1.js
|
parallel
|
--> [firefox] ---|--> spec2.js
Type - 4: Execute different spec files in parallel with same browser.
Consider you have 5 spec files in your test suit and you want to
execute everything in parallel. The below configuration will help you
to do that.
example configuration in the conf.js file.
capabilities: {
browserName: 'chrome',
specs: [
'spec1.js', 'spec2.js', 'spec3.js' , 'spec4.js' , 'spec5.js'
],
maxInstances : 5,
shardTestFiles: true
}
The above configuration will launch 5 chrome instances and each spec will execute in those 5 chrome instances in parallel.
|-- [instance 1] --|--> spec1.js
|-- [instance 2] --|--> spec2.js
--> [chrome] ---|-- [instance 3] --|--> spec3.js
|-- [instance 4] --|--> spec4.js
|-- [instance 5] --|--> spec5.js
The maxInstances number represents the maximum amount of browser windows that Protractor is allowed to create.
For example, with maxInstances set to 10, a test suite of 200 tests would result in Protractor creating 10 Chrome instances with each instance running 20 tests, whereas without shardTestFiles this would be one Chrome instance running all 200 tests.

You are unable to run "it" blocks parallel from within the same spec file. The alternate solution would be to divide up your spec file such as spec1.js, spec2.js, andspec3.js
You would then add this to your conf.js file
specs:['filePath/spec1.js','filePath/spec2.js','filePath/spec3.js'],
capabilities: {
shardTestFiles: true,
maxInstances: 5 //set this to amount you want running at once
}
The specs param will accept arrays, or you can use wildcards such as filePath/*.js which would run all .js files within that folder (Make sure they are are protractor test cases)
maxInstances will be set to the amount running at once. I find it easier to use headless mode when running multiple instances at once, for chrome the option looks like:
chromeOptions: {
args: ["--headless", "--disable-gpu", "--window-size=1920,1080"]
}

Related

WebdriverIO setting browser language problem for headless chrome browser on linux server

I am using webdriverio for test automation and I am trying to change my chrome browser configurations via wdio.config.js file. I am running chrome headless browser and locally everything geos fine, but on the linux server it looks like the language setting doesn't take an effect.
An additional detail is that I have 2 jobs in the pipeline (1 for English and one for Netherlands language) but it seems both of them are running in English.
Here are my browser capabilities section:
{
maxInstances: 1,
browserName: 'chrome',
'goog:chromeOptions': {
args: [
'--headless',
'--disable-dev-shm-usage',
'--disable-gpu',
'--window-size=1920,1080',
'--disable-web-security',
'--lang=nl',
'ignore-certificate-errors'
],
},
}

Selenium doesn't start webdriver

versions
"nightwatch": "^0.9.16"
"chromedriver": "^2.30.1"
"selenium-server-standalone-jar": "^3.4.0"
I'm using nightwatch but that sh
I also tried with
I'm using nightwatch to run Selenium in this repo and I've tried with chrome and firefox drivers, no luck on either.
I have selenium standalone and chromedriver packages, and I know the path is right on nightwatch.conf.js:
const jar = require('selenium-server-standalone-jar')
console.log(jar.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar
const chromedriver = require('chromedriver')
console.log(chromedriver.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/chromedriver/lib/chromedriver/chromedriver
'selenium': {
'start_process': true,
'server_path': jar.path,
'log_path': '',
'port': 4444,
'cli_args': {
'webdriver.chrome.driver': chromedriver.path,
'webdriver.ie.driver': '',
},
},
'test_settings': {
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true,
'acceptSslCerts': true,
},
},
yet when I run the test it times out and hangs:
$ yarn e2e:ui
yarn e2e:ui v0.24.6
$ nightwatch -e chrome
Starting selenium server... started - PID: 12936
[App E2e Ui] Test Suite
===========================
✖ Timed out while waiting for element <body> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.before (/home/goldylucks/apps/ci-workshop/test/ui/app.e2e-ui.js:9:8)
I tried it with the following combinations:
1. with the express server which serves the app on another terminal
2. without the express server
3. each of the above with chromedriver manually started at another terminal (I really don't think it should matter and that I should do this, just wanted to be thorough ...)
running the chromedriver manually yields the following and hangs:
$ node_modules/chromedriver/lib/chromedriver/chromedriver
Starting ChromeDriver 2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5) on port 9515
Only local connections are allowed.
I also tried running with firefox and it didn't work, which leads me to believe the problem is deeper than the chromedriver, i.e. related to selenium interacting with nightwatch.
I recall this happening a while back. I think it was that a previous instance Selenium had not closed freed port 4444 when shutting down. Try shutting down selenium and restarting.
To do that, open the following webpage manually, in the browser of your choice.
http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer
Then try running the script again as normal.

Create new WebDriver session for each spec file

We have a bunch of e2e protractor tests on jasmine2 framework and recently we started to run them on SauceLabs.
SauceLabs has a restriction that one WebDriver session can not run longer than 30 mins. This makes perfect sense to me, however causes our tests to fail as protractor runs all our tests in a single WebDriver session.
So I'm wondering how can I initiate new WebDriver session, say for each spec file or for each 'describe'? Or there is a solution that protractor can offer out of the box?
Timeout increase is not an option for me.
Many thanks.
I believe that's what you are looking for:
{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 5
},
Use this in your config.js file and make sure to divide the tests among multiple spec files. I am using this in my tests (an example here), and it is working fine for me.
{
'name': 'Window10 -Chrome-tests',
'browserName': 'chrome',
shardTestFiles: true,
platform: 'Windows 10',
screenResolution: '1376x1032',
maxInstances: 5
},

Run parallel Protractor tests in multiple Chrome tabs

I'm using the following .conf:
capabilities: {
browserName : 'chrome',
shardTestFiles: true,
'time-zone': 'AEST',
maxInstances: 5,
singleWindow: true
}
I'm using singleWindow as described in the capabilities page for Selenium and the properties are passed to the WebDriver according to this. However I'm still seeing multiple individual windows appearing and disappearing during execution. These fight for focus and it's very annoying while doing other work.
Is it possible to run parallel tests in separate tabs rather than separate instances/windows of Chrome?

Test browser code with Intern through Grunt and Phantomjs

I have been playing with Intern and made my tests work in the browser. To better integrate with my current workflow I'm trying to run my tests through grunt with phantomjs. However all my attempts have failed. I've been looking at this question as a reference Intern WebDriver and PhantomJS but can't figure out all of the steps to make it work.
First of all: Is it even possible to run the tests through grunt and phantomjs?
A little bit of info:
I don't want/can't connect to Sauce Labs or a Selenium testing environment.
I want to test browser code while having jQuery as a shimmed dependency
I have Grunt 0.4.1 and phantomjs 1.9.1 installed
I'm not testing any ajax request (as the linked question is having problem with)
I'm not familiar with neither Selenium nor Sauce Lab
If it is possible to test through grunt and phanomjs, how would I go about doing it?
I guess that I have to start the GhostDriver
phantomjs --webdriver=8910
But then what are the important pieces of info in the Intern config to make this work?
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
environments: [
{
browserName: 'phantom',
version: '1.9.0',
platform: 'Linux'
}
],
webdriver: {
host: 'localhost',
port: 8910
},
maxConcurrency: 3,
useSauceConnect: false,
// ...
});
How does the environments browserName map to phantomjs? I've tried the browserNames 'phantom' as well as 'phanomjs' with different versions and platforms (running Mac 10.7)
My Gruntfile section for intern looks like:
intern: {
phantom: {
options: {
config: 'tests/intern',
reporters: ['webdriver']
}
}
}
Running this setup without any test-suite that includes browser code outputs
'ReferenceError: document is not defined' in 'node_modules/intern/lib/reporters/webdriver.js:41:19'
Adding browser tests gives 'ReferenceError: window is not defined' in 'src/vendor/jquery/jquery-1.9.1.js:9597:5'
Running it through node gives the same 'window is not defined' error.
node node_modules/intern/client.js config=tests/intern
What am I doing wrong/missing here?
There are two problems with your Gruntfile configuration:
The default run type for the Grunt task is 'client', which means it runs the Node.js client by default, not the test runner. You need to set runType: 'runner' in your Gruntfile options to run tests against your specified environments.
The webdriver reporter is for use in a browser client only and is specified automatically by the test runner when it is needed. You should typically never use it directly. The reporter you specify in the Gruntfile should be the one you want the test runner to use; the console default is usually appropriate.
These two things in combination mean that you’ve configured Intern to try to use a reporter that only works in a browser in conjunction with the test runner inside the Node.js client, hence the error. Once corrected, the remaining configuration should work properly to run on PhantomJS, assuming it is already running on localhost at port 8910.