I am going through the tutorial at http://www.protractortest.org/#/tutorial and want to run the protractor tests.
The first problem I faced is that when running the webdriver-manager update I got the certificate issues as mentioned in this thread Can't update chromedriver and seleniumrelease
So, I manually downloaded the chromedriver_win32.zip and selenium-server-standalone-2.47.1.jar
I then extracted the zip file and placed chromedriver.exe at the same folder C:\Users\username\AppData\Roaming\npm\node_modules\protractor\selenium
Then I started the server and I ran the test protractor conf.js
I got the following exception:
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
I am aware that it is missing the path to chromedriver.exe which I need to specify as a system property, so taking a que from this thread for i.e. with protractor how to setup internet explorer configuration? I put the following in the conf.js
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
seleniumArgs: ['-Dwebdriver.chrome.driver=C:\Users\username\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver.exe']
}
But still I am getting the same error, I know I am missing something very simple but not sure what!
We were having the same issue like you, what we did is added the following in the config
directConnect: true,
chromeDriver: 'C:\\tools\\selenium\\chromedriver',//this will be your path to chromedriver FOLDER
cheers
Related
I am a beginner in protractor. I did the installations necessary for running protractor. When tried running the sample script mentioned in the protractor documentation, i am getting ETIMEDOUT error. and the url points to 127.0.0.1:4444. The same url is not accessible manually also. But when trying http://localhost:4444/wd/hub, page opens properly. I am not sure why the conf.js trying to access the 127.0.0.1:4444, even if i give the 'seleniumAddress' parameter to 'http://localhost:4444/wd/hub'. Please help me guys to resolve this issue
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});
I agree with the other responses. http://localhost:4444/wd/hub is the same as http://127.0.0.1:4444/wd/hub. Usually this is defined in your /etc/hosts file.
Since I imagine you are just trying to run your Protractor tests, as long as you've downloaded the binaries with webdriver-manager update, you could do one of the two options:
Set directConnect: true (and remove seleniumAddress. This is available for chrome or firefox (version 47*) without the selenium standalone server.
Remove seleniumAddress all together. Protractor will launch the selenium standalone server for you before the test and then tear it down when the test is over.
Note: for the above to work, webdriver-manager update should run from the project directory to download the binaries to the correct directory. Something like node node_modules/.bin/webdriver-manager update or ./node_modules/.bin/webdriver-manager update should download the driver binaries to node_modules/protractor/node_modules/webdriver-manager/selenium.
So why Firefox 47, currently newer versions are not supported. We are currently testing Firefox 48+ but there are still a few outstanding issues.
You need 2 terminal for this.
In first terminal, run below command:
webdriver-manager start
this will create a server for node/client to access(that you have added in seleniumAddress)
In second terminal, run below command:
protractor conf.js
This will start your script, by using server created at http://localhost:4444/wd/hub.
And localhost is same as 127.0.0.1.
If localhost is not the same as 127.0.0.1 it sounds like your hosts files has been played around with or some more nefarious networking issue. I do not feel we have enough information to correctly debug why you are having this issue but I would like to suggest a workaround. Why not use your actual local internal IPv4 address?
To get a list of your IPv4 addresses in Windows type
ipconfig | findstr /R /C:"IPv4 Address"
To get a list of your IPv4 addresses in Linux type
hostname -i
To get your IPv4 address on a Mac type
ifconfig |grep inet
The address on mac should be located on the last line between inet and netmask
Your config file should look something like this after
exports.config = {
seleniumAddress: 'http://192.138.0.100:4444/wd/hub',
specs: ['todo-spec.js']
};
I'm writing acceptance tests for my angular web application project. They're run via protractor, and work just fine on chrome. But when I try to run them on Internet Explorer 11, I get a failure complaining that "The path to the driver executable must be set by the webdriver.ie.driver system propery". However, I have my project configured to download the IE driver to the same place as the chromedriver executable.
While I'm sure I could move the IE driver excutable to a folder stored in my PATH env variable, then every developer on the project would have to do the same or update their PATHs to point to the driver.
My question is - is there a simple configuration I'm missing to make this IE driver available to protractor just as Chrome's driver is?
My package.json:
{
//...
"scripts": {
"webdriver-update": "webdriver-manager update --ie",
"preacceptance-tests": "npm run webdriver:update -- --standalone",
"acceptance-tests": "protractor",
//...
}
My protractor.conf.js:
exports.config = {
baseUrl: 'http://localhost:3000/',
specs: [
'src/**/**test.ts',
'src/**/*test.ts'
],
capabilities: {
'browserName': 'internet explorer' //If I put chrome here, the tests pass
},
onPrepare: function() {
browser.ignoreSynchronization = true;
},
seleniumServerJar: "node_modules/protractor/selenium/selenium-server-standalone-2.51.0.jar",
useAllAngular2AppRoots: true
};
I run "npm run acceptance-tests", and chromedriver.exe and IEDriverServer.exe are downloaded to my node_modules/protractor/selenium folder. Protractor seems to be aware of the chromedriver, but why can't it see the IEDriverServer?
I can't seem to find an answer anywhere, other than manually pointing my PATH to this folder. It seems like I shouldn't have to if protractor can find the chromedriver...
As far as I know from having checked the Selenium source, there's only one workaround.
If an executable named IEDriverServer.exe exists in the current working directory (which is explicitly checked, and which you can query with process.cwd()), then that instance will be chosen and the PATH check bypassed (the error message is a little misleading).
You can follow the logic in the Selenium source here and here.
I'm trying to run protractor by connecting directly to Chrome, not running Selenium. As the docs say, this is possible by setting the directConnect to true in the config file.
When I run protractor with directConnect: true, I get:
Using ChromeDriver directly...
[launcher] Running 1 instances of
WebDriver Error: spawn ENOENT
at errnoException (child_process.js:1001:11)
at Process.ChildProcess._handle.onexit (child_process.js:792:34) [launcher] Process exited with error code 1
If I run protractor without directConnect and instead specify my selenium url, everything runs fine.
I'm running Protractor version 1.6.1, Chrome version 41.0.2272.35 beta-m (64-bit), and Chromedriver version 2.13.0.
Update: While the solution below worked for me, after talking with a protractor dev I realized that if I run webdriver-manager update to install a local chromedriver, then I don't need to set the chromeDriver setting in my protractor config.
I had the same issue and solved it by varying the chromeDriver path setting in protractor-conf.js depending on whether I was on Windows or OSX/Linux.
Solution and writeup below assumes you are using chromedriver provided by npm install chromedriver. Also this solution worked with protractor 3.2.2 and chromedriver 2.21.2.
Protractor+chromedriver worked on OSX and Linux but I was getting ENOENT errors on Windows. I have filed an issue here and have also documented a workaround.
The issue (I think) is that childProcess.spawn has issues on Windows (see a list of issues here) and the node_modules/chromedriver/bin/chromedriver file will not correctly run when called via childProcess.spawn - likely because this file is not executable and Windows doesn't know to use the node binary to interpret the file.
The workaround is to provide the path to the windows executable when running on Windows. It is easy enough - though hackish - to vary the chromeDriver arg in protractor-conf.js as demonstrated below :
protractor-conf.js for all three OS:
var chromeDriverPath = process.platform === 'win32' ? 'node_modules/chromedriver/lib/chromedriver/chromedriver.exe' : 'node_modules/chromedriver/bin/chromedriver';
exports.config = {
directConnect: true,
chromeDriver: chromeDriverPath,
specs: [
'features/*.feature'
],
capabilities: {
browserName: 'chrome',
platform: 'ANY',
chromeOptions: {
args: ['--test-type']
}
}
}
Hope this helps.
ENOENT means Error, NO such ENTity, and relates to the file system.
Check you have the right path set in the chromeDriver option.
capabilities : {
chromeOptions: {
"debuggerAddress":"127.0.0.1:8088"
}
},
directConnect: true,
chromeDriver : "../bin/chromedriver_2.15.322448.exe"
I'm building an AngularJS app on Windows. I want to create end-to-end tests with Jasmine. From my understanding, I need protractor to run these kinds of tests. For that reason, I've added the following to my package.json:
"devDependencies": {
...
"grunt-protractor-runner": "0.2.4",
"selenium-webdriver":"2.41.0",
...
}
In my gruntfile.js, I've configured Protractor as such:
grunt.initConfig({
protractor: {
options: {
configFile: "node_modules/protractor/referenceConf.js", // Default config file
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
args: {
// Arguments passed to the command
}
},
tests: {
options: {
configFile: "tests/config/e2e.conf.js",
args: {} // Target-specific arguments
}
},
}
});
I'm then running the protractor:tests target. The contents of e2e.conf.js look like the following:
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'
},
// Spec patterns are relative to the location of the spec file. They may
// include glob patterns.
specs: ['../../tests/e2e/user-tests.e2e.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
Now, when I run grunt from the command-line, I get an error that says:
Using the selenium server at http://localhost:4444/wd/hub
C:\Projects\MyProject\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702
throw error;
^
Error: ECONNREFUSED connect ECONNREFUSED
...
I don't understand why I'm getting this error. I see in the Protractor Getting Started Guide that it expects a selenium standalone server to be running. However, I thought that was the purpose of the Grunt task runner: start the selenium server. I see webdriver-manager in node_modules\grunt-protractor-runner\node_modules\protractor\bin, however, if I change to that directory and run webdriver-manager update from the command-line, I get an error that says:
'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.
How do I get the selenium piece going so that I can run end-to-end tests with protractor?
Thank you!
Have you tried with "node" command ?
It worked for me :
node .\node_modules\grunt-protractor-runner\node_modules\protractor\bin\webdriver-manager update
This should download for you chromedriver and selenium server. If not, ou can also manually download/extract :
http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar
https://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip
in :
src/test/config/selenium/selenium-server-standalone.jar
src/test/config/selenium/chromedriver.exe
An other thing is that you need to be sure that Chrome is isntalled in :
<WINDOWS_USERS_FOLDER>\<USERNAME>\AppData\Local\Google\Chrome\Application\chrome.exe
First up:
There are many components in there that I don't understand :)
Feel free to add comments to help me improve my answer.
I do know some Selenium so here goes.
seleniumAddress: 'http://localhost:4444/wd/hub',
To me, this line indicates that you are trying to run the Selenium Grid Server.
Here's how to start it: (yes, it needs to be started manually as far as I know)
From a separate console, run the following:
java -jar selenium-server-standalone-2.41.0.jar -role hub
#now wait a few seconds for the hub to start
java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register
What did we just do?
Started a hub. This hub is like a test distributor - it receives the requests.
Started a node. (You can start any number of nodes). This node is what will actually conduct the test.
You can verify that this server was started successfully. Just visit the local host link on your browser.
Gotchas:
Check that your firewall is not giving you problems. I've had crippling issues getting started on Windows 7 and finally moved over to Ubuntu (but that's probably just my situation).
Open ports 4444 (for hub), 5555(for node) for both incoming and outgoing connections on Windows Firewall.
I'm trying to learn AngularJS. As part of this, I want to learn to use end-to-end testing. Currently, I have a directory structure like this:
node_modules
.bin
...
protractor
...
node_modules
.bin
adam-zip
glob
minijasminenode
optimist
saucelabs
selenium-webdriver
protractor
config.js
src
tests
test.e2e.js
My config.js file looks like the following:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: [
'../src/tests/test.e2e.js'
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
test.e2e.js looks like the following:
'use strict';
describe('My Sample', function () {
driver = protractor.getInstance();
beforeEach(function () {
driver.get('#/');
});
it('My First Test', function () {
message = "Hello.";
expect(message).toEqual('World.');
});
});
When I attempt to run my end-to-end tests using protractor, I run the following command from the command-line:
node_modules\.bin\protractor protractor\config.js
When I run that command, I receive the following error:
C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1542
throw error;
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:12
7:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1528:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriv
er\lib\webdriver\webdriver.js:130:49)
at Function.webdriver.WebDriver.createSession (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver
\lib\webdriver\webdriver.js:110:30)
at Builder.build (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\builder.js:105:20)
at runJasmineTests (C:\Src\MyProject\node_modules\protractor\lib\runner.js:191:45)
at C:\Src\MyProject\node_modules\protractor\lib\runner.js:255:5
at C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriv
er\lib\webdriver\promise.js:1438:20)
at notify (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:328:12)
at then (C:\Src\MyProject\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:377:7)
What am I doing wrong?
I solved this with --standalone flag:
webdriver-manager start --standalone
I got it working by removing the following line from my config.js
seleniumAddress: 'http://localhost:4444/wd/hub',
Are you running a selenium server? The git README states the following:
WebdriverJS does not natively include the selenium server - you must start a standalone selenium server. All you need is the latest selenium-server-standalone.
source: https://github.com/angular/protractor
The error message is due to the following:
[ECONNREFUSED] The attempt to connect was ignored (because the target is not listening for connections) or explicitly rejected.
Check the URL of the Webdriver manager. The default URL is:
http://localhost:4444/wd/hub
Use a background process to run the webdriver-manager, then run protractor:
Start-Process webdriver-manager start -passthru
protractor conf.js
This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. Leave this server running
References
Protractor Tutorial
Protractor Docs: Config File Reference
CONNECT Man Page
POSIX Man Page
For me, this had happened due to incompatible versions of Node and Protractor.
My fix-
Update Node to latest version (v7.0.0 in my case)
Follow steps given here https://stackoverflow.com/a/19333717/1902831
Install latest protractor version (4.0.10 in my case) using:
npm install -g protractor
Open another terminal and execute these command:
webdriver-manager update
webdriver-manager start
Run tests in another terminal using:
protractor conf.js
If you are using the npm protractor-webdriver grunt plugin (https://www.npmjs.org/package/grunt-protractor-webdriver) you may exeprience same kind of error.
This is due to webdriver termination just before test ends. The test runs successfully and then you have a message like :
Session deleted: Going to shut down the Selenium server
Shutting down Selenium server: http://127.0.0.1:4444
Shut down Selenium server: http://127.0.0.1:4444 (OKOK)
d:\Projets\Clouderial\nodeProjects\cld-apps\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (d:\Projets\Clouderial\nodeProjects\cld-apps\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:419:13)
I resolve this using the keepAlive option in the grunt plugin.
Here is my Gruntfile.js config :
protractor_webdriver: {
options: {
keepAlive : true // True to keep the webdriver alive
},
start: {
},
},
...
I hope this will help someone.
JM.
I also faced the same problem,the trick that worked for me is to use two cmd windows,keeping the one open after typing webdriver-manager start and without pressing enter key(if enter key is pressed the selenium server is shutdown,don't know why) open another cmd window and call your tests.
#Alexandros Spyropoulos, it took me quite some time to figure out how to run protractor and I think we had the same problem. You should open one terminal tab and run webdriver-manager start --standalone. Then open another terminal tag and run protractor ***.conf.js
In the hopes that it might help someone: I'd been having the same problem - encountering ECONNREFUSED using grunt-protractor-runner. The nuance to my case is that I was running my entire E2E environment (test files, web application and entire backend) within a Docker container.
I tried running protractor
with and without additional grunt-protractor-webdriver task to get webdriver up and running 'manually' (no difference);
with and without enabling directConnect and keepAlive settings (bypassing Selenium and resulting in crashes related to Chromedriver, one of which was described here).
The solution was rather simple: increase the amount of memory allocated to the container. On my Windows 10 host machine, I performed the following steps:
Run VBoxManage.exe modifyvm default --memory 8192 (via custom shell script) before starting the docker-machine (via Docker Quickstart script, which is equivalent to docker-machine start). (Thanks to this SO answer).
Changing my shell script to run my default container, adding the --shm-size=4G argument to my docker run command. (See docs)
You can verify if it worked by running df -h in your guest machine, by checking the amount of memory mounted on /dev/shm.
As a result, I no longer have seemingly inexplicable errors such as ECONNREFUSED.
If you run the provided protractor demo, you should try running the protractor config in the same command prompt as selenium. Try running both selenium server and protractor separately.
Make Sure first selenium runs by following command.
webdriver-manager start --standalone
And run the protractor in a separate command window.
protractor conf.js
(In my case conf.js was the config file )
I faced a similar issue to the one #David Remie faced with the Selenium Docker grid/standalone. With minimal RAM/CPU, the tests would start before the webdriver was up. A less resource consuming approach is to wait a few seconds before testing (run 'sleep 5' or something like that).
Increasing RAM was sometimes enough as a workaround for the issue, but the real problem was that the Selenium CMD (/opt/bin/entry_point.sh, starts a supervisor that runs the webdriver) from the image based on https://hub.docker.com/r/selenium/node-base/dockerfile was taking time to start the Selenium webdriver.
webdriver-manager start ----- didn't help, But below one helped
webdriver-manager start --standalone