【发布时间】:2017-11-07 12:38:19
【问题描述】:
有没有办法刮掉或删除 element.all 数组返回的随机值或少数值?
我试图自动化的场景是检查“HTML”这个词是否应该出现在从数组列表返回的每一行中。
我使用 w3Schools 作为虚拟测试网站来试用我的场景,下面是由于断言而失败的代码。
describe('Searching for word HTML', function() {
var array=[];
var counter=0;
it('Beginning of the test', function() {
browser.ignoreSynchronization = true;
browser.get('https://www.w3schools.com/html/default.asp');
browser.sleep(5000).then(function(){});
var lines = element.all(by.css('#leftmenuinnerinner>a'));
lines.count().then(function(counting){
console.log("There are total "+counting+" links");
counter=counter+counting;
return counting;
})
lines.getText().then(function(text){
console.log("Values:::: "+text);
for(var k=0;k<text.length;k++){
expect(text[k]).toContain('HTML');
}
})
})
})
我知道我可以使用 xpath 值并仅遍历 76 个值的循环,但我正在尝试通过 css 选择器的方法,我需要严格获取整个值列表,所以有什么方法可以修剪或者通过我返回的数组中的代码动态地刮掉值“HTTP Messages”、“HTTP Methods”、“PX to EM Converter”和“Keyboard Shortcuts”,以便我的断言通过?
【问题讨论】:
标签: javascript arrays automation protractor gulp-protractor