casperjs

testing DOM elements with phantomjs/casperjs

老子叫甜甜 提交于 2020-01-13 17:26:40
问题 I've got an AJAX-based javascript application which I would like to cover with interface tests. For example, I would like to write a test that loads my website (from a given URL) and checks if there are some DOM elements (given ids and given classes) that exist. The problem is that when I enter the URL in a browser, my application has a Loading... label displayed and an AJAX request is sent beneath. When AJAX response arrives, some processing is done and the right webpage content is displayed

Saving table data obtained while scraping a webpage using casperjs [closed]

做~自己de王妃 提交于 2020-01-12 04:00:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Which would be the best method to save table data obtained while scraping a webpage using casperjs? Using a json object and store it as a file after serializing. Using ajax request to php then storing it in a mysql db. 回答1: For simplicity sake, view CasperJS as a way to

File IO inside CasperJS

柔情痞子 提交于 2020-01-11 15:47:09
问题 Is it possible do read/write files inside a CasperJS Script ? var fs = require('fs'); var data = fs.readFileSync('testdata.data', 'utf-8'); console.log(data); Calling casperjs fileio.js returns: 'undefined' is not a function Even after running npm install fs . Bonus point if not : explain why ? 回答1: CasperJS does not make use of NodeJS' fs module. Instead, it uses that of PhantomJS Here's a short example of how to use PhantomJS' filesystem module: var fs = require('fs'); var utils = require(

How to download a file through a custom POST request with CasperJS

无人久伴 提交于 2020-01-11 11:42:36
问题 I am writing a crawler and needs to download file generated after a form request using POST. I have successfully used this.download(url,'POST',Params) for regular forms. One of the sites has many fields using the same name, thus preventing me from using the regular download method. After trying a lot of things, I tried with $.ajax() and __utils.sendAJAX() to process the form like this: response = this.evaluate(function(){ url=... params = $('form#theirForm').serialize(); data = __utils__

Clear localstorage with Casperjs

。_饼干妹妹 提交于 2020-01-11 06:49:07
问题 I'm using casperjs to do some testings of a backbonejs application using localstorage. My problem is that I can not clear the localstorage when testing with casperjs. I have been trying to use localStorage.clear(); at the beginning of my casper file but nothing is cleared. 回答1: I found workaround for this problem by deleting file *.localstorage in one of the following directories: Windows c:\Users\YOUR_USER\AppData\Local\Ofi Labs\PhantomJS\ Mac OS X: /Users/YOUR_USER/Library/Application

CasperJS: Simulate swipe-event

丶灬走出姿态 提交于 2020-01-06 21:51:06
问题 I tried to build a few casperjs tests. Went well so far but at one thing I failed: Building a test for a swipe-event. I need something like this: casper.mouse.down("#myelement"); // press and hold mousebutton casper.mouse.move_x(200); // Move mouse 200 to the right casper.mouse.up(); // Release mousebutton But there is no function like move_x in the casper-docs. Does anyone have an idea? 回答1: You can easily write your own move_x method by getting the coordinates of the selector and using

How to get the binary of the image requested by CasperJS?

点点圈 提交于 2020-01-06 14:46:35
问题 Code: casper.on("resource.received", function (response) { if (response.url.indexOf('checkcode') != -1) { this.log('response: ' + JSON.stringify(response), 'debug'); } }) Output: [debug] [phantom] [2016-04-21T01:36:46.007Z] response: {"body":"","bodySize":1847,"contentType":"image/png","headers":[{"name":"Server","value":"Tengine/2.1.0"},{"name":"Date","value":"Thu, 21 Apr 2016 01:36:45 GMT"},{"name":"Content-Type","value":"image/png"},{"name":"Content-Length","value":"1847"},{"name":

Casperjs - trying to run casper script from command line doesn't output correctly

人盡茶涼 提交于 2020-01-06 08:16:19
问题 I'm brand new to casperjs, and in the process of trying to run my first casper script from the command line (using $ casperjs sample.js ), I received this output: Casper CLI passed args: [] Casper CLI passed options: { "casper-path": "/usr/local/Cellar/casperjs/1.1-beta2/libexec", "cli": true } Instead of the predicted output of: CasperJS, a navigation scripting and testing utility for PhantomJS PhantomJS: Headless WebKit with JavaScript API Here are the contents of the sample file: var

How to control a CasperJS automation script from a remote jquery client using socket.io

こ雲淡風輕ζ 提交于 2020-01-06 02:57:17
问题 I have an automation script in CasperJS controlling a PhantomJS headless browser that logs into a site, enters data over multiple pages / form. From the same physical server, I have PHP/MySQL serving up a CRM client website. On the CRM site, I want to have the ability to: Trigger the remote CasperJS script to go browse a remote site and log in and fill out forms Read the output stream (i.e. "Page 1 complete, page 2 complete" ,etc) Display the status updates to the client user as the CasperJS

CasperJS test doesn't return after execution

妖精的绣舞 提交于 2020-01-05 19:59:20
问题 I'm having a problem getting casperjs test to exit after execution, I have to hit CTL-C to exit execution. I'm on OSX 10.7 with casperjs 1.1 devel. To test this wasn't my code I simply copied this sample from the docs: var casper = require("casper").create(); function Cow() { this.mowed = false; this.moo = function moo() { this.mowed = true; // mootable state: don't do that at home return 'moo!'; }; } casper.test.begin('Cow can moo', 2, function suite(test) { var cow = new Cow(); test