问题描述
我将给出“开始日期”和“结束日期”,然后单击“创建”按钮。 预期的输出是
- 使用下载按钮从“从日期”到“到日期”找到N个案例
- 从“从日期”到“到日期”共找到0个案例,没有下载按钮
在第一种情况下:
<div data-ng-if="canDownload()" class="ng-scope"
<h3 class="ABC" id="summary">N cases ound from "from dates" to "to dates"
<a data-ng-href="URL" id="summaryHREF"
<button class="XYZ" type="submit">Download<
在第二种情况下:
<div data-ng-if="noCases()" class="ng-scope"
<h3 class="ABC" >0 cases ound from "from dates" to "to dates"
我成功地测试了阳性方案(在发现病例的情况下)
let notes = element(by.id("summary"));
var EC = protractor.ExpectedConditions;
var flag = browser.wait(EC.visibilityOf(notes), 5000, '**** There are cases to Download ****');
if(flag){
this.downloadReg = element(by.xpath("//button[text()='Download']"));
this.downloadReg.click();
}
else{
console.log("No Cases found and Do Nothing");
}
如何检查“摘要”文本是否包含“找到0个案例...”,然后什么也不做,或者是否找到案例,然后单击“动态生成的下载”按钮。
1楼
dheeraj
1
已采纳
2019-02-22 14:12:34
请尝试以下代码段,
browser.wait(EC.visibilityOf(element(by.css('#summary'))), 5000, '**** There are cases to Download ****').then(flag => {
if(flag){
this.downloadReg = element(by.xpath("//button[text()='Download']"));
this.downloadReg.click();
}else{
console.log("No Cases found and Do Nothing");
}
});
干杯!
2楼
Kacper
0
2019-02-21 12:55:56
我建议使用:
if else
没有其他必要, if else
无需使用-当测试找不到预期的测试时,它将在超时时失败。
3楼
tehbeardedone
0
2019-02-22 03:24:27
您可以先检查DOM中是否存在下载按钮,然后单击它。 否则,什么也不做,继续前进。
假设在第二种情况下, h3
元素也具有'summary'
id属性。
const notes = element(by.id('summary'));
await browser.wait(EC.visibilityOf(notes), 5000);
const downloadBtn = element(by.buttonText('Download'));
const flag = await downloadBtn.isPresent();
if (flag) {
await downloadBtn.click();
}
4楼
Ven Test
0
2019-02-25 11:19:11
1)等待元素使用期望的条件(EC)定位2)使用cssContainingText('locator',“ string”)
要不然
使用以下命令编写动态xpath: