我的页面上有一些链接,试图在单击前后验证文本。
如果单击前的链接文本为“一二”,而单击后的链接文本为“一二”,则测试用例通过。但是如果单击后文本为“二合一”,则失败。
我使用了expect(before click).tocontain(afterclick)
和expect(before click).matches(afterclick)
。两者都不起作用,所以我正在寻找仅包含的东西。
如果有类似的事情可以帮我吗?
verifylinks(){
var alllinks = element.all(by.css('div>h3>a'));
browser.sleep(15000); // just for debug purpose to wait page loading.
alllinks.count().then(function (length) {
console.log('link amount: ' + length);
for (let i = 0; i < length; i++) {
alllinks.get(i).getText().then(function (linktextbeforeclick) {
var string = linktextbeforeclick.replace(/\(|,/g, '');
var textbeforeclick = string.replace(/\)|,/g, '');
console.log("textbeforeclick:" + textbeforeclick);
alllinks.get(i).click();
browser.sleep(5000);
element(by.css('div>h2')).getText().then(function (linktextafterclick) {
var string = linktextafterclick.replace(/\(|,/g, '');
var textafterclick = string.replace(/\)|,/g, '');
console.log("textafterclick:" + textafterclick);
expect(textbeforeclick).toContain(textafterclick);
})
browser.navigate().back();
})
}
})
}
答案 0 :(得分:0)
verifylinks() {
let alllinks = element.all(by.css('div>h3>a'));
alllinks.count().then(function(count){
console.log('link amount:', count);
for(let i=0;i<count;i++) {
let beforeText = getLinkText(alllinks.get(i));
alllinks.get(i).click();
browser.sleep(5000);
let afterLink = element(by.css('div>h2');
// confirm the locator for finding after click link is correct.
let afterText = getLinkText(afterLink);
Promise.all([beforeText, afterText])
.then(function(txts){
console.log('link text before click:', txt[0]);
console.log('link text after click:', txt[1]);
expect(txt[0]).toEqual(txt[1]);
});
browser.navigate().back();
browser.sleep(5000);
}
});
}
getLinkText(link) {
return link.getText().then(function(str){
return str.replace(/\(|,/g, '').replace(/\)|,/g, '').trim();
});
}
答案 1 :(得分:0)
如果您使用的是!pip install tensorflow-gpu==2.0.0-alpha0
(我强烈建议您使用异步语言编写顺序测试,那么会很费事),就像
async/await