AVA + Spectron + JavaScript 对 JS 编写的客户端进行自动化测试
什么是 AVA (类似于 unittest)
AVA 是一种 JavaScript 单元测试框架,是一个简约的测试库。AVA 它的优势是 JavaScript 的异步特性和并发运行测试, 这反过来提高了性能。
什么是 Spectron
Spectron 是一个 node.js 框架,用于自动化应用程序 Electron。
AVA + Spectron + JavaScript
AVA + Spectron + JavaScript 对 JavaScript 的客户端进行自动化集成测试。
AVA 常用的 api
- test([title], implementation) 基本测试
- test.serial([title], implementation) 串行运行测试
- test.cb([title], implementation) 回调函数形式
- test.only([title], implementation) 运行指定的测试
- test.skip([title], implementation) 跳过测试
- test.todo(title) 备忘测试
- test.failing([title], implementation) 失败的测试
- test.before([title], implementation) 钩子函数,这个会在所有测试前运行
- test.after([title], implementation) 钩子函数,这个会在所有测试之后运行
- test.beforeEach([title], implementation) 钩子函数,这个会在每个测试之前运行
- test.afterEach([title], implementation) 钩子函数,这个会在每个测试之后运行
- test.after.always([title], implementation) 钩子函数,这个会在所有测试之后运行,不管之前的测试是否失败
- test.afterEach.always([title], implementation) 钩子函数,这个会在每个测试之后运行,不管之前的测试是否失败
AVA 内置断言
- .pass([message]) 测试通过
- .fail([message]) 断言失败
- .truthy(value, [message]) 断言 value 是否是真值
- .falsy(value, [message]) 断言 value 是否是假值
- .true(value, [message]) 断言 value 是否是 true
- .false(value, [message]) 断言 value 是否是 false
- .is(value, expected, [message]) 断言 value 是否和 expected 相等
- .not(value, expected, [message]) 断言 value 是否和 expected 不等
- .deepEqual(value, expected, [message]) 断言 value 是否和 expected 深度相等
- .notDeepEqual(value, expected, [message]) 断言 value 是否和 expected 深度不等
- .throws(function|promise, [error, [message]]) 断言 function 抛出一个异常,或者 promise reject 一个错误
- .notThrows(function|promise, [message]) 断言 function 没有抛出一个异常,或者 promise resolve
- .regex(contents, regex, [message]) 断言 contents 匹配 regex
- .notRegex(contents, regex, [message]) 断言 contents 不匹配 regex
- .ifError(error, [message]) 断言 error 是假值
- .snapshot(expected, [message]) 将预期值与先前记录的快照进行比较
- .snapshot(expected, [options], [message]) 将预期值与先前记录的快照进行比较
如下是 creat_furure.ts 测试脚本。
import test from 'ava';
import { cycle, config, util, RQPro } from '../../helpers';
test.beforeEach(async t => {
t.context.account = config.loadAccount();
t.context.selector = config.loadSelector();
t.context.app = await cycle.start();
t.context.client = t.context.app.client;
await cycle.login(t.context.client, t.context.account.auto);
t.context.rqpro = new RQPro(t.context.app);
});
test.afterEach(async t => {
await util.wait(500);
await cycle.stop(t.context.app);
});
test('should support create future algorithm and build , async t => {
const { client, selector } = t.context;
await client.waitForExist(selector.olAlgorithms.container);
await client.click(selector.olAlgorithms.createBtn);
await client.waitForExist(selector.olAlgorithms.createDialog);
await util.wait(500);
await client.setValue(selector.olAlgorithms.createFormTitleInput, `guard-${Date.now()}`);
await client.click(selector.olAlgorithms.createsFormStockCheckbox);
const title = await client.getTitle();
if (title.indexOf('模拟') !== -1) {
t.pass();
}
});
脚本中的 waitForExist 、 click 、setValue 等对元素的操作的方法来自于 WebdriverIo, 元素定位方法为 css selecotor,元素定位存放在配置文件 selector.yml 里。
实际项目结构如下:

参考资料:
https://github.com/avajs/ava#faq
https://juejin.im/entry/597e88035188257f833d3bb8
http://webdriver.io/api.html
AVA + Spectron + JavaScript 对 JS 编写的客户端进行自动化测试的更多相关文章
- 前端之JavaScript:JS简单介绍
JavaScript(JS)之简单介绍 一.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名Scr ...
- 为Node.js编写组件的几种方式
本文主要备忘为Node.js编写组件的三种实现:纯js实现.v8 API实现(同步&异步).借助swig框架实现. 关键字:Node.js.C++.v8.swig.异步.回调. 简介 首先介绍 ...
- Breach - HTML5 时代,基于 JS 编写的浏览器
Breach 是一款属于 HTML5 时代的开源浏览器项目,,完全用 Javascript 编写的.免费.模块化.易于扩展.这个浏览器中的一切都是模块,Web 应用程序在其自己的进程运行.通过选择合适 ...
- js编写验证码
这是一个简单的js编写的验证码,自己已经亲自验证,没有问题了 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...
- Node.js编写CLI的实践
导语:通常而言,Node.js的应用场景有前后端分离.海量web页面渲染服务.命令行工具和桌面端应用等等.本篇文章选取CLI(Command Line Tools)这子领域,来谈谈Node.js编写C ...
- 怎么用js编写1——100的质数?
这里来自csdn问答的一个问题,怎么用js编写1——100的质数? http://ask.csdn.net/questions/214429 质数也就是素数,即只能被1和自身整除的数,因此可以构造循环 ...
- JavaScript中利用Ajax 实现客户端与服务器端通信(九)
一:Ajax (Asynchronous JavaScript and XML)不是一个新的技术,事实上,它是一些旧有的成熟的技术以一种全新的更加强大的方式整合在一起 Ajax的关键技术: 1.使用X ...
- js编写轮播图,广告弹框
1.轮播图 js编写轮播图,需要用到setInterval(计时器):先给一个div,里面放轮播图的图片,将轮播图的图片明明为相同样式的:如:banner1.jpg,banner2.jpg,banne ...
- Node.js 使用http客户端向网站请求数据并保存
app.js代码: // 内置http模块,提供了http服务器和客户端功能 var http=require("http"); // 内置文件处理模块 var fs=requir ...
随机推荐
- How do I prevent Eclipse from hanging on startup?
Under Eclipse 3.6 (Helios), the corresponding file seems to be .metadata/.plugins/org.eclipse.core.r ...
- JSF - Access Managed-Bean in a servlet
When you have to access your Managed Bean in a servlet, it depends on the scope you set for the Bean ...
- vs读取ini文件
读取string类型: DWORD GetPrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpDefaut,LPSTR ...
- [AlgorithmStaff] Bresenham快速直线算法
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Unity2017.3 | NativeC 最近在学习 Unity tilemap Brush 自定义笔刷功能时候,看到其 ...
- 插件 uploadify
一.属性 属性名称 默认值 说明 auto true 设置为true当选择文件后就直接上传了,为false需要点击上传按钮才上传 . buttonClass ” 按钮样式 buttonCursor ‘ ...
- Visual Studio 2010 常用快捷方式
调试快捷键 F6: 生成解决方案 Ctrl+F6: 生成当前项目 F7: 查看代码 Shift+F7: 查看窗体设计器 F5: 启动调 ...
- Java NIO API详解(转)
原文连接: http://www.blogjava.net/19851985lili/articles/93524.html 感谢原作者 NIO API 主要集中在 java.nio 和它的 subp ...
- WEB开发常见错误-php无法操作数据库
Ubuntu 安装phpmyadmin 和配置 ubuntu 安装 phpmyadmin 两种 : 1: apt-get 安装 然后使用 已有的虚拟主机目录建立软连接 sudo apt-g ...
- KbmMW 4.40.00 正式版发布
经过快3个月的测试,kbmmw 4.40 正式版终于在圣诞节前发布了. We are happy to announce the availability of a new kbmMW release ...
- 密码分析:使用 Ettercap 和 它的 ARP 毒化功能来嗅探流量
vim /etc/etterconf 将 ec_uid 和 ec_gid 改为 0 需要取消下面的 IPTABLES 行的注释.它在靠近文件末尾的 LINUX 一节 ettercap -G Shift ...