我有一个使用Dojo在页面之间导航的单页面应用程序。我正在使用实习生编写一些功能测试,而我试图清除一些小问题。具体来说,我在让实习生超时方面遇到麻烦。超时似乎对我没有任何影响。我正在尝试使用“ setPageLoadTimeout(30000)”设置初始加载超时,但这似乎被忽略了。我也叫“ setImplicitWaitTimeout(10000)”,但是这似乎没有任何作用。
我遇到的主要问题是,在测试环境中,发送请求和解析响应并将其注入DOM可能需要花费几秒钟的时间。我能够解决此问题的唯一方法是,例如,通过显式调用“ sleep(3000)”,但这可能会遇到一些麻烦,有时在我查询它们时DOM元素还没有准备好。(如前所述,setImplicitWaitTimeout(10000)似乎对我没有影响)
使用该应用程序,当DOM更新时,我会触发一个事件。我使用dojo.subscribe来挂接到应用程序中。是否可以在内部使用dojo.subscribe来控制测试的执行?
这是我的代码示例。我还应该提到我使用Dijit,因此在响应返回并创建小部件时(通过data-dojo-type声明)也存在一些延迟...
define([
'intern!object',
'intern/chai!assert',
'require',
'intern/node_modules/dojo/topic'
], function (registerSuite, assert, require, topic) {
registerSuite({
name: 'Flow1',
// login to the application
'Login': function(remote) {
return remote
.setPageLoadTimeout(30000)
.setImplicitWaitTimeout(10000)
.get(require.toUrl('https://localhost:8080/'))
.elementById('username').clickElement().type('user').end()
.elementById('password').clickElement().type('password').end()
.elementByCssSelector('submit_button').clickElement().end();
},
// check the first page
'Page1':function() {
return this.remote
.setPageLoadTimeout(300000) // i've tried these calls in various places...
.setImplicitWaitTimeout(10000) // i've tried these calls in various places...
.title()
.then(function (text) {
assert.strictEqual(text, 'Page Title');})
.end()
.active().type('test').end()
.elementByCssSelector("[title='Click Here for Help']").clickElement().end()
.elementById('next_button').clickElement().end()
.elementByCssSelector("[title='First Name']").clear().type('test').end()
.elementByCssSelector("[title='Gender']").clear().type('Female').end()
.elementByCssSelector("[title='Date Of Birth']").type('1/1/1980').end()
.elementById('next_button').clickElement().end();
},
// check the second page
'Page2':function() {
return this.remote
.setImplicitWaitTimeout(10000)
.sleep(2000) // need to sleep here to wait for request & response injection and DOM parsing etc...
.source().then(function(source){
assert.isTrue(source.indexOf('test') > -1, 'Should contain First Name: "test"');
}).end()
// more tests etc...
}
});
});
我正在从内部dojo节点模块中导入相关的Dojo模块,但不确定如何使用它。
谢谢
您的测试正在超时,因为实习生测试的显式超时设置为30秒,无法通过其API访问。可以通过添加'intern/lib/Test'
到您的define数组,然后覆盖Test对象的超时来更改它,例如Test.prototype.timeout = 60000;
。
例如:
define([
'intern!object',
'intern/chai!assert',
'require',
'intern/node_modules/dojo/topic',
'intern/lib/Test'
], function (registerSuite, assert, require, topic, Test) {
Test.prototype.timeout = 60000;
...
}
这应该将超时更改为一分钟而不是30s,以防止测试超时。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句