自己写的第一个CasperJS
2017-01-30 11:36
225 查看
/** * Created by jane on 2017/1/2. */ Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }; var casper = require('casper').create({ waitTimeout : 20000, verbose: true, logLevel: 'debug', pageSettings: { loadImages: true, loadPlugins: true, userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53', }, viewportSize: { width: 0, height: 0 } }); casper.start(); casper.thenOpen('http://www.baidu.com', function () { this.waitForSelector("#index-bn", function success() { this.capture("screenshot/1 baidu " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {top: 0, left: 0, width: 0, height: 0}); this.fill("form", { "word": "哈哈" }, false); this.then(function () { casper.wait(5000, function () { this.echo('should appear after 5s'); this.click("#index-bn"); }); }); }, function fail() { this.capture("screenshot/error baidu " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {top: 0, left: 0, width: 0, height: 0}); }); this.waitFor(function check() { return true; }, function then() { this.capture("screenshot/2 baidu " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {top: 0, left: 0, width: 0, height: 0}); }) }, null, 5000); casper.run();
相关文章推荐
- 在Maven Central发布了自己的第一个开源项目
- 『Asp.Net 组件』第一个 Asp.Net 服务器组件:自己的文本框控件
- 写出自己人生的第一个小程序
- AR--未来技术提前探索<2>[自己做的第一个AR]
- 下面就是开始自己制作第一个模块
- 学习MVC3(二)——创建自己的第一个网页:实现用户登陆(2)
- 自己动手的第一个 Hibernate后台代码
- 自己写的第一个练习网页【2017.7.12】
- 终于写成自己的第一个线性汇编小程序
- 记自己的第一个完整的java web项目
- 发布自己的module - 我的第一个npm组件!
- struts2学习笔记之一、eclipse搭建自己的第一个web工程
- 自己复制粘贴出来的第一个java小程序
- 编写和提交自己的第一个内核patch
- 第一个自己写的python程序:windows下备份文件
- 用记事本开始写自己的第一个WebService
- JavaScript-创建第一个自己的类库
- 第一个自己独立开发并发布的软件
- java 多线程实例,自己写的第一个例子,理解什么是多线程,怎么写多线程
- 使用openface训练自己的第一个模型