Selenium doesn't start webdriver - selenium

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.

Related

How to run feature files in Safari using WebDriverIO?

I'm using WebDriverIO to automate a web page, I'm able to run my feature files in Chrome but I need them to run in Safari. I'm using a Mojave 10.14.6 device. I've allowed remote automation on safari, and enabled safaridriver from terminal.
My wdio.conf.js capabilities are look like this:
capabilities: [{
maxInstances: 5,
browserName: 'safari'
}]
When I run using chrome it works as spected but in the case of safari I get the following message:
ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4444
My package.json looks like this:
"dependencies": {
"#wdio/cli": "^7.5.7"
},
"devDependencies": {
"#wdio/cucumber-framework": "^7.5.3",
"#wdio/local-runner": "^7.5.7",
"#wdio/spec-reporter": "^7.5.7",
"chromedriver": "^90.0.0",
"wdio-chromedriver-service": "^7.0.0"
}
Is there any other configuration I need to add in wdio.conf.js file?
Thanks in advance.
It turns out to be a problem with the port that was being used. After the port was changed from 4444 to the correct value, the issue was solved.

Karate UI & Selenium standalone server input commands not working [duplicate]

This question already has answers here:
Run tests with Karate-Chrome (Connection refused exception)
(3 answers)
Closed 1 year ago.
I am running selenium-standalone server locally and trying to run this example feature against it.
Scenario: try to login to github and then do a google search
Given driver 'https://github.com/login'
And input('#login_field', 'dummy')
And input('#password', 'world')
When submit().click("input[name=commit]")
Then match html('#js-flash-container') contains 'Incorrect username or password.'
Given driver 'https://google.com'
And input("input[name=q]", 'karate dsl')
When submit().click("input[name=btnI]")
Then waitForUrl('https://github.com/intuit/karate')
I have configured my driver as such
* configure driver = { type: 'chromedriver', start: false, webDriverUrl: 'http://localhost:4444/wd/hub' }
Chromedriver is running:
ChromeDriver 2.46.628411 on port 9515
The chrome browser displays and navigates to Google. The input command/method attempts to write the login id and password and clicks the Commit button. The error message expected by the test does display so the test passes.
The issue is input command/method attempts while running in this configuration. It does not input dummy or world into the appropriate fields they are just left empty.
If I run the feature with this driver configuration * configure driver = { type: 'chrome', showDriverLog: true } it works just fine.
I am not very familiar with this configuration and just starting to use Karate UI but we do use selenium-standalone server and chromedriver with other projects and do not experience this issue.
I did search for a solution but wasn't able to find anything useful.
Has anyone else run into this issue before and if so how did you resolve it?
Thank you
Very well can be an old version of Selenium server. Just checked and this works with Chrome / ChromeDriver 83
It would help if you can follow this process: https://github.com/intuit/karate/tree/develop/examples/ui-test

protractor error 105 and webdriver-manager interactions

I've seen this question before but nothing in the answers solved my problems. I am trying to do the protractor tutorial and here is the conf.js file:
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
Here is the spec.js file:
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
I am also getting ERROR100 on running another project, but for simplicity, I'm going to focus on this one project. Here is the error I'm getting:
E/configParser - Error code: 105
E/configParser - Error message: failed loading configuration file conf.js
E/configParser - C:\Workspace\ProtractorCalc\conf.js:6
I know this has to be something with my webdriver/selenium, but I don't know enough to debug it properly. I run webdriver-manager update and webdriver-manager start before running the conf.js file and when I do webdriver-manager start, it looks like it's running, but also prompts me to end webdriver-manager start in order to give me control of the command line:
I/e the last line when running it is "Selenium Server is up and running"
but then to be able to type protractor conf.js, I have to enter ctrl+c and I get this back:
Attempting to shut down selenium nicely
Staying alive until the Selenium Standalone process exists
events.js:163 throw er; //Unhandled 'error' event
Error: read ECONNRESET
at exports._errnoException (util.js:1050:11)
at TCP.onread(net.js.581:26)
Terminate batch job (Y/N)?
So is webdriver-manager kicking me out and that's why protractor's conf.js file is failing?
webdriver-manager start starts the webdriver, as you say, and it is running properly. However, when you press ctrl+c to "regain control", you're actually killing the process. It's at that point that webdriver stops, and that's why protractor won't run.
The easiest way to do this correctly is to open two command windows: run webdriver-manager start in the first one and protractor conf in the second.
First the logging refers to the conf.js file. When I look at your file I guess the problem is that you don't provide a capability to run the tests against. In other words, against what browser do you want to run your tests?
Here is an example project which has an example conf.js-file. If you change your file to this I think it should work without a problem
// An example configuration file.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};

Setting up selenium grid to use Microsoft edge

Environment:
win10 (build 10240)
Vaadin Testbench 4.1
Selenium 2.53
Drivers for Firefox, Chrome, IE11 and Edge for build 10240
Node and hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role node -Dwebdriver.edge.driver=c:\users\powder\MicrosoftWebDriver.exe
Usage in java code
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.edge().getBrowserName());
//DesiredCapabilities capabilities = DesiredCapabilities.edge(); Tried as well
capabilities.setCapability("acceptSslCerts", "true");
setDriver(new RemoteWebDriver(new URL(this.remoteHubUrl), capabilities));
getDriver().get("http://www.google.com");
Errormessage
Error forwarding the new session cannot find : Capabilities [{acceptSslCerts=true, browserName=MicrosoftEdge}]
Selenium grid console - edge is missing
Everything is working fine with other browsers, but not with Edge. Any ideas how to fix that?
There are 2 problems here:
First, if you look at the default node config you will notice that only Firefox, Chrome and IE are enabled by default (that's why all you need to use them is specify driver location via a system property). If you want to use any other browser then you need to use your own json config:
{
"capabilities": [
{
"browserName": "MicrosoftEdge",
"platform": "WIN10",
"maxInstances": 1
},
{
"browserName": "firefox",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "chrome",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "internet explorer",
"platform": "WIN10",
"maxInstances": 1
}
],
"hub": "http://selenium-hub-host:4444"
}
and pass it to your command line:
java "-Dwebdriver.edge.driver=c:\path\to\MicrosoftWebDriver.exe" "-Dwebdriver.gecko.driver=c:\path\to\geckodriver.exe" "-Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe" "-Dwebdriver.ie.driver=c:\path\to\IEDriverServer.exe" -jar "c:\path\to\selenium-server-standalone.jar" -role node -nodeConfig "c:\path\to\the\above.json"
(btw: alternatively you can also put the whole config in your command line using multiple -capabilities or -browser params)
This in theory should work. However in practice you will often be hit by the 2nd problem, which is: "sometimes it randomly doesn't work" ;] Initially everything will look fine: your grid will properly report Edge browser capability on the console, it will properly delegate tests to a node containing Edge, the node will properly start Edge browser, however the browser will sometimes freeze on its initial blue screen with e logo and after few seconds you will get some exception on the client side without any meaningful stack-trace nor message (I don't have it saved anywhere to paste here now).
Some people suggested a workaround to start 2 separate nodes on the same machine (on different ports of course) : one only for Edge and second for IE, FF and Chrome. This way it seems to work pretty stable (tested on Edge build 15063 running on win-10 and Selenium-3.4.0)
Additional info:
Apart from the above, Edge driver has few limitations that require specific workarounds in the configuration:
currently only 1 concurrent session is supported by the driver/browser so maxInstances must be set to 1 (kudos to this answer)
the driver must be running in the foreground, so that the browser window can be actually displayed on the desktop. Therefore the node cannot be started as a Windows Service nor from Windows Task Scheduler at startup. The best way to automate starting of the node is to configure auto-login and add a batch script starting the node to user's Startup Programs as described in my article
Try putting the -D parameters before the -jar parameter. I had an issue where it thought -Dwebdriver..... was a parameter to selenium itself instead of java.

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.