casperjs

How to pass data from the “then” methods in CasperJS?

懵懂的女人 提交于 2019-12-04 06:22:09
It's common to have multiple then methods when working with CasperJS. The following is an example: casper.then(function(){ var a = "test"; // ... }) casper.then(function(){ // how to use the variable a in the first "then" }) My question is, what's the common way to pass values from former then s to following then s? For the aforementioned example, how to use a in the second then ? There are many way, but the easiest would be to use global variables. If you don't want to clutter your scripts with global variables (which should not be of the same concern as global variables in the browser,

Phantom.js / Casper.js with rotating proxy?

邮差的信 提交于 2019-12-04 06:19:15
I have a simple goal: load webpages with either phantom.js (out of the box) or casper.js (nice and easier) but using proxy and rotate it from a list if current one is bad (i.e. webpage loads fail or something like that). I know casper.js has --proxy param but it dictates the user to specify only ONE proxy and use it during runtime. Question #1 is: how to rotate proxy on the fly programmatically? I did some research and found this node-requester but it's not integrated with casper.js . I tried to extract out just the proxy feature in the code but didn't really understand how it works in the

CasperJs + jenkins : when a test fails, how to retrieve all information on this test

爷,独闯天下 提交于 2019-12-04 05:17:21
Well , I would like to know how to get back the information of a test failed in jenkins. Here the result of my folder (fr) (it displays 22 min. but in parallel it's 3min) : Here the description of the test failed -jenkins- : Here the description of the test failed -casper- : So my problem is jenkins displays only the message of the test failed, and I would like to have also useful information as line and code (in fact there is the console output but it's not convenient-> I've changed my mine, it is, see xUnit with Jenkins: how to display colors in the Build Console Output? , but I still want

Run/Execute CasperJS script by clicking a button on webpage

两盒软妹~` 提交于 2019-12-04 01:52:49
问题 I have a casperJS script which returns a JSON when run on commandline. I want to have an arrangement such that 1) I create a webpage 2) On clicking a button on the webpage the casperJS scripts gets executed at the server side and post/return the result back to the webpage. How can i do the same. EDIT: I am invoking an AJAX process written in php on clicking the buttom. The php script contains echo exec('casperjs sample.js'); It returned nothing but on checking the webserver error log I got

CasperJs, how to repeat a step X times onWaitTimeout?

99封情书 提交于 2019-12-03 23:05:32
问题 So what I want to do is create a casperJS function which allows us to repeat a step X times, by refreshing the page first, when this step function reaches the timeout. For unreliable test due to a specific page bug/freeze at the moment and reduce the percentage of false negative. I have just a problem, I don't know how to break this loop, because I'm in IIFE scope, see following code : var echoTest = function(){ casper.echo('Hi'); }; var trueFunction = function(){ return true; }; var

Message does not appear when called from evaluate method

孤者浪人 提交于 2019-12-03 22:55:41
问题 I'm new to casperjs and playing around with it, but I can't get its evaluate() functionality to work. This is my example var casper = require('casper').create(); casper.echo('started...'); casper.start('http://www.google.de/'); casper.then(function() { this.echo(this.getTitle()); }); casper.then(function() { this.evaluate(function() { this.echo('test'); }); }); casper.run(); I'm executing it with casperjs sample.js After started... and Google nothing happens in console output. The closure

Login amazon using CasperJS with handling Captcha

岁酱吖の 提交于 2019-12-03 20:28:10
问题 I am using PhantomJs and CasperJs to login with amazon it works fine, however after multiple times login amazon gives Captcha and my script fails. I dont know how to handle login script if it has captcha. Here is my current code which works fine if no captcha. var casper = require('casper').create(); var AMAZON_USER = 'amazon-username'; var AMAZON_PASS = 'amazone-password'; casper.start('https://www.amazon.com/gp/wallet', function () { this.echo('Loggin into amazon...'); var emailInput =

How to for loop in casperjs

微笑、不失礼 提交于 2019-12-03 16:57:58
I am trying to click a 'next' button N number of times and grab the page source each time. I understand that I can run an arbitrary function on the remote website, so instead of click() I just use the remote function nextPage() How do I run the following, an arbitrary number of times: var casper = require('casper').create(); casper.start('http://www.example.com', function() { this.echo(this.getHTML()); this.echo('-------------------------'); var numTimes = 4, count = 2; casper.repeat(numTimes, function() { this.thenEvaluate(function() { nextPage(++count); }); this.then(function() { this.echo

Does CasperJs then() wait on emitted events in the previous function?

白昼怎懂夜的黑 提交于 2019-12-03 15:06:41
I am just curious how CasperJS handles events with regards to the call stack. Let's say we have some code: casper.on('foo', function() { this.wait(60000); this.echo('foo'); }); casper.start('http://www.stackoverflow.com', function() { this.echo('start'); this.emit('foo'); }); casper.then(function() { this.echo('done'); }); casper.run(); I know that then() will wait check against 3 flags : pendingWait, loadInProgress, and navigationRequested. Printing out the call stack shows the emit call to be in the function start(), so will start() not be considered finished until the event is finished? I.e

setInterval and this.wait in casper.js

邮差的信 提交于 2019-12-03 13:40:54
问题 I need to make a loop of 3 times and 2 seconds in between each iteration . I tried these 3 options: Option 1 var casper = require('casper').create({ verbose: false, logLevel: 'debug' }); casper.start("http://google.com"); casper.on('remote.message', function(msg) { this.echo('remote message caught: ' + msg); }) casper.thenEvaluate(function() { var x = 0; var intervalID = setInterval(function () { console.log("Using setInternal " + x); if (++x === 3) { window.clearInterval(intervalID); } },