3

Running a test case on selenium node js got error Error: ECONNREFUSED connect ECONNREFUSED.

Test case

var assert = require('assert'),
 test = require('selenium-webdriver/testing'),
 webdriver = require('selenium-webdriver');
test.describe('Google Search', function () {
 test.it('should work', function (done) {
 this.timeout(100000);
 var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
 driver.get('http://www.google.com');
 var searchBox = driver.findElement(webdriver.By.name('q'));
 searchBox.sendKeys('simple programmer');
 searchBox.getAttribute('value').then(function (value) {
 assert.equal(value, 'simple programmer');
 });
 driver.quit();
 done();
 });
});

And the error stack trace as follows

Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:63528 at ClientRequest. (node_modules\selenium-webdriver\http\index.js:238:15)

asked Mar 16, 2017 at 7:08

1 Answer 1

2

I'm not sure your example would work, if you want to run the tests locally you would need to install and load the correct selenium drivers.

For chrome I tried to use the var driver = new webdriver.Builder().forBrowser('chrome') syntax with no luck, chrome would fire up but not run tests, I just saw the error you describe. However for FireFox var driver = new webdriver.Builder().forBrowser('firefox').build(); workes perfectly !

I found this works (running locally)

 var assert = require('assert'),
 webdriver = require('selenium-webdriver'),
 By = webdriver.By,
 until = webdriver.until,
 chrome = require('selenium-webdriver/chrome'),
 firefox = require('selenium-webdriver/firefox');
 var path = require('chromedriver').path;
 var driver = chrome.Driver.createSession(new chrome.Options(), new 
 chrome.ServiceBuilder(path).build());
 driver.get('http://mysite/myapp/tests/functional/start.html');
 //tests here
answered Feb 8, 2018 at 9:36

1 Comment

working with selenium 4 as well. Thanks Kevin.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.