I already installed phantomjs globally npm install -g phantomjs
Started selenium with java -jar selenium-standalone-2.52.0.jar
Configure the World object for cucumberjs properly like this:
var options = {
//desiredCapabilities: { browserName: 'internet explorer' }, // WORK
//desiredCapabilities: { browserName: 'chrome' }, // WORK
desiredCapabilities: { browserName: 'phantomjs' }, // NOT WORK
waitforTimeout : 2000,
host: '127.0.0.1',
port: 4444
};
this.browser = webdriverio.remote(options);
It worked with chrome & IE, but failed for phantomjs.
This is the error I got from Selenium console:
ERROR - org.apache.commons.exec.ExecuteException: Execution failed
(Exit value: -559038737. Caused by java.io.IOException: Cannot run
program "C:\Program Files (x86)\nodejs\phantomjs" (in directory "."):
CreateProcess error=193, %1 is not a valid Win32 application)
C:\Program Files (x86)\nodejs\phantomjs exists.
Do I miss any configuration for phantom / selenium?
Well, finally I found the reason in this similar github issue.
C:\Program Files (x86)\nodejs\phantomjs only works for Linux system. Looks like the webdriver for phantomjs didn't check for the case of running on window application.
To quick-fix the problem, I remove the file C:\Program Files (x86)\nodejs\phantomjs, so selenium will automatically call phantomjs.bat on the same folder. Everything will work fine.
Related
I'm trying to setup a brand new angular 9 application local development environment for a SPA SharePoint Online application.
As part of the process I need to setup the local proxy server sp-rest-proxy. I configured it to use on demand credentials. This is the config/private.json content:
{
"siteUrl": "https://tenant.sharepoint.com/sites/mysite",
"strategy": "OnDemandCredentials",
"ondemand": true
}
My package.json file includes:
{
"scripts": {
"serve": "node src/server.js"
}
}
server.js content is:
const RestProxy = require('sp-rest-proxy');
const settings = {
configPath: './config/private.json', // Location for SharePoint instance mapping and credentials
port: 8080, // Local server port
staticRoot: './node_modules/sp-rest-proxy/static' // Root folder for static content
};
const restProxy = new RestProxy(settings);
restProxy.serve();
I run:
npm run serve
Open browser and point it to http://localhost:8080 when I try to execute a simple request like /_api/web?$select=Title I get the following error:
{
"readyState": 4,
"responseText": "Command failed: C:\\WINDOWS\\system32\\cmd.exe /d /s /c \"electron C:\\projects\\MyProject\\node_modules\\node-sp-auth\\lib\\src\\auth\\resolvers\\ondemand\\electron\\main.js https://tenant.sharepoint.com/sites/diner false\"",
"status": 400,
"statusText": "Bad Request"
}
No browser window is shown.
I have electron installed globally.
When I execute the following on the command line:
electron C:\projects\MyProject\node_modules\node-sp-auth\lib\src\auth\resolvers\ondemand\electron\main.js https://tenant.sharepoint.com false
Nothing happens, the process ends with no messages, no browser window is opened.
What can I do to find and fix the problem?
On-Demand auth requires Electron being installed npm i -g electron#6.
Electron is optional in node-sp-auth, as it's huge it was an architectural decision making it optional and for manual install only for that rare cases when On-Demand is needed.
The issue is solved after upgrading sp-rest-proxy to version 2.11.1.
See this issue on GitHub
I have some code that was generated by Appium Recorder. When I try to run node test.js it says "driver.init is not a function"
I ran npm install webdriverio in the same directory and I have the node_modules directory there.
Here is the contents of test.js:
// Requires the webdriverio client library
// (npm install webdriverio)
// Then paste this into a .js file and run with Node:
// node <file>.js
const wdio = require('webdriverio');
const caps = {"platformName":"android","platformVersion":"6.0.1","deviceName":"Nexus","automationName":"Appium","browserName":"Chrome"};
const driver = wdio.remote({
protocol: "http",
host: "localhost",
port: 4723,
path: "/wd/hub",
desiredCapabilities: caps
});
driver.init()
.element("com.android.chrome:id/url_bar")
.setValue("https://www.google.com/")
.end();
I expect the code to run, but it says TypeError: driver.init is not a function
it seems to depend on the version of webdriverio you are using. I got the same issue when working with the latest version, but with "webdriverio": "^4.6.1", it works. If you go on the Getting Started section, you'll see the new way to use the module : https://webdriver.io/docs/gettingstarted.html
Hope it helps
I installed nodejs, python, phantomjs, casperjs.
But when I test with test script file as below.
Path added to Environmental variables.
Also version can be showed at any directory.
Image Attached: Error Output
C:\Users>phantomjs --version
2.1.1
C:\Users>casperjs --version
1.1.4
C:\Users>cd jbm
C:\Users\JBM>cd Desktop
C:\Users\JBM\Desktop>casperjs.bat slmjstest.js
'casperjs.bat' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\JBM\Desktop>casperjs slmjstest.js
CasperError: Can't find module capser
phantomjs://code/bootstrap.js:307 in patchedRequire
var casper = require('capser').create({verbose: true,
logLevel: "debug"});
casper.start('http://casperjs.org/', function() {
this.echo(this.getTitle());
});
casper.thenOpen('http://phantomjs.org', function() {
this.echo(this.getTitle());
});
casper.run();
You have misspelled module name in your require.
var casper = require('capser')
var casper = require('casper').create({verbose: true,
logLevel: "debug"});
Also call the script with just casperjs script.js
Hope that helps!
I have been trying to follow a tutorial given HERE. However, when I try to start the protractor test given, no tests seem to run at all. My webdriver-manager seems to run perfectly however. Basically nothing happens.
I have tried the following:
node protractor conf.js
node node_modules/protractor conf.js
node node_modules/protractor node_modules/protractor/conf.js
node node_modules/protractor node_modules/protractor/tests/conf.js
None of these work, and the first one throws an error. I've tried putting copies of the files in multiple directories, but none of those seem to work either. I'm no exactly sure what the issue is, but this is how much files are setup.
ui_directory/ <-- This is the overall directory for my web projects
ui_directory/conf.js
ui_directory/todo-spec.js
ui_directory/node_modules/
ui_directory/node_modules/protractor/
ui_directory/node_modules/protractor/conf.js
ui_directory/node_modules/protractor/todo-spec.js
ui_directory/node_modules.protractor/tests/
ui_directory/node_modules.protractor/tests/conf.js
ui_directory/node_modules.protractor/tests/todo-spec.js
What exactly is the proper command to run the tests from the tutorial? All todo-spec.js and conf.js files are the same.
My conf.js file contains the following:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};
Please follow the below steps to run basic protractor Test.
Create a Folder, Say example in Desktop (Folder name is protractor)
Create a config and Spec file with .js extension
Make sure both the files are in Same Location / Folder
Open Command Prompt, And Navigate to project Folder (protractor)
Once navigated to project folder, Type as in bracket:
[protractor config.js] // This will execute protractor Test
Example of Basic Protractor Config File is given as
exports.config = {
//The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
//Here we specify the name of the specs files.
framework: 'jasmine',
specs: ['Protractor_spec.js'],
jasmineNodeOpts: {
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 1440000
},
}
I am trying to run my portractor tests on live-server via one grunt task.
I have installed live-server (https://www.npmjs.com/package/live-server) and grunt-execute. With grunt execute I managed to start live-server with a grunt command in 2 steps:
1st I created a node script (liveServer.js)
var liveServer = require("live-server");
var params = {
port: 8080,
host: "localhost",
open: true,
wait: 1000
};
liveServer.start(params);
2nd I created a task in my grunt file to start the script:
(in grunt.initConfig)
execute: {
liveserver: {
src: ['liveServer.js']
},
}
and registered a command to trigger it:
grunt.registerTask('live', [
'execute:liveserver'
]);
Now if I run "grunt live" in my commandline live-server starts, opens a browser, and I can browse my application.
I also created a protractor task in my grunt file, which works just fine as well.
(in grunt.initConfig)
protractor: {
options: {
keepAlive: false,
noColor: false
},
e2e: {
options: {
configFile: 'protractor.conf.js',
}
}
},
If I trigger it with a registered task the protractor tests run just fine, only I have to make sure live-server is running first.
So ofcourse I want to combine the two in one command that starts live-server and then runs my protractor tests.
So I tried:
grunt.registerTask('runProtractor', [
'execute:liveserver',
'protractor'
]);
But unfortunately this does not work, live-server starts and then ... nothing happens, the protractor tests aren't run. I tried changing some of the live-server parameters such as open and wait, but without any luck. There are no error messages either.
As I said before separately the tasks work both fine (with two command windows, first start live-server in one and then protractor in the other)
Does anybody have a clue why my does not continue after the live-server has started?
The execution of live-server blocks all subsequent tasks, since it doesn't "finish", i.e. to grunt the task is still running, which is why it won't proceed to the next task. You can use grunt-concurrent to run tasks in parallel.