Лил*_*ина 2 testing filtering cycle angularjs protractor
我尝试用量角器开始测试,现在我遇到了一个问题,我无法解决.
我有这个测试:
describe('Test_3', function() {
var my_url = 'http://wks-15103:8010/ps/ng-components/examples/ps-checkbox.html'
var main_checkbox = element(by.xpath("//div[@ng-model='My_Group']/div[1]/span/span[1]"));
var checkbox_list = element.all(by.xpath("//div[@ng-model='My_Group']/div[2]/div/span/span[1]"));
var title_checkbox_list = element.all(by.xpath("//div[@ng-model='My_Group']/div[2]/div/span"));
var disabled_pri = 'n-check-checkbox';
var enabled_pri = 'n-check-checkbox n-check-checkbox_checked';
beforeEach(function() {
browser.get(my_url);
});
it('schould be chosen',function(){
main_checkbox.click();
checkbox_list.filter(function(elem, index) {
return elem.getAttribute('class').then(function(text) {
return text != 'n-check-checkbox n-check-checkbox_disabled' & text!='n-check-checkbox n-check-checkbox_disabled n-check-checkbox_checked';
});
}).then(function(filteredElements) {
filteredElements.each(function(element, index) {
expect(element.getAttribute('class')).toEqual(disabled_pri);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
它不起作用.但后来我尝试使用过滤而没有循环.each它工作正常.
describe('Test_3', function() {
var my_url = 'http://wks-15103:8010/ps/ng-components/examples/ps-checkbox.html'
var main_checkbox = element(by.xpath("//div[@ng-model='My_Group']/div[1]/span/span[1]"));
var checkbox_list = element.all(by.xpath("//div[@ng-model='My_Group']/div[2]/div/span/span[1]")); //??? ?????? ????? ?????????
var title_checkbox_list = element.all(by.xpath("//div[@ng-model='My_Group']/div[2]/div/span")); //??? ?????? ????????? ? ??????????
var disabled_pri = 'n-check-checkbox';
var enabled_pri = 'n-check-checkbox n-check-checkbox_checked';
beforeEach(function() {
browser.get(my_url);
});
it('schould be chosen',function(){
main_checkbox.click(); //?????? ?????? ? ?????????? ????????
checkbox_list.filter(function(elem, index) {
return elem.getAttribute('class').then(function(text) {
return text != 'n-check-checkbox n-check-checkbox_disabled' & text!='n-check-checkbox n-check-checkbox_disabled n-check-checkbox_checked';
});
}).then(function(filteredElements) {
filteredElements[0].click();
filteredElements[0].click();
expect(filteredElements[0].getAttribute('class')).toEqual(disabled_pri);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我的错是什么?
如文档filter中所述,它返回一个实例ElementArrayFinder.当你then在实例上调用一个方法时ElementArrayFinder,它会解析为一个ElementFinders 数组,所以在回调中then你会得到一个纯JavaScript的数组ElementFinder.要迭代它,您可以使用本机JavaScrupt forEach:
checkbox_list.filter(function(elem, index) {
// ...
})
.then(function(filteredElements) {
filteredElements.forEach(function(element, index) {
// ....
});
});
Run Code Online (Sandbox Code Playgroud)
否则,ElementArrayFinder有它自己的方法each,你应该在结果上调用它filter,而不是在回调中then:
checkbox_list.filter(function(elem, index) {
// ...
})
.each(function(element, index) {
// ....
});
Run Code Online (Sandbox Code Playgroud)
也许源代码ElementArrayFinder也可以帮助你.
| 归档时间: |
|
| 查看次数: |
5071 次 |
| 最近记录: |