扫一扫分享
Zombie.js 是一个node.js环境下,非常小巧高效率的Web UI Automation Test库.本文将介绍如何使用Zombie.js对Web UI进行自动化测试。Zombie.js是一个轻量级框架,用于在模拟环境中测试客户端JavaScript代码,无需浏览器。
例子
const Browser = require('zombie');
// We're going to make requests to http://example.com/signup
// Which will be routed to our test server localhost:3000
Browser.localhost('example.com', 3000);
describe('User visits signup page', function() {
const browser = new Browser();
before(function(done) {
browser.visit('/signup', done);
});
describe('submits form', function() {
before(function(done) {
browser
.fill('email', 'zombie@underworld.dead')
.fill('password', 'eat-the-living')
.pressButton('Sign Me Up!', done);
});
it('should be successful', function() {
browser.assert.success();
});
it('should see welcome page', function() {
browser.assert.text('title', 'Welcome To Brains Depot');
});
});
});
此示例使用Mocha测试框架,但Zombie将与其他测试框架一起使用。由于Mocha支持promises,我们也可以像这样编写测试:
const Browser = require('zombie');
// We're going to make requests to http://example.com/signup
// Which will be routed to our test server localhost:3000
Browser.localhost('example.com', 3000);
describe('User visits signup page', function() {
const browser = new Browser();
before(function() {
return browser.visit('/signup');
});
describe('submits form', function() {
before(function() {
browser
.fill('email', 'zombie@underworld.dead')
.fill('password', 'eat-the-living');
return browser.pressButton('Sign Me Up!');
});
it('should be successful', function() {
browser.assert.success();
});
it('should see welcome page', function() {
browser.assert.text('title', 'Welcome To Brains Depot');
});
});
});
手机预览