1. 介绍
Nightwatch.js 是基于 Node.js 和 WebDriver 的 E2E 测试框架,以下是三段是官方给出的定义:
Nightwatch.js is an easy to use Node.js based End-to-End (E2E) testing solution for browser based apps and websites. It uses the powerful W3C WebDriver API to perform commands and assertions on DOM elements.
Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js and using the W3C WebDriver API (formerly Selenium WebDriver).
Nightwatch.js is a complete browser (End-to-End) testing solution which aims to simplify the process of setting up Continuous Integration and writing automated tests. Nightwatch can also be used for writing Node.js unit tests.
Keywords
2. 特点
- Clean syntax - 简洁的语法
- Built-in test runner - 自带测试环境
- Selenium server - 测试用的服务器,需要JRE
- Cloud services support - 支持云服务
- CSS & Xpath support - 支持CSS和XPATH选择器
- Continous integration support - 支持持续集成
- Easy to extend - 易于扩展
特点一般都是比较抽象的,不理解也没关系,我们可以从实践中慢慢体会。
3. Demo
我们来看下面的Demo找找感觉。看过之后,以前有写过测试的,应该会觉得很熟悉;没写过的,应该也能从方法名中推测出方法大体的作用。
module.exports = {
'Demo test Google' : function (client) {
client
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.assert.title('Google')
.assert.visible('input[type=text]')
.setValue('input[type=text]', 'rembrandt van rijn')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('ol#rso li:first-child',
'Rembrandt - Wikipedia')
.end();
}
};
在控制台执行命令后,会输出类似下面的结果
demo
4. Next
知道了 Nightwatch 的作用,下面我们去亲手搭建一个Nightwatch的Demo。
网友评论