我是CasperJS的新手,我已经开始创建一个测试套件了.一些步骤(如登录到应用程序)将被重复使用,因此我们希望在库文件(包含在测试文件中)中管理它们.
此外,我们有多个环境运行(开发,集成,生产等),因此我们需要为此参数化测试步骤,因此应该可以将参数传递给模块.
我搜索了文档和stackoverflow(我知道有类似的问题),但我的Javascript技能显然太有限,我无法启动并运行.
这是我的示例测试文件:
// googletesting.js
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
casper.start("http://www.google.fr/", function() {
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertTitle("casperjs - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
test.assertEval(function() {
return __utils__.findAll("h3.r").length >= 10;
}, "google search for \"casperjs\" retrieves 10 or more results");
});
casper.run(function() {
test.done();
});
});
Run Code Online (Sandbox Code Playgroud)
这就是它应该是(或类似的):
// …Run Code Online (Sandbox Code Playgroud)