使用CasperJS实现页面对象模式 [英] Page Object Pattern Implementation with CasperJS
问题描述
有没有人已经用casperjs实现了著名的页面对象模式",这对于长期的测试可维护性很有用吗?
Is there anyone who have already implemented the famous "Page Object Pattern" with casperjs, it's very useful for test maintenability in the long term ?
当您必须分开机制和测试目的时,使用它非常酷.用这种方式编写测试变得更加愉快.
It's very very cool to use that when you have to separe the mechanics and the purpose of your tests. it become more pleasurable to write your tests this way.
有一些关于红宝石和硒的例子:
http://blog.josephwilk.net/cucumber/page-object-pattern.html
https://code.google.com/p/selenium/wiki/PageObjects
There are some examples with ruby and selenium:
http://blog.josephwilk.net/cucumber/page-object-pattern.html
https://code.google.com/p/selenium/wiki/PageObjects
推荐答案
使用第二个链接中的示例,您可以将其转换为类似Javascript类的对象并封装在其自己的模块中:
Using the example in your second link, you can convert this to a Javascript class-like object and encapsulate in its own module:
var LoginPage = function(casper) {
this.casper = casper;
};
LoginPage.prototype.typeUsername = function(username) {
this.evaluate(function() {
__utils__.findOne('input.username').value = username;
});
};
exports = LoginPage;
,然后在测试中使用它:
and then use it in your test:
var LoginPage = require("./LoginPage.js");
var login = new LoginPage(this);
login.typeUsername("geoff");
这篇关于使用CasperJS实现页面对象模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!