e2e tests fail on server with selenium - selenium

I'm about to create an application full js based on vuejs. Following https://github.com/vuejs-templates/webpack, I have started a project:
$ vue init webpack my-project && cd my-project && yarn install
When I run unittest yarn run unit everything goes well, but when I run yarn run e2e which runs nightwatch.js, I get this error:
> Starting dev server...
Starting to optimize CSS...
> Listening at http://localhost:8889
Starting selenium server... started - PID: 23451
started - PID: 23451
[Test] Test Suite
=====================
Running: default e2e tests
[client :: capabilities] Test Suite
=======================================
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ Error: socket hang up
at createHangUpError (_http_client.js:344:15)
at Socket.socketOnEnd (_http_client.js:436:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The selenium server is started on the fly when the e2e tests start and is shutdown when they finish. I'm sure because when I stop nightwatch.js before it fails I see :
$ ps aux | grep -i selenium
java -Dwebdriver.chrome.driver=node_modules/chromedriver/lib/chromedriver/chromedriver -jar node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar -port 4444
So the real error based on the output I get is mostlikely Error retrieving a new session from the selenium server. How do I fix this?
package.json
"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^2.53.1",
test/e2e/nightwatch.conf.js
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},

I recently started a Vue.js project with Webpack template. Your problem sounds familiar, but surprisingly, I forgot how I solved it...
The only difference I can see between your package.json and mine is the selenium-server version (^3.0.1). You should also check your Node version because Nightwatch is based on it. I remember that I had to update Node and npm for some reason (I do not use Yarn).
This is my environment (and it is working fine):
Node.js (v8.1.3)
npm (5.0.3)

Did you run node nightwatch.config.js, or node {whatever your nightwatch config file is called}. This will install Selenium and ChromeDriver correctly.

Related

Cypress E2E Testing VueJS with GitLab Runner returns 404 not found

I have the following simple GitLab CI file
stages:
- e2e_test
e2e_test:
stage: e2e_test
tags:
- test
script:
- npm config set strict-ssl false
- npm install
- npm run test:e2e:ci
I am running the above script in a shell runner for very specific corporate reasons.
This script results in a 404 error with the following log
npm run test:e2e:ci
> todo-app#0.1.0 test:e2e:ci /home/gitlab-runner/builds/UHz6XzwM/0/microservices-and-cognitive-solutions/demos/microservice-concept/todo-app
> vue-cli-service test:e2e --headless
INFO Starting e2e tests...
INFO Starting development server...
DONE Compiled successfully in 8865ms6:51:36 PM
App running at:
- Local: http://localhost:8083/
- Network: http://10.108.201.150:8083/
App is served in production mode.
Note this is for preview or E2E testing only.
====================================================================================================
(Run Starting)
tput: No value for $TERM and no -T specified
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 3.8.3 │
│ Browser: Electron 78 (headless) │
│ Specs: 1 found (test.js) │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: test.js (1 of 1)
Browserslist: caniuse-lite is outdated. Please run the following command: `npm update`
My First Test
1) Visits the app root url
0 passing (341ms)
1 failing
1) My First Test Visits the app root url:
CypressError: cy.visit() failed trying to load:
http://localhost:8083/
The response we received from your web server was:
> 404: Not Found
This was considered a failure because the status code was not '2xx'.
If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'
at Object.cypressErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86207:11)
at Object.throwErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86162:18)
at Object.throwErrByPath (http://localhost:8083/__cypress/runner/cypress_runner.js:86194:17)
at http://localhost:8083/__cypress/runner/cypress_runner.js:71493:31
at visitFailedByErr (http://localhost:8083/__cypress/runner/cypress_runner.js:71006:12)
at http://localhost:8083/__cypress/runner/cypress_runner.js:71474:22
at tryCatcher (http://localhost:8083/__cypress/runner/cypress_runner.js:120203:23)
at Promise._settlePromiseFromHandler (http://localhost:8083/__cypress/runner/cypress_runner.js:118139:31)
at Promise._settlePromise (http://localhost:8083/__cypress/runner/cypress_runner.js:118196:18)
at Promise._settlePromise0 (http://localhost:8083/__cypress/runner/cypress_runner.js:118241:10)
at Promise._settlePromises (http://localhost:8083/__cypress/runner/cypress_runner.js:118316:18)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueue (http://localhost:8083/__cypress/runner/cypress_runner.js:114928:16)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114938:10)
at Async.drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114812:14)
If I clone the same repository on the same server and manually run the following commands in the terminal it works fine.
npm install
npm run test:e2e:ci
Any idea why the same commands would fail in a GitLab runner shell but working in a user shell
I found the problem to fix my issue. I needed to set a no_proxy environment entry in my gitlab-runner config.toml file. This won't affect everyone, but since i am behind a corporate proxy, I needed it.
export no_proxy="localhost"

Not able to run basic test using webdriver IO

I am new to webdriver I am trying to run following code
var assert = require('assert');
describe('webdriver.io page', function() {
it('should have the right title', function () {
browser.url('/');
var title = browser.getTitle();
assert.equal(title,'WebDriverIO - Selenium 2.0 javascript bindings for nodejs');
});
});
When I am trying to run $npm test it is giving me following exception
> web-wedio#1.0.0 test /Users/user_namej/Downloads/web-wedio
> wdio
A service failed in the 'onPrepare' hook
Error: Selenium exited before it could start
Another Selenium process may already be running or your java version may be out of date.
Be sure to check the official Selenium release notes for minimum required java version: https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG
at ChildProcess.errorIfNeverStarted (/Users/user_namej/Downloads/web-wedio/node_modules/selenium-standalone/lib/start.js:158:10)
at ChildProcess.emit (events.js:159:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
Continue...
[23:57:43] COMMAND POST "/wd/hub/session"
ERROR: Error forwarding the new session Empty pool of VM for setup Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences#9288a03, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, maxInstances=5, requestOrigins={name=webdriverio, version=4.13.1, url=http://webdriver.io}}]
firefox
at new RuntimeError (/Users/user_namej/Downloads/web-wedio/node_modules/webdriverio/build/lib/utils/ErrorHandler.js:143:12)
at Request._callback (/Users/user_namej/Downloads/web-wedio/node_modules/webdriverio/build/lib/utils/RequestHandler.js:316:39)
at Request.self.callback (/Users/user_namej/Downloads/web-wedio/node_modules/request/request.js:185:22)
at Request.emit (events.js:159:13)
at Request.<anonymous> (/Users/user_namej/Downloads/web-wedio/node_modules/request/request.js:1157:10)
at Request.emit (events.js:159:13)
at IncomingMessage.<anonymous> (/Users/user_namej/Downloads/web-wedio/node_modules/request/request.js:1079:12)
at Object.onceWrapper (events.js:254:19)
at IncomingMessage.emit (events.js:164:20)
at endReadableNT (_stream_readable.js:1062:12)
I try . to shut down server using
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
but it is redirecting to 500 error page,Also I tried to do it with different commands
lsof -i :4444
kill -9 $(lsof -ti tcp:4444)
Still not working.What should I do.
Please let me know if more details required
Silly question, but have you checked your java version to see if it's compatible?
If not, maybe this could help explain your problem: https://github.com/SeleniumHQ/selenium/issues/2043

Protractor with Visual Studio Team Services - "Could not find chrome binary"

I've been trying to setup Protractor on Visual Studio Team Services and currently I'm having a build run a .bat file to start my protractor test.
When the build runs, it gives me an error message saying Could not find Chrome binary, and gives me a file location that doesn't exist on my directory.
Error trace-back:
2017-05-25T20:43:49.3521640Z ##[section]Starting: Run script protractor.bat
2017-05-25T20:43:49.3521640Z
===========================================================================
2017-05-25T20:43:49.3521640Z Task : Batch Script
2017-05-25T20:43:49.3521640Z Description : Run a windows cmd or bat script and optionally allow it to change the environment
2017-05-25T20:43:49.3521640Z Version : 1.1.3
2017-05-25T20:43:49.3521640Z Author : Microsoft Corporation
2017-05-25T20:43:49.3521640Z Help : [More Information]
(https://go.microsoft.com/fwlink/?LinkID=613733)
2017-05-25T20:43:49.3521640Z
============================================================================
2017-05-25T20:43:49.3601629Z ##[command]d:\a\1\s\protractor.bat
2017-05-25T20:43:49.3761643Z
2017-05-25T20:43:49.3761643Z d:\a\1\s>cd .\e2e
2017-05-25T20:43:49.3761643Z
2017-05-25T20:43:49.3761643Z d:\a\1\s\E2E>protractor conf.js
2017-05-25T20:43:50.8302366Z [20:43:50] I/direct - Using ChromeDriver directly...
2017-05-25T20:43:50.8342360Z [20:43:50] I/launcher - Running 1 instances of WebDriver
2017-05-25T20:43:50.8342360Z [20:43:50] E/direct - Error code: 135
2017-05-25T20:43:50.8342360Z [20:43:50] E/direct - Error message: Could not find chromedriver at C:\NPM\Modules\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.25.exe
2017-05-25T20:43:50.8342360Z [20:43:50] E/direct - Error: Could not find chromedriver at C:\NPM\Modules\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.25.exe
2017-05-25T20:43:50.8342360Z at Direct.getNewDriver (C:\NPM\Modules\node_modules\protractor\built\driverProviders\direct.js:65:27)
2017-05-25T20:43:50.8342360Z at Runner.createBrowser (C:\NPM\Modules\node_modules\protractor\built\runner.js:197:43)
2017-05-25T20:43:50.8342360Z at C:\NPM\Modules\node_modules\protractor\built\runner.js:276:30
2017-05-25T20:43:50.8342360Z at _fulfilled (C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:834:54)
2017-05-25T20:43:50.8342360Z at self.promiseDispatch.done (C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:863:30)
2017-05-25T20:43:50.8342360Z at Promise.promise.promiseDispatch (C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:796:13)
2017-05-25T20:43:50.8342360Z at C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:556:49
2017-05-25T20:43:50.8342360Z at runSingle (C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:137:13)
2017-05-25T20:43:50.8342360Z at flush (C:\NPM\Modules\node_modules\protractor\node_modules\q\q.js:125:13)
2017-05-25T20:43:50.8342360Z at _combinedTickCallback (internal/process/next_tick.js:67:7)
2017-05-25T20:43:50.8342360Z [20:43:50] E/launcher - Process exited with error code 135
2017-05-25T20:43:50.8552361Z ##[error]Process completed with exit code 135.
2017-05-25T20:43:50.8582364Z ##[section]Finishing: Run script protractor.bat
When I install Chromedriver on the build it installs it to a different file location:
d:\a\1\s\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
The test runs fine locally but doesn't work when I commit it to VSTS.
Is there anyway to make it so that chromedriver is installed in a different file location, or have Selenium look in a different place for chromedriver?
Thanks
Put the relative path to the ChromeDriver executable in conf.js. This is well-documented.
Use webdriver-manager package that comes with protractor - it can download any version of any binary that you want - https://www.npmjs.com/package/webdriver-manager
So it ends up with running webdriver-manager update before starting protractor tests (just make sure that if you are running locally installed protractor - you also update using locally installed webdriver-manager)
First, based on the log, you are using Hosted Build agent that running as service, but the test need to be interact with UI, so you can’t to do Protractor test with Chrome on Hosted Build agent.
You can refer to this way to set up a private build agent on your machine: Deploy an agent on Windows
Secondly, you can refer to these steps to install chromedriver:
Add Npm task (npm command: install; arguments: -g protractor)
Add Command Line task (Tool: webdriver-manager; Arguments: update --versions.chrome 2.25)

NightWatch Selenium Socket Hangup in Jenkins / Ubuntu16

Issue :
We are running NightWatch tests in Jenkins, and once in a while, we get this error :
[0;31mConnection refused! Is selenium server started?
[0m[0;90m{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at Socket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:501:12) code: 'ECONNRESET' }[0m
The fix recommended in other places is already there :
export DBUS_SESSION_BUS_ADDRESS=/dev/null
This is how we run the tests :
sudo npm install selenium-standalone -g
selenium-standalone install --version=3.0.1 --baseURL=https://selenium-release.storage.googleapis.com --drivers.chrome.version=2.28 --drivers.chrome.baseURL=https://chromedriver.storage.googleapis.com --basePath=bin
sudo npm install nightwatch#0.9.13 -g && nightwatch --tag sanity --retries 1 --suiteRetries 1
Rebuilding the job usually run the tests successfully.
Softwares' version:
Chrome : 57
Chrome driver : 2.28
Selenium: 3.0.1
NightWatch : 0.9.13 (bumped down from 0.9.14 in case the latest release had a bug but no change.)
Jenkins : 1.6x
Ubuntu : 16.04
Using xvfb
Error Scenarios
The tests were running fine until about 2 weeks ago, just when we switched to Ubuntu 16, but that day it started happening on Ubuntu 14 too.
It especially happens when we've just spun a new Jenkins slave (on AWS cloud.) Happens more often at the very start of the test run but sometimes it happens in the middle of the run too.
I'll appreciate any help or pointers!
I have the same problem yesterday.
Maybe you can change the version of Chrome.
such as Chrome:55.
when i changed the version of chrome the selenium
We ran into a similar issue, but our error message was more specific:
Selenium is already running on port ####. Or some other service is.
The solution was to use the Jenkins Port Allocator Plugin to assign an available port number to an environment variable.
From there, we were able to set the port number in our globals.js like this (with a default of 4444 for running locally):
portNumber: process.env.PORT_NUMBER || 4444,
In our nightwatch.conf.js file, we used a lodash template to replace values in our nightwatch.json like this:
fs = require('fs'),
_ = require('lodash'),
template = _.template(fs.readFileSync('./nightwatch.json', 'utf8')),
settingsString,
settings;
settingsString = template({
portNumber: globals.portNumber
});
settings = JSON.parse(settingsString);
module.exports = settings;
Finally, in our nightwatch.conf file, we set the values for all port references to:
"<%= portNumber %>"

seleniumAddress not taking effect in Protractor config

I am having a issue where seleniumAddress is not taking effect in protractor config. I use seleniumAddress: 'http://127.0.0.1:4444/wd/hub' but I see:
[18:52:35] E/launcher - Timed out waiting for the WebDriver server at http://127.0.0.1:47780/hub
The port should be 4444 instead of 47780. Any ideas?
one#development ~/github/drop $ protractor --version
Version 4.0.7