I will give "from dates" and "To dates" and hit a "create" button. The expected output is
In the 1st scenario :
<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<
In the 2nd scenario :
<div data-ng-if="noCases()" class="ng-scope"
<h3 class="ABC" >0 cases ound from "from dates" to "to dates"
I am successful in testing the postive scenario(where cases found)
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");
}
How do I check if the "summary" text contains "0 cases found...." then do nothing or if the cases found, then click on the Dynamically generated Download button.
Pls try the below snippet,
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");
}
});
Cheers!