Sai*_*ram 11 selenium angularjs protractor
我正在用量角器编写E2E测试.我不得不从浏览器中获取信息并多次执行一个步骤.
我正在测试一个屏幕,它将在a
idhtml id不会改变.提交当前表单后再次查询时值会更改.for(i = 0 ; i < count ; i++){
console.log("counter is "+i);
element(by('id')).evaluate('value').then(function(v) {
// do some action on UI based on v
element(by('id1')).sendKeys(v+v);
// submit etc.,
// some angular code runs in the frontend.
}
// need to wait since webdriver jumps to the next one without this completing
}
Run Code Online (Sandbox Code Playgroud)
许多博客文章/文档表明你不能在循环中使用它,但不建议任何替代方法来执行此操作.
任何建议赞赏.
永远不要在循环中使用protractor元素语句:简单的原因是webdriverJS(量角器)API是异步的.元素语句返回一个promise,当promise继续执行时,该promise将处于未解析状态.这导致不可预测的结果.因此,建议使用递归函数而不是循环.
来源:http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/
编辑:更新的问题与工作流程的详细信息
量角器中的循环是这样的
describe('Describe something', function() {
var testParams = [1,2,3,4,5,6,7,8,9,10];
beforeEach( function() {
// ...
});
for (var i = 0; i < testParams.length; i++) {
(function (testSpec) {
it('should do something', function() {
// inside loop
});
})(testParams[i]);
};
});
Run Code Online (Sandbox Code Playgroud)
编辑:我可能会误解你的问题,但在我看来,你想在进入下一个之前完成页面上的所有(动态计数)操作?
it('should clear old inspections', function() {
inspectieModuleInspectieFixture.getRemoveInspectionButton().count().then(function (value) {
if(value == 0){
console.log('--- no inspections to remove ---');
}
for(var i = 0; i < value; i++){
//global.waitForClickable(inspectieModuleInspectieFixture.getRemoveInspectionButtonList(i+1));
inspectieModuleInspectieFixture.getRemoveInspectionButtonList(i+1).click();
console.log('iteration '+i + 'count '+value )
};
});
global.wait(5000);
}); */
Run Code Online (Sandbox Code Playgroud)
这对页面上的元素进行计数,然后针对找到的元素数量执行操作
在上面的示例中,我使用容器来保存我的元素,因此我的代码仍然可读(即inspectieModuleInspectieFixture.getRemoveInspectionButton()保存$(“.elementSelectorExample”)
还有一个注释为“global.waitForClickable”,它指的是我创建的一个“时间模块”,它扩展了“等待”的功能,在这种情况下,它会等到元素可见/可点击。
这很容易反映出来,也许是这样的:
waitForElementNoDisplay: function(element){
return browser.wait(function() {
return element.isDisplayed().then(function(present) {
return !present;
})
});
},
Run Code Online (Sandbox Code Playgroud)
这将使量角器等待,直到不再显示元素。(显示:无)
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |