【发布时间】:2017-04-12 16:29:22
【问题描述】:
我是 Mocha 和 Webdriver.io 的新手,所以如果我很愚蠢,请原谅...
这是我的代码 -
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Login to ND', function() {
// set timeout to 10 seconds
this.timeout(10000);
var driver = {};
// hook to run before tests
before( function () {
// load the driver for browser
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
return driver.init();
});
// a test spec - "specification"
it('should be load correct page and title', function () {
// load page, then call function()
return driver
.url('https://ND/ilogin.php3')
// get title, then pass title to function()
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("NetDespatch Login");
// uncomment for console debug
console.log('Current Page Title: ' + title);
return driver.setValue("#userid", "user");
return driver.setValue("#password", "pass");
return driver.click("input[alt='Log in']");
});
});
// a "hook" to run after all tests in this block
after(function() {
return driver.end();
});
});
我可以使用 Mocha 执行此操作,并且测试通过,即使它似乎没有完成我定义的所有“步骤”..
它打开页面,记录网站标题,并在用户 ID 中输入“用户”,但是.. 它没有填充密码字段,也没有选择登录链接,并且似乎没有显示任何错误..
Login to ND
Current Page Title: ND Login
✓ should be load correct page and title (2665ms)
1 passing (13s)
但是,由于它没有执行所有步骤,我不希望它通过,不过,我也不明白为什么它不会执行最后几个步骤。
欢迎任何帮助。
谢谢
卡尔
【问题讨论】:
-
您确实意识到,一旦您在函数中添加了
return语句,该函数就会退出,并且return之后的任何内容都不会执行,对吧? -
我猜不是,这对为什么它退出是有道理的,我只是做一个“驱动程序”。如果我希望它继续之后没有返回?谢谢
-
如果我删除用户名/密码上的 3 个返回值/单击它们都不会运行,如果我从初始函数中删除它,它不会执行,我不明白我在做什么'没有得到,为什么这对我来说没有意义..
标签: javascript selenium mocha.js webdriver-io