I have a test that works fine on my machine, but I'm running into problems when I try to move it to the server OS (Windows Server 2008 specifically). All the test really needs to do is load up each URL from a file. When I run it on the server os, it only loads a blank page. But I know it's reading the file, because I can console.log out the list of URLs, and also if my file has 5 lines, it will say 5 tests failed.
A different test I tried which doesn't read from a file, which is just given an array of a few URLs to read through works fine, by the way
Any idea what's going on? Here is my code:
var fs = require('fs');
var i = 0;
var errorlog = "";
module.exports = {
'Person Page Test w/ txt file' : function (browser) {
//iterates through excel sheet testing each URL
fs.readFileSync('PersonPageUrls.txt').toString().split('\n').forEach(function (line) {
var url = line;
i++;
console.log(url);
browser
.url(url)
.saveScreenshot('tests/PersonPage/screenshots/PersonPage' + i + '.png')
.waitForElementVisible('button[class=Person__readMoreButton___28toI]', 3000, false, function(result) {
if (!result.value) {
//if test fails, add to error log string
browser.url(function(currentUrl){
console.log();
errorlog = errorlog + "Test fail on: " + currentUrl.value + "\r\n";
});
}
});
});
browser.end()
}
};
and my nightwatch.json
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "selenium-server-standalone-2.48.2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"on_failure" : true,
"on_error" : true,
"on_success" : true,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Heres the output I get (running on a 2 line text file) (if it isn't obvious, I replaced the real URLs it prints with ~~~~. But it does print the urls):
D:\NightwatchProjects>nightwatch -t tests/PersonPage/personpagetxt.js
Starting selenium server... started - PID: 3004
[Person Page\personpagetxt] Test Suite
======================================
Running: Person Page Test w/ txt file
~~my url 1 ~~
~~my url 2~~
? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds. - expected "visible" but got: not fo
und
at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
at Array.forEach (native)
at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)
? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds. - expected "visible" but got: not fo
und
at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
at Array.forEach (native)
at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)
FAILED: 2 assertions failed (11.389s)
Test fail on: about:blank
Test fail on: about:blank
----------------------------------------------------
TEST FAILURE: 2 assertions failed, 0 passed (11.53s)
? PersonPage\personpagetxt
- Person Page Test w/ txt file
Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"
Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"
D:\NightwatchProjects>
Related
I'm trying to run Logstash in an EC2 Ubuntu instance,
but when I run:
logstash-5.2.0/bin/logstash -f logstash.conf --debug
I get:
Starting puma
Trying to start WebServer {:port=>9600}
start
Trying to start WebServer {:port=>9601}
[api-service] start
Successfully started Logstash API endpoint {:port=>9601}
PeriodicPoller: Stopping
stopping pipeline {:id=>"main"}
Closing inputs
stopping {:plugin=>"LogStash::Inputs::Http"}
Closed inputs
This is logstash.conf
input
{
http
{
host => "127.0.0.1"
port => 31311
}
}
output
{
elasticsearch
{
hosts => ["localhost:9200"]
}
stdout
{
codec => rubydebug
}
}
When I run
curl 'http://localhost:9200/?pretty'
I get:
{
"name" : "QrRfI_U",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "LLdvAaAsQSCULTfl_b4xIA",
"version" : {
"number" : "5.2.0",
"build_hash" : "24e05b9",
"build_date" : "2017-01-24T19:52:35.800Z",
"build_snapshot" : false,
"lucene_version" : "6.4.0"
},
"tagline" : "You Know, for Search"
}
So elasticsearch is running fine.
What if you have your hosts as:
hosts => "localhost"
And make sure that the http port which you've mentioned above is not bound to any other process.
If that's not the case just to make sure, run plugin list and check whether http-input plugin does exist.
We have created a real time chat application, with a socket.io, nodejs & mongodb. It is working fine on to a local & modulus server, but not working as expected on AWS.
Socket gets disconnected randomly with a ping timeout after around 60 sec. I also set "Heart Timeout" & "Heart Interval" but still it gets disconnected.
Here is the attached config file for node,
var config = {
local : {
mode : "LOCAL",
port : 8080,
db_path : "mongodb://localhost/local_db",
site_loc : "http://dummy.local/",
api_loc : "http://dummy.dummy.com/"
},
dev : {
mode : "DEV",
port : 8080,
db_path : "mongodb://dbath:27017/dev_db",
site_loc : 'http://dummy.dummy.com/',
api_loc : 'http://dummy.dummy.com/'
},
stage : {
mode : "STAGE",
port : 3000,
db_path : "mongodb://localhost:27017/stage_db",
site_loc : 'http://dummy.dummy.com/',
api_loc : 'http://dummy.dummy.com/'
},
production : {
mode : "PROD",
port : 443,
db_path : "mongodb://localhost:27017/live_db",
site_loc : 'https://dummy.com/',
api_loc : 'https://dummy.dummy.com/'
}
}
module.exports = function(mode) {
return config[mode || process.argv[2]] || config.local;
}
I resolved this issue, by just adding a port number besides link like,
http://www.chat.com:3000/
by d way thanks everyone...
I am using selenium server, nightwatch on node.js and phantomjs for selenium. I use phantomjs just for headless browser (with it selenium doesn't open browser visually when running tests).
My basic test passes when I use firefox as the browser but fails when I use phantomjs browser.
I setup basic google test:
module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
And setup phantomjs server. This is my nightwatch.json:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "selenium-server-standalone-2.53.1.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 3001,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 3001,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled": true,
"acceptSslCerts": true,
"phantomjs.binary.path" : "phantomjs.exe"
}
}
}
}
When I set browserName to "firefox", test passes, "OK. 3 assertions passed.".
But when it is "phantomjs", one passes, one fails, and one error during execution: " TEST FAILURE: 1 error during execution, 1 assertions failed, 1 passed. (3.511s)".
With errors:
Timed out while waiting for element to be present for 1000 milliseconds. - expected "visible" but got: "not found"
ERROR: Unable to locate element: "input[type=text]" using: css selector
I start server manually.
I tested with latest version of phantomjs (2.1.1) and with 1.9.8
EDIT:
Selenium server also reports this error when using phantomjs:
WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP.
I encoutnered something like this in the past and observed that Default size of phantomjs browser was very small. Could you please try resizing browser and check what happens.
Something like below,
module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.resizeWindow(1000, 800);
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
Yes, resizing the browser window may solve this problem. We are running our test suite in Phantom JS and we have set this in code when we initialize the browser window:
client.maximizeWindow();
I was using selenium-webdriver and wanted to try out nightwatch.js to see if it is easier to use. I followed the instructions here. I decided to let Nightwatch automatically start the selenium server for me so I did what I thought was the proper configuration based on the linked provided above. I get an error that I can't figure out and the output says:
Starting selenium server... started - PID: 1760
[Test] Test Suite
=================
Running: demoTestGoogle
Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:8080
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14)
Connection refused! Is selenium server started?
Process finished with exit code 1
The selenium debug log file says this
13:43:03.394 INFO - Launching a standalone Selenium Server
13:43:03.474 INFO - Java: Oracle Corporation 25.73-b02
13:43:03.474 INFO - OS: Windows 7 6.1 amd64
13:43:03.483 INFO - v2.52.0, with Core v2.52.0. Built from revision 4c2593c
13:43:03.530 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:43:03.530 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
13:43:03.536 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform VISTA
13:43:03.665 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
13:43:03.665 INFO - Selenium Server is up and running
This is my nightwatch.json file
{
"src_folders": [ "tests" ],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": true,
"server_path": "./bin/selenium-server-standalone-jar/jar/selenium-server-standalone-2.52.0.jar",
"start_session" : true,
"log_path": "",
"host": "",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "",
"webdriver.ie.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 8080,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Edit: Added demoTestGoogle, I have a nightwatch.js file in which I run and then it runs the demoTestGoogle function.
nightwatch.js which runs demoTestGoogle
require('nightwatch/bin/runner.js');
demoTestGoogle function in separate JS file
this.demoTestGoogle = function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'The Night Watch')
.end();
};
As suggested by this great guide to Nightwatch, dwyl-learn-nightwatch, you can replace your nightwatch.json file with a .js file to add features like variables, globals and even requiring in Selenium so Nightwatch can see it and run it.
Here's a simple example I modified from that GitHub source to start selenium with its tests. Make sure to install the dependencies in the project, first:
npm install --save-dev nightwatch chromedriver selenium-server
Then replace that JSON file with a .js one, perhaps named nightwatch.conf.js and notice the config options under the selenium key in the config file:
nightwatch.conf.js
const seleniumServer = require("selenium-server");
const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";
module.exports = {
"src_folders": [
"tests/e2e"
],
"output_folder": "./reports",
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver" : chromedriver.path
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": SCREENSHOT_PATH // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // set a (default) timeout period, maybe 5s
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true
}
}
}
}
function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
return count < 10 ? '0' + count : count.toString();
}
var FILECOUNT = 0; // "global" screenshot file count
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath (browser) {
var a = browser.options.desiredCapabilities;
var meta = [a.platform];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}
module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
And the command I use to run this is this, using the locally installed nightwatch version:
nightwatch --config nightwatch.conf.js
Hope that helps!
Goodluck and good on your for testing your code.
Here's the bit in question from my nightwatch.json file :
"selenium" : {
"start_process" : true,
"server_path" : "lib/selenium-server-standalone.jar",
"log_path" : "test_logs"
},
"test_settings" : {
"jenkins" : {
"launch_url" : "url not disclosed",
"selenium_port" : 4444,
"selenium_host" : "jenkins.undisclosed-cloud.com",
"cli_args" : {
"webdriver.chrome.driver" : "/usr/local/bin/chromedriver"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"platform" : "LINUX"
}
}
}
If I change the browserName to firefox then the test runs fine in the specified linux server, which is running on a DOCKER CONTAINER.
But when i choose chrome, i am getting the error:
Connection refused! Is selenium server started?
I've seen this error before on my local machine and managed to fix it by adding chromedriver to the path. I thought it would be the same issue on this linux server but it did not resolve it. I went on to the linux box and verified I can start the chromedriver directly in
"/usr/local/bin/chromedriver"
By the way I have verified I'm on 64-bit linux machine and the symlinks are all set.
Linux version: Linux 3.11.0-26-generic | v2.43.1 | r5163bce
ERROR LOG AFTER RUNNING TEST WITH --verbose
INFO Request: POST /wd/hub/session
- data: {"desiredCapabilities": {"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform": "LINUX","name":"Free Resource Download Test"}}
- headers: {"Content-Type":"application/json; charset=utf-8","Content- Length":151}
ERROR Response 500 POST /wd/hub/session{ status: 13,
sessionId: null,
value:
{ message: 'chrome not reachable\n
So, this is a docker container and a problem is within Chrome&Docker.
you have 2 options, either run add "--privileged" parameter to a Docker or run Chrome with "--no-sandbox" argument.