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
},
Related
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'
],
},
}
I'm using Webdriver.io to run UI tests in a Node environment.
I'd like to run Headless Chrome and came up with the following working configuration:
{
capabilities: [{
browserName: 'chrome',
args: ['--headless', '--disable-gpu']
}
}],
services : ['selenium-standalone'],
execArgv : ['--inspect']
}
However, I can't figure out whether capabilities is deprecated or not; I'm wondering because all the examples I see reference desiredCapabilities instead.
If I use desiredCapabilities though, then Chrome runs normally, not in headless mode.
I feel like I'm missing something, but I don't know what. Is there a significant difference between the two, and is one going away?
Thanks!
If you run webdriverio through the test runner (using a wdio.conf.js file), it uses capabilities.
If you run it in standalone mode (e.g. node myTest.js), it uses desiredCapabilities
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"]
}
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?
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.