protractor "ERROR - Unable to start a WebDriver session" - angularjs

I have some it tests on my single-page-app written in angular.
the tests are in protractor.
they ran during the build before, but now that I moved all of them to a branch something got broken and when I run the tests I'm getting:
Running "protractor:normal" (protractor) task
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://172.31.9.226:23730/wd/hub
ERROR - Unable to start a WebDriver session.
c:\projects\blog-manager\node_modules\protractor\node_modules\selenium- webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
Warning: Protractor test(s) failed. Exit code: 1 Use --force to continue.
Aborted due to warnings.
Process finished with exit code 6
the conf file is as follows:
'use strict';
module.exports.config = {
allScriptsTimeout: 60000,
baseUrl: 'http://localhost:9000/',
specs: [
process.cwd() + '/test/spec/e2e/**/*.js'//,
// process.cwd() + '/test/e2e/spec/**/*.js'
],
framework: 'jasmine',
capabilities: {
browserName: 'chrome',
"chromeOptions": {
binary: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
args: [],
extensions: [],
}
},
onPrepare: function () {
// Disable animations so e2e tests run more quickly
var disableNgAnimate = function () {
angular.module('disableNgAnimate', []).run(function ($animate) {
$animate.enabled(false);
});
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
// Store the name of the browser that's currently being used.
browser.getCapabilities().then(function (caps) {
browser.params.browser = caps.get('browserName');
});
},
jasmineNodeOpts: {
defaultTimeoutInterval: 300000
}
};
any suggestions on how to solve this would be much appreciated.
Thanks!

According to alecxe's answer it's chrome binary issue which can be solved by installing chrome in same place as chromedriver expects to be or specifying the executable path to the binary settings.
capabilities: {
"browserName": "chrome",
"chromeOptions": {
binary: "D:/Program Files/Chrome/chrome.exe",
args: [],
extensions: [],
}
},
See his answer here
Even though you are setting the executable path correctly it seems little off to me binary: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
Is this correct?
Alternatively, I would try this

Related

e2e testin with jasmine protractor "no specs found"

I'm new testing with protractor, but I cant run my tests.
My protractor.config.js:
exports.config = {
allScriptsTimeout: 99999,
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
baseUrl: 'http://localhost:8080/',
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['.src/test/e2e/login.e2e.spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
includeStackTrace: true
}
};
and this is the test I'm trying to run:
'use strict';
describe('my app', function() {
beforeEach(function () {
browser.get('index.html');
});
it('should automatically redirect to / when location hash is empty', function() {
expect(browser.getLocationAbsUrl()).toMatch("/");
});
});
And this is the error I get:
I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[13:20:49] I/launcher - Running 1 instances of WebDriver
Started
No specs found
Finished in 0.001 seconds
[13:20:50] I/launcher - 0 instance(s) of WebDriver still running
[13:20:50] I/launcher - chrome #01 passed
[13:20:50] The following tasks did not complete: e2e
[13:20:50] Did you forget to signal async completion?
I'm running webdriver-manager and my app server. My jasmine version is: 2.5.2
and my protractor version is:
4.0.9
Any idea of what I'm doing wrong??
Thanks!!!
I realized what was my problem (thanks to the comments that helped me to realize).
I was running my test with a gulp task I made:
function e2e() {
gulp.src(["/src/test/*.js"]).pipe(protractor({
configFile: "conf/protractor.config.js",
args: ['--baseUrl', 'http://localhost8080']
})).on('error', function (e) {
throw e;
});
}
I dont know why this: gulp.src(["/src/test/*.js"])wasnt getting to acces to my test files, so I changed it for: gulp.src(["src/test/e2e/login.e2e.spec.js"])
I know its not the best solution,but enough to survive...

ngMockE2E does not work with remote Selenium server

Setup
We use protractor, protractor-cucumber, and angular-mocks to handle our e2e tests. Builds are managed by grunt.
We have two build configs; pool and local. pool is the configuration that is picked up by our CI environment, local is for debugging purposes and is setup to run on a local machine. The primary difference between the two setups is that local runs everything locally, whereas pool uses a remote Selenium server (outside the CI server itself).
protractor.conf.js:
exports.config = {
params: {
widgetUrl: 'http://localhost:9980',
vudUrl: 'xxx',
testDelay: 3000,
},
// The timeout for each script run on the browser. This should be longer
// than the maximum time your application needs to stabilize between tasks.
allScriptsTimeout: 150000,
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:' + (process.env.PORT || '9082'),
// list of files / patterns to load in the browser
specs: ['./e2e/features/*.feature'],
cucumberOpts: {
require: ['./e2e/steps/*.js', './e2e/pageObjects/*.js', './e2e/support/*.js'],
format: 'pretty',
tags: ['#context-test']
},
// Patterns to exclude.
exclude: [],
// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// and
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
browserName: 'chrome',
loggingPrefs: {
'driver': 'INFO',
'server': 'INFO',
'browser': 'INFO'
}
},
// ----- The test framework -----
//
// Jasmine and Cucumber are fully supported as a test and assertion framework.
// Mocha has limited beta support. You will need to include your own
// assertion framework if working with mocha.
framework: 'custom',
frameworkPath: 'node_modules/protractor-cucumber-framework',
mocks: {
dir: "mocks", // path to directory with mocks
default: []
},
onPrepare: function() {
// Chai config
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
console.log('params: ' + JSON.stringify(browser.params));
//browser.driver.manage().window().maximize();
}
};
We configure our mocks in a Before hook (snipped here for brevity):
this.Before(function(scenario, callback) {
// ...
let data = require(`${TEST_DATA_DIR}/default.js`);
let httpMocker = function() {
angular.module('httpMocker', ['ngMockE2E'])
.run(function($httpBackend) {
$httpBackend.whenPOST(...);
};
browser.addMockModule('httpMocker', httpMocker, {data})
// ...
callback();
});
Problem
Despite identical test setups, ngMockE2E is not being called when run in the CI environment. This can be demonstrated by the following test:
test.feature:
#Test
Feature: Test and debug
#context-test
Scenario: Get console output
Given I access the page
Then I get the log output
test.steps.js
module.exports = function() {
this.Given(/^I access the page$/, () => {
util.waitAndDo(() => true);
});
this.Then(/^I get the log output$/, () => {
util.waitAndDo(() => {
browser.manage().logs().get('browser').then(function(browserLog) {
console.log('log: ' + require('util').inspect(browserLog));
});
})
});
};
This test will dump the browser log rather than actually testing anything. When it is run locally, the logs are empty. However, when the same test is run in the CI environment, the logs show errors for failed calls to the URLs being mocked.
We have verified that the URLs used in the CI environment correctly match the regex in our mocks, so it is not a match-miss. The module is simply not being called.
To reiterate - the only major difference in configuration is that the pool config makes use of a remote Selenium hub. How could this affect how our tests are run, and why would it prevent our mocks from working?

AngularJs Protractor Html Reporter Fails Config Parser

I am trying to use protractor html screenshot reporter but it's failing to require in the the config file. Here's my config:
//Configuration for Protractor
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
baseDirectory: '/screenshots',
takeScreeenShotOnlyForFailedSpecs: true
});
exports.config = {
//Address of Selenium server
seleniumAddress: 'http://localhost:4444/wd/hub',
//framework: 'jasmine2',
chromeOnly: false,
multiCapabilities: [
{'browserName': 'chrome'}
],
//URL of the application
baseUrl: 'http://localhost:80',
cache: false,
//Spec pattern
specs: ['**/specs/*-spec.js'],
onPrepare: function () {
//browser.driver.manage().window().maximize();
browser.driver.manage().window().setSize(480, 800);
browser.driver.manage().window().setPosition(400, 100);
jasmine.getEnv().addReporter(reporter);
},
//Options passed to Jasmine-node
jasmineNodeOpts: {
includeStackTrace: true,
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
}
};
I have both protractor and the protractor html screenshot report installed globally . Here's the error protractor is throwing:
[13:48:23] E/configParser - error code: 105
[13:48:23] E/configParser - description: failed loading configuration file protractor-config.js
Any help would be most helpful!!
UPDATE:
I moved to the require call inside the onPrepare in the config and I getting the proper error:
[14:27:15] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[14:27:15] I/launcher - Running 1 instances of WebDriver
[14:27:18] E/launcher - Error: Error: Cannot find module 'protractor-html-screenshot-reporter'
Seems like it can't find the node module. Anyone else seeing this issue?
UPDATE2:
So, I think I found my problem. I was installing like this:
npm install -g protractor-html-screenshot-reporter
Which seems to be the cause the fail. Installing with this command:
npm install protractor-html-screenshot-reporter --save-dev
Works! For whatever reason installing globally doesn't work but installing locally does, which is a bit of a downer :( If anyone knows how to get this to work with the screenshot reporter installed globally let me know how :)

Error while waiting for Protractor to sync with the page: in Protractor IE11 execution

I am getting error in IE11 as
Error while waiting for Protractor to sync with the page: "root element (body) has no injector. this may mean it is not inside ng-app.
when I execute my protractor scripts.I set framework: jasmine2 but it didn't help out.However same working fine in Chrome and Firefox.
Following is my code:
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
//config.seleniumAddress = 'http://127.0.0.1:4444/wd/hub';
maxSessions: 1,
capabilities:
{
'browserName': 'internet explorer'
},
framework: 'jasmine',
specs: ['TC_Sprint2_Case1.js'],
onPrepare: function() {
beforeEach(function() {
browser.driver.manage().window().setSize(1280, 1024);
});
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'D:/Manoj/TestReport3/',
docTitle: 'Test Case Execution Details',
docName: 'BYTestReport.html',
//Meta builder
metaDataBuilder: function(spec, descriptions, results, capabilities){
var metaData = {
description: descriptions.join('|'),
passed: results.passed(),
os: 'Windows 7',
browser: {
name: capabilities.caps_.browserName
, version: capabilities.caps_.version
}
};
if(results.items_.length > 0) {
var result = results.items_[0];
metaData.message = result.message;
metaData.trace = result.trace.stack;
}
return metaData;
} // Meta Builder ends
}));
},
We can use browser.driver.get('https://google.co.in'); instead of browser.get('https://google.co.in');
Earlier I used browser.get(URL). It caused the synchronization problem.When I use browser.driver.get(URL).It solved the problem.
In your config, try setting nativeEvents to false:
capabilities:{
browserName: 'internet explorer'
nativeEvents:false
},
IE sometimes hangs on startup and this seems to solve it for me. This being said, there are other things that could cause IE to not bind.

Protractor - Cucumber : Annoying ECONNREFUSED Errors while working as expected

I'm trying to integrate Cucumber with protractor, While the setup is working as expected (the test fail and succeed normally), I'm getting annoying ECONNREFUSED errors that makes my feedback unreadable.
Question 1: What't ECONNREFUSED's error exact meaning? I don't really understand the feedback and I couldn't find good documentation for it.
Question 2: What could be the problem with my setup? Is my setup proper?
Question 3: Has anyone run BDD tests in vagrant box with cucumber over protractor? Example code please :)
Dependencies
npm i protractor cucumber selenium-webdriver chai chai-as-promised express grunt-protractor-runner protractor-cucumber --save-dev
As you see I'm running my commands via grunt inside a vagrant box. The vagrant box has only firefox, I'm not sure if that's a problem, protractor was running just fine before.
Terminal Feedback
[vagrant#vagrant web-src]$ grunt protractor:singlerun
Running "protractor:singlerun" (protractor) task
Using the selenium server at http://localhost:4444/wd/hub
Feature: Blog
As a user
I want to visit blog
So that I can stay informed about a topic
Scenario: A disclaimer scenario # tests/e2e/cucumber/features/Blog.feature:6
/var/www/miyagi/web-src/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131
var session = webdriver.promise.controlFlow().execute(function() {
^
Error: ECONNREFUSED connect ECONNREFUSED
at <anonymous>
at <anonymous>
at <anonymous>
at <anonymous>
at <anonymous>
at <anonymous>
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/var/www/miyagi/web-src/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:49)
at Function.webdriver.WebDriver.createSession (/var/www/miyagi/web-src/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)
at Builder.build (/var/www/miyagi/web-src/node_modules/protractor/node_modules/selenium-webdriver/builder.js:106:20)
at HostedDriverProvider.getDriver (/var/www/miyagi/web-src/node_modules/protractor/lib/driverProviders/hosted.js:63:9)
at /var/www/miyagi/web-src/node_modules/protractor/lib/runner.js:241:41
at _fulfilled (/var/www/miyagi/web-src/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/var/www/miyagi/web-src/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/var/www/miyagi/web-src/node_modules/protractor/node_modules/q/q.js:759:13)
at /var/www/miyagi/web-src/node_modules/protractor/node_modules/q/q.js:573:44
>>
>> Test failed but keep the grunt process alive.
Done, without errors.
[vagrant#vagrant web-src]$
Protractor Config
// conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../cucumber/features/*.feature'],
multiCapabilities: [{
browserName: 'firefox'
}],
onPrepare: function() {
var width = 1024;
var height = 600;
browser.driver.manage().window().setSize(width, height);
// implicit and page load timeouts
browser.manage().timeouts().pageLoadTimeout(40000);
browser.manage().timeouts().implicitlyWait(25000);
// for non-angular page
browser.ignoreSynchronization = true;
},
framework: 'cucumber',
cucumberOpts: {
require: '../cucumber/features/*.steps.js',
format: 'pretty'
}
};
Grunt task
protractor: {
options: {
configFile: '<%=tests %>/e2e/protractor/config.js', // Default config file
noColor: false, // If true, protractor will not use colors in its output
keepAlive: true
},
auto : {
keepAlive: true // If false, the grunt process stops when the test fails.
},
singlerun: {}
},
Feature
Feature: Blog
As a user
I want to visit blog
So that I can stay informed about a topic
Scenario: A disclaimer scenario
Given I visit blog
Then I should see a disclaimer
Steps
//http://chaijs.com/
var chai = require('chai');
//https://github.com/domenic/chai-as-promised/
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
module.exports = function() {
var url = 'http://dev.com/search',
searched = url + '#/?q=food&page_number=1&sort=relevance',
driver,
resultsA, resultsB, resultsC,
page,
site;
this.Given(/^I visit blog$/, function(callback) {
browser.get(url);
driver = browser.driver;
browser.getTitle()
.then(function ( title ) {
expect(browser.getTitle()).to.eventually.equal(arg1).and.notify(callback);
});
});
this.Then(/^I should see a disclaimer$/, function(callback) {
element( by.css ( '.disclaimer' ) )
.isDisplayed()
.then(function (el) {
expect(el).to.have.length(1);
callback();
});
});
};
Cheers
You never mentioned setting up a local selenium server. Did you forget it?
./node_modules/protractor/bin/webdriver-manager update
./node_modules/protractor/bin/webdriver-manager start
Just let that run in its own terminal window, and try running your tests again.
Any chance you already have another instance of webdriver running? Or a firewall that is blocking the connection?
This is a working example that I found. However it is in .coffee
https://github.com/whyvez/angular-cucumber-example

Resources