I'm attempting to setup Nightwatch.js for the first time. I'm following the following tutorial: https://github.com/dwyl/learn-nightwatch
Unfortunately I've hit a roadblock, and I'm in need of help resolving it.
Error retrieving a new session from the selenium server.
Connection refused! Is selenium server started?
nightwatch.conf.js
module.exports = {
"src_folders": [
"test"// Where you are storing your Nightwatch e2e/UAT tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/nightwatch/bin/selenium.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // set to false to test progressive enhancement
}
}
}
}
guinea-pig.js
module.exports = { // addapted from: https://git.io/vodU0
'Guinea Pig Assert Title': function(browser) {
browser
.url('https://saucelabs.com/test/guinea-pig')
.waitForElementVisible('body')
.assert.title('I am a page title - Sauce Labs')
.saveScreenshot('ginea-pig-test.png')
.end();
}
};
Based on the configuration setup. I kept it as basic as possible. I cannot pinpoint the source where it would suggest another selenium server has started. Any ideas?
EDIT: TIMEOUT ERROR
In your nightwatch.json file, within "selenium"
Make sure your server path is correct.
Make sure your webdriver.chrome.driver path is correct.
Those are specific to your machine. If those do not refer to the correct file in the correct location, you'll get problems starting the selenium server.
After that, you want to make certain that the version of the selenium server you have works with the version of chrome driver you have and that that will work with the version of the Chrome browser you have.
But as Krishnan Mahadevanindicated, without the whole error message, we can't be of much more help.
The solution involved deleting my instance of Chrome (although it was the most recent version) and simply reinstalling the browser again.
I encourage all facing the same problems to first look at QualiT's response above as it's the more conventional troubleshooting strategy.
I had got the same issue when I used vue-cli init on my project. after I updated to Java 9, this problem was resolved.
Related
Running commands via Node's execFile on windows is a nightmare. Many a time, when I get a "Command failed" error if I copy the "failed" command from the error it executes just fine. Sometimes, trying windowsVerbatimArguments: true helps but usually, it does not.
For example, right now I am running Visual Studio's MSBuild.exe, with the following parameters in Node.js - I have printed the exact array passed to execFile:
Running MSBuild with parameters: [
'D:\\PROJECT\\vcxproj\\HelperProject.vcxproj',
'-t:OutputBuildMacro',
'-p:ProjectToImport=D:\\PROJECT\\vcxproj\\HelperProject.vcxproj;PropertyToGet="OutputType,BlueProjectsVersionPropsGlobalIncluded"'
]
Executable path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe
If I copy these items from the array and paste them into the command line it will run just fine. Clearly, Node.js is messing up when passing the command. Because this has happened to me many times, just a few weeks ago with Irfan View, I am not looking for a solution for this specific problem - I would just be asking a similar question again very soon.
I am looking for a guide how to see what is Node.js actually passing so that I can make a guess how to edit the parameters so that they are accepted by the command I call.
How to see what is Node.js exactly sunning why I call execFile?
You can use NODE_DEBUG environment variable to get extra info out of NodeJS.
You can find docs here.
For example this index.js:
const { execFile } = require('child_process');
execFile('/bin/ls', ['/Volumes'], {}, (err, stdout, stderr) => {
if (err) {
console.error('Command failed');
} else {
console.log('Command succeded');
}
});
And to enable debug logging for child_process module execute:
NODE_DEBUG=CHILD_PROCESS node index.js
(On Windows the environment variable seems to be set differently)
set NODE_DEBUG=CHILD_PROCESS & node index.js
in my case it produces this kind of output:
CHILD_PROCESS 85208: spawn {
cwd: null,
env: null,
gid: undefined,
uid: undefined,
shell: false,
windowsHide: false,
windowsVerbatimArguments: false,
args: [ '/bin/ls', '/Volumes' ],
detached: false,
envPairs: [
'COMMAND_MODE=unix2003',
...
'TERM=xterm-256color',
'NODE_DEBUG=CHILD_PROCESS',
],
file: '/bin/ls'
}
P.S.
Setting NODE_DEBUG=* will produce all debug log information that is available in NodeJS.
I am running a Gatsby site on Netlify, there is an error / crash specific to IE and I want to show an alert and then redirect to chrome download page if the user is using IE, since I am not supporting IE anyway. I think the crash is caused by a npm package and i dont wanna change to other one because it suit my need.
I put the below script in the Layout component which is run on every page, but the error kicks in and crash the site, the site flash a normal dom before it crash. Am wondering if there are any way to fix it
The script works fine if i change the condition to chrome and run it on chrome to test it
//Layout.js
const handleIE = () => {
if (typeof window !== "undefined") {
let ua = window.navigator.userAgent
if(ua.indexOf('MSIE') > -1) {
alert('Internet Explorer is not supported. Please use Chrome or Firefox')
window.location.href = "https://www.google.com/chrome/";
}
}
}
<Helmet>
<script>{handleIE()}</script>
</Helmet>
// Error log on IE
DOM7011: The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337
HTML1300: Navigation occurred.
SEC7118: XMLHttpRequest for https://ka-f.fontawesome.com/releases/v5.15.3/css/free.min.css?token=e4232fccfser required Cross Origin Resource Sharing (CORS).
SEC7118: XMLHttpRequest for https://ka-f.fontawesome.com/releases/v5.15.3/css/free-v4-shims.min.css?token=e4232fccfser required Cross Origin Resource Sharing (CORS).
SEC7118: XMLHttpRequest for https://ka-f.fontawesome.com/releases/v5.15.3/css/free-v4-font-face.min.css?token=e4232fccfser required Cross Origin Resource Sharing (CORS).
SCRIPT1003: Expected ':' File: classic.js, Line: 679, Column: 32
SCRIPT1003: Expected ':' File: classic.js, Line: 679, Column: 32
[object Error]
description "Object doesn't support property or method 'trunc'"
message "Object doesn't support property or method 'trunc'"
name "TypeError"
number -2146827850
stack "TypeError: Object doesn't support property or method 'trunc'
SCRIPT438: Object doesn't support property or method 'trunc'
File: framework-7bdbbf12b92c7ff172a2.js, Line: 2, Column: 2442
Thank you!!
The IE issue is breaking your application before the script can load. Despite being improbable because you are loading the script in each page that imports the Layout component (you may want to use one of the gatsby-browser APIs), your code seems to work.
If you want to be able to bypass this limitation by showing an alert to the IE
user you may need to polyfill the functionality, at least to allow the trunc method, which seems to be the offending one.
Said that, this trunc method may come from your code (unlikely) or from third-party dependencies. If it's from your code just remove it or find another IE-friendly solution. If it comes from one of the Node modules, you may need to find another solution.
First of all, you need to find which dependency is causing this issue, then, as it is described in this GitHub thread.
Create a .babelrc at the root of your Gatsby project:
{
"env": {
"test": {
"presets": [
"#babel/preset-env",
{
"loose": true,
"modules": "commonjs",
"useBuiltIns": "entry",
"targets": { "browsers": [">0.25%", "not dead"] }
}
]
}
},
"presets": [
"babel-preset-gatsby",
[
"#babel/preset-env",
{
"debug": true,
"loose": true,
"modules": false,
"useBuiltIns": "entry",
"targets": { "browsers": [">0.25%", "not dead"] }
}
]
],
"plugins": [
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
],
"babel-plugin-macros",
"#babel/plugin-syntax-dynamic-import",
[
"#babel/plugin-transform-runtime",
{
"helpers": true,
"regenerator": true
}
]
]
}
Note: you may need to install the required modules.
Then, you only need to add the polyfill. In your gatsby-browser.js:
import '#babel/polyfill'
// eslint-disable-next-line import/prefer-default-export
export const onClientEntry = () => {
// Without this function body the import will not be picked up.
// handleIE()
}
Aas I said at the beginning of the post, this gatsby-browser.js API (onClientEntry) will work for your use case, so you can re-use it. You can load there your script (handleIE) to check the user agent. In that way, you will be only loading once per user entry the script, rather X times (one for each page that extends the Layout component the user visit)
You may also find useful this GitHub gist about polyfill IE 10-11 in Gatsby.
I am using NodeJS/React/Express/winston in conjunction. Here are the versions:
react & react-router-dom: 15.6.1
express: 4.15.3
node: 8.4.0
npm: 5.3.0
winston: 2.3.1
express-winston: 2.4.0
I instantiate my logger as such:
var logger = new (winston.Logger) ({
transports: [
new(winston.transports.File) ({
filename: 'log.txt',
handleExceptions: true,
prettyPrint: true
})
], exitOnError: false
});
I have created log.txt so the directory and file both exist.
At this point, I can go to my server and everything renders successfully as before.
If I add any calls to my logger, such as:
logger.info("Hello World!");
my application no longer renders, however I do not see any errors in the Console.
I have tried this as well with express-winston to log middleware requests which has the same outcome: logging works in the console for express-winson, but not when I want to write to an external file.
I just cannot seem to locate the source of this problem, it has absolutely baffled me. Please let me know if you see any red flags or have suggestions for how to debug this problem. Thank you very much for your time and help!
****** UPDATE ******
I have found that if I use:
try {
logger.info("hello");
}
catch(e) { alert(e); }
I get this message:
TypeError: fs.stat is not a function
I cannot find anything online that can fix this. Please advise
Is there a way to setup Flow to run with WebPack 2 watch. So that Flow would run a 'flow status' command on each WebPack successful build ?
Currently I tried:
webpack-shell-plugin.
It allows me to run shell commands before and after WebPacks build. But once a flow finds an error, it terminates the watch process.
code:
...
plugins: [
new WebpackShellPlugin({
onBuildEnd:['npm run --silent flow']
})
]
flow-status-webpack-plugin
For me it does not work. It doesn't produce nothing inside the console.
flow-babel-webpack-plugin
While this plugin did work, sadly on each build it restarts the flow server, making the flow type chasing extremely long. Also because of the server restart native flow support form Visual Studio Code and InteliJ stops working.
I solved this issue using
'flow-status-webpack-plugin'
the webpack.config looks like this:
var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin');
{
...
plugins: [
new FlowStatusWebpackPlugin({
onError: function(stdout) {
console.log(stdout)
},
onSuccess: function(stdout){
console.log(stdout)
},
restartFlow: false,
failOnError: true,
binaryPath: './node_modules/.bin/flow'
})
]
}
Every protractor example I can find on the internet seems to use browser.get with a web URI.
browser.get('http://localhost:8000');
I'd like to use Selenium to simple navigate to a file:// path so that I don't need a local web server running in order to perform tests. All I need is a simple HTML page and some assets.
That doesn't seem to work though.
browser.get('file:///Users/myusername/dev/mpproject/spec/support/index.html');
When I paste that URI into my browser window I get a HTML page. When I try to open it with protractor I get a timeout.
How can I run tests on this page with protractor? The ideal answer will work with a relative file path from the myproject root.
I am posting the solution I've found in here which helped me run Protractor with a file protocol.
By default, Protractor use data:text/html,<html></html> as resetUrl, but location.replace from the data: to the file: protocol is not allowed (we'll get "not allowed local resource" error), so we replace resetUrl with one with the file: protocol:
exports.config = {
// ...
baseUrl: 'file:///absolute/path/to/your/project/index.html',
onPrepare: function() {
// By default, Protractor use data:text/html,<html></html> as resetUrl, but
// location.replace from the data: to the file: protocol is not allowed
// (we'll get ‘not allowed local resource’ error), so we replace resetUrl with one
// with the file: protocol (this particular one will open system's root folder)
browser.resetUrl = 'file://';
}
// ...
};
If you want to run a relative path to your project folder, then you could just use Node.js tools, because Protractor runs in a Node.js environment. For example, __dirname will return an absolute path to a directory where your Protractor config file is saved. As a result use:
exports.config = {
// ...
baseUrl: 'file://' + __dirname + '/spec/support/index.html'
// ...
};
Also, if you application does XHR requests to some endpoints, which are not allowed from file:, you may have to run your test browser with custom flags. In my case it was Chrome:
exports.config = {
// ...
capabilities: {
browserName: 'chrome',
chromeOptions: {
// --allow-file-access-from-files - allow XHR from file://
args: ['allow-file-access-from-files']
}
}
// ...
}
I had the same error and fixed by applying Michael Radionov's fix but removing the baseUrl. Here is my setup:
protractor.config.js:
exports.config = {
capabilities: {
browserName: 'chrome'
},
specs: [
'*.js'
],
onPrepare: function() {
// By default, Protractor use data:text/html,<html></html> as resetUrl, but
// location.replace from the data: to the file: protocol is not allowed
// (we'll get ‘not allowed local resource’ error), so we replace resetUrl with one
// with the file: protocol (this particular one will open system's root folder)
browser.ignoreSynchronization = true;
browser.waitForAngular();
browser.sleep(500);
browser.resetUrl = 'file:///';
}
};
e2etest.js:
'use strict';
describe("Buttons' tests are started", function() {
it('Should retrieve 20 records into table', function() {
browser.get('file:///C:/Users/path_to_file/index.html');
/* Test codes here */
});
});
What is the error log?
This could be something related to 'Loading' angular. For that you can try
browser.driver.ignoreSynchronization = true;
The error log will surely help in trying to understand the problem.
I think there is typo mistake. In "get" method you should include the URL in double quotes "".
Try using double quotes like below:
WebDriver driver=new FirefoxDriver();
driver.get('file:///E:/Programming%20Samples/HTML%20Samples/First%20Program.html');