[英]Unable to compare multiple array values with dynamic array in expect-Protractor
Below is the scenario i am trying to automate: 以下是我要自动执行的方案:
I am getting an expectation failure when comparing static array with a dynamic array. 将静态数组与动态数组进行比较时,出现预期失败。
Below is my code: 下面是我的代码:
describe('My Test', function() {
var names1="";
var names2="";
var names3="";
it('Test starts', function() {
browser.ignoreSynchronization = true;
browser.get('https://www.w3schools.com/angular/');
browser.sleep(5000).then(function(){
});
var results = element.all(by.css(".sidesection>p>a"));
results.get(0).getText().then(function(text){
console.log("Names are "+text);
names1=text;
})
results.get(1).getText().then(function(text){
console.log("Names are "+text);
names2=text;
})
results.get(2).getText().then(function(text){
console.log("Names are "+text);
names3=text;
})
});
it('Test starts2', function() {
var array=[names1,names2,names3];
console.log("URLS fetched are this:- "+names1);
console.log("URLS fetched are this:- "+names2);
console.log("URLS fetched are this:- "+names3);
var results2 = element.all(by.css(".sidesection>p>a"));
expect(results2.getText()).toContain(array);
});
});
The problem you are trying to expect(someArray).toContain(array)
which is not possible. 您试图
expect(someArray).toContain(array)
的问题expect(someArray).toContain(array)
这是不可能的。 In case of string or regex it is possible. 如果是字符串或正则表达式,则是可能的。 For you solution we can perform like this,
对于您的解决方案,我们可以像这样执行,
element.all(by.css(".sidesection>p>a")).getText().then(function(menus){
for(var i=0; i<array.length; i++){
expect(menus.indexOf(array[i])!=-1).toBeTruthy();
}
});
you can also try to segreggate the array values in form of individual string keywords & then use them in the expect statements like below: 您还可以尝试以单个字符串关键字的形式隔离数组值,然后将其用于Expect语句中,如下所示:
expect(results2.getText()).toContain(names1);
expect(results2.getText()).toContain(names2);
expect(results2.getText()).toContain(names3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.