ECONNREFUSED using nightwatch-accessibility library - nightwatch.js

I'm trying to use the nightwatch-accessibility library, but keep getting error
POST /session/b4e18278544c74b9213c030b8119ee7e/timeouts/async_script - ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:9515
Error while running .setTimeoutsAsyncScript() protocol action: An unknown error has occurred.
POST /session/b4e18278544c74b9213c030b8119ee7e/execute_async - ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:9515
Error while running .executeScriptAsync() protocol action: An unknown error has occurred.
Normal tests work fine. As far as I can tell I am following the example correctly. The test assertions work correctly it just appears at the end of the test run.
nightwatch.json
{
"src_folders": ["test"],
"page_objects_path": "page-objects",
"globals_path": "./globals.js",
"custom_commands_path": ["./node_modules/nightwatch-accessibility/commands"],
"custom_assertions_path": ["./node_modules/nightwatch-accessibility/assertions"],
"end_session_on_fail": false,
"skip_testcases_on_fail": false,
"selenium": {
"start_process": false
},
"webdriver": {
"start_process": true,
"server_path": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"port": 9515
},
"test_settings": {
"default": {
"webdriver.port": 9515,
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}
globals.js
const chromedriver = require('chromedriver');
module.exports = {
before: function (done) {
chromedriver.start();
done();
},
after: function (done) {
chromedriver.stop();
done();
}
};
First test
module.exports = {
'#tags': ['accessibility'],
'First test': function (browser) {
browser
.url(`http://www.google.com`)
.pause(3000)
.initAccessibility()
.assert.accessibility('html', {
verbose: true
})
.end()
}
}
Executing by typing nightwatch from the terminal like I would other tests. Any ideas and is this the best accessibility assertion library for NightwatchJS?

I ended up using nightwatch-axe-verbose instead. Usage details included on this web accessibility testing using nightwatch blog post.

Related

How to run tests programmatically in Nightwatch.js?

I'm using Nightwatch.js and trying to run E2E tests using the programmatic API as described here.
Here is my nightwatch.json file:
{
"src_folders": ["tests"],
"webdriver": {
"start_process": true,
"server_path": "node_modules/.bin/chromedriver",
"port": 9515
},
"test_settings": {
"default": {
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}
and index.js script:
const Nightwatch = require('nightwatch');
Nightwatch.runTests(require('./nightwatch.json')).then(() => {
console.log('All tests has been passed!');
}).catch(err => {
console.log(err);
});
When I run the script I get the error:
Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:9515". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
I feel it needs some configuration but the documentation isn't very helpful here.

Using karma-typescript with graphql-tag loader

I am trying to run tests written in TypeScript using tape and the karma-typescript loader.
In my project I use webpack with graphql-tag/loader and import the queries directly into my TypeScript files like:
import myQuery from "../query/hello.graphql";
These imports are causing issues when I try and run the tests.
module.exports = function (config) {
config.set({
frameworks: ["tap", "karma-typescript"],
files: [
"src/**/*.ts",
"src/**/*.tsx",
"query/**/*.graphql"
],
preprocessors: {
"src/**/*.ts": ["karma-typescript"],
"src/**/*.tsx": ["karma-typescript"]
},
karmaTypescriptConfig: {
compilerOptions: {
"skipLibCheck": true,
"allowSyntheticDefaultImports": true
},
bundlerOptions: {
transforms: [
require("karma-typescript-es6-transform")()
]
}
},
reporters: ["progress", "karma-typescript"],
browsers: ["Firefox"]
});
};
I guess that I would ideally like to perform a second transform on the .graphql files. Based on the approach used in jest-transform-graphql, I tried adding another transform:
function (context, callback) {
if (/\.graphql$/.test(context.module)) {
context.source = loader.call({ cacheable() { } }, context.source);
return callback(undefined, true);
}
return callback(undefined, false);
}
But I still get errors like:
{
"message": "SyntaxError: unexpected token: identifier\nat query/hello.graphql:1:6\n\n",
"str": "SyntaxError: unexpected token: identifier\nat query/hello.graphql:1:6\n\n"
}
How can I apply the transformation to the graphql files, so that I don't get syntax errors from them in the browser?

Nightwatchjs: how to solve Error retrieving a new session from the selenium server?

This is my part of my config:
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./selenium-server-standalone-3.8.1.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver": "./chromedriver_win32/chromedriver.exe"
}
},
test_settings" : {
"default" : {
"use_ssl": true,
"credentials": {
"username": "admin",
"key": "secret"
},
The test was running fine until I inserted use_ssl. Now I am getting this error:
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:797:
at exports._errnoException (util.js:1020:11)
at WriteWrap.afterWrite (net.js:800:14) code: 'EPROTO', errno: 'EPROTO', syscall: 'write' }
I am trying to test a page which requires windows authentication.

Timeout when trying to create elasticsearch index

I am trying to create an elasticsearch index and am getting a timeout error. The commented out code works fine, so the server is running and is pingable. Here is my code:
import * as elasticsearch from "elasticsearch";
export const elasticClient = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace',
requestTimeout: 30000
});
// elasticClient.ping({
// requestTimeout: 30000,
// }, function (error) {
// if (error) {
// console.error('elasticsearch cluster is down!');
// } else {
// console.log('All is well');
// }
// });
// elasticClient.cluster.health({},function(err:any,resp:any) {
// console.log("-- Client Health --",resp);
// });
elasticClient.indices.create({
index: 'grr'
},function(err,resp,status) {
if(err) {
console.log(err);
}
else {
console.log("create",resp);
}
});
Here is the error message:
Elasticsearch INFO: 2017-06-17T02:36:12Z
Adding connection to http://localhost:9200/
Elasticsearch DEBUG: 2017-06-17T02:36:12Z
starting request {
"method": "PUT",
"path": "/grr",
"query": {}
}
{ Error: Request Timeout after 30000ms
at C:\Users\myname\myproject\node_modules\elasticsearch\src\lib\transport.js:342:15
at Timeout.<anonymous> (C:\Users\myname\myproject\node_modules\elasticsearch\src\lib\transport.js:371:7)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
status: 408,
displayName: 'RequestTimeout',
message: 'Request Timeout after 30000ms' }
Elasticsearch TRACE: 2017-06-17T02:36:42Z
-> PUT http://localhost:9200/grr
<- 0
I am really at a loss of what's going on. I'm using version 13.1.0 of the elasticsearch.js library
edit:
I've also tried using a curl statement (taken directly from the official site and modified to work in a Windows command prompt) to create the index and am having a similar issue, except it doesn't time-out; it just goes into an infinite loop.
It ended up being my Symantec Antivirus!! I uninstalled it and everything works as normal.

chutzpah with requirejs and sinon

I am trying to run chutzpah with Qunit requirejs and sinon. I have defined the chutzpah json like this:
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References": [
{ "Path": "Scripts/jquery-2.1.1.js" },
{ "Path": "Scripts/sinon-1.9.1.js" },
{ "Path": "Scripts/require.js" }
],
"Tests": [
{ "Path": "tests" }
]
}
the unit test:
define(['base/core', 'base/myService'],
function (core, myService) {
module("chutzpah test");
test("will return correct version from core", function() {
var version = core.version;
equal(version, 8);
});
test("sinon checking", function() {
sinon.stub(myService, 'getMessage').returns('fake value');
var result = core.returnMessage();
equal(result, 'fake value');
});
});
when I run the test, I am always getting the following error:
------ Discover test started ------
Error: Timeout occured when executing test file
While Running:d:\tdd javascript\unittestjavascript\unittestjavascript\tests\base\mytests.js
========== Discover test finished: 0 found (0:00:11.1241566) ==========
I have tried to find why it's doesn't work, but had no success.
Does any one have any idea what I am doing wrong?

Resources