Casperjs doesn't work in windows 10 - node.js

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!

Related

child_process in Node js Google App Engine

I have a Node Express server that works on localhost. It uses child_process to run a C++ standalone executable.
The code that uses child_process is the following (the application creates output.txt):
app.post('/generate', async function(req, res)
{
var input1 = req.body.input1;
var input2 = req.body.input2;
var execFile = require('child_process').execFile;
var program = "path/to/executable";
var args = [input1, input2];
var child = execFile(program, args,
function (error, stdout, stderr){
console.log(error);
console.log(stdout);
console.log(stderr);
const file = __dirname + "/output.txt"
app.get('/output.txt', function (req, res) {
res.sendFile(path.join(__dirname + '/output.txt'));
});
res.send("/output.txt");
})
})
This works locally.
I'm now trying to deploy it on Google Cloud Platform with App Engine.
However, when I go the website that I host, and launch this POST /generate request, I don't get the expected output. In the Google Cloud Platform logs of my project I can see the following error:
textPayload: "{ Error: spawn cpp/web_cpp_app/x64/Debug/web_cpp_app ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
"
At first I didn't understand the error, but now I can see that if I locally run the same project, but set the path of the standalone executable to an invalid path, I get the same error. I'm guessing that when I deploy, my executable is somehow not included?
Is there something specific I need to add in package.json or app.yaml files, to include the executable?
EDIT:
Could it be that the app engine runs on Linux, and my executable is for Windows?
ENOENT means "no such file or directory", so your path could be wrong, or the container doesn't recognize the program as executable.
But either way, you will need to build and include a linux-compatible binary of your child_process program in your project directory when you deploy. You could build this manually, or use something like Cloud Build to compile it in a container that's identical to that of App Engine.
You are right about the OS, per this Doc Appengine standard for NodeJS uses Ubuntu OS, and flexible uses Debian
About the executable compatibility I found this post

Appium - webdriverio init is not a function

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

phantomjs cannot find module webpage in node's child process

I'm trying to run phantomjs in a node child process. Phantomjs complains it can not find module 'webpage'. Running the script from the cli works fine:
phantomjs script.js
I stripped the problem down to these two files:
main.js:
var script = require('./script');
var cp = require('child_process');
cp.exec('/usr/bin/phantomjs script.js');
script.js
var page = require('webpage').create();
page.open("http://www.google.com", function(status) {
console.log("opened google? ", status);
var title = page.evaluate(function(s) {
return s;
}, 'Hello');
console.log(title);
phantom.exit();
});
Running the following command fails:
node main.js
with error:
module.js:340
throw err;
^
Error: Cannot find module 'webpage'
I've tried to specify the working directory in cp.exec as an option without effect. Is there a way to set the node search path for modules in a global context so it can be found in a new node process? Or am I doing something else wrongly?
PhantomJS is not a node.js module and cannot be directly used from node. I think you understand this, because you try to invoke it via child_process.
The problem is the line var script = require('./script');. As I understand, it is the phantomjs script. Since node.js doesn't have a webpage module, but phantomjs does the require fails and everything with it. Simply remove the line. It doesn't seem like you use it anyway.

Running 'casperjs test' in phantom

So I have a file running in node which runs a local copy of PhantomJS as below shows:
phantom.casperPath = 'node_modules/casperjs';
phantom.injectJs('node_modules/casperjs/bin/bootstrap.js');
var casper = require('casper').create({
viewportSize: config.viewportSize
});
casper.test.begin('Runing tests here', 5, function suite(test) {
// Tests here
});
Without the casper.test.begin() my tests function fine. I have the correct version 1.1.0 which can use this test suite but I get the following error in my console:
CasperError: casper.test property is only available using the `casperjs test` command
The CasperJS docs mentions this too: http://docs.casperjs.org/en/latest/testing.html. My question is how do I run this Casper under this command in the above code so I can use these tests?
Thanks!
CasperError: casper.test property is only available using the casperjs test command
problem solved.
You have to include this line at the top of your script in your xyz.js, so that the .test property becomes true;
phantom.casperTest = true;
Then you should have no problem Launching from the terminal:
casperjs xyz.js
you can also call casperjs test xyz.js
For more info, check the doco here : http://docs.casperjs.org/en/latest/testing.html

Cannot find module 'connect' on Mac OS X Lion

I installed connect module using NPM running the following command:
npm install connect
it created the module in /Download/usr/node_modules/connect folder. I created a file which
uses connect module using
var connect = require('connect');
var util = require('util');
function sendjson(res,obj)
{
res.writeHead(200,{'Content-Type':'application/json',});
var objstr = JSON.stringify(obj);
util.debug('SENDJSON' + objstr);
res.end(objstr);
}
var server = connect.createServer(
connect.router(function(app){
app.get('/foo', function(req,res){
sendjson(res,{path:'foo'});
})
app.get('/bar', function(req,res){
sendjson(res,{path:'bar'});
})
})
);
server.listen(3000);
I run node createServer.js and it throws in the terminal and it gives me the following error.
Cannot find module 'connect'
NPM modules by default need to be installed locally in the folder that contains the source file that uses them. So if your source file is in /Desktop/nodescripts, you should run "npm install connect" in that same folder. That will create node_modules folder in that path, and your script will be able to find it.

Resources