You are on page 1of 4

1157 catch of forloop

2.logs only one sheet executed , error may be issue


3. 2nd sheet name is not changed
3. logs only one sheet executed (as hardassert is present)

modified: DaisyDev/src/com/persistent/daisy/base/Configurations.java
modified: DaisyDev/src/com/persistent/daisy/core/Executor.java
modified: DaisyDev/src/com/persistent/daisy/core/Master.java
modified:
DaisyDev/src/com/persistent/daisy/core/browser/SeleniumUtils.java

ForLoop iteration number is not logged


{forLoop ,Foreach ,}
Log for line number should contain Script:Sheetname
{general ,forLoop , Failure , include ,Fails , }

=================BROKEN_CMD
public void checkBrokenLinks(String homePage) {
int BrokenLinkCount=0;
int BrokenImgCount=0;
String url = "";
HttpURLConnection huc = null;
int respCode = 200;
// driver = new ChromeDriver();
// driver.manage().window().maximize();

driver.get(homePage);

List<WebElement> links = driver.findElements(By.tagName("a"));


List<WebElement> images = driver.findElements(By.tagName("img"));

Iterator<WebElement> it = links.iterator();
Iterator<WebElement> iteratorImg = images.iterator();

while(it.hasNext()){
url = it.next().getAttribute("href");

Logs.getLog().startLog().warn("=>>>>>" +url);

if(url == null || url.isEmpty() || url.equals("#")){


Logs.getLog().startLog().warn("URL is either '_' / '#' / 'null'
");
Report.getReport().logFail(url+" : not valid link : URL is '_' /
'#' / 'null' " );
BrokenLinkCount++;
continue;
}

try {

try {
huc = (HttpURLConnection)(new URL(url).openConnection());
}
catch(Exception e) {
Logs.getLog().startLog().warn("File link in URL");
Report.getReport().logFail(url+" : not valid link :File
link in URL" + "[indicate file]");
BrokenLinkCount++;
continue;
}

huc.setRequestMethod("HEAD");
huc.connect();
respCode = huc.getResponseCode();
if(respCode >= 400){
Logs.getLog().startLog().warn(url+" is a broken link");
Report.getReport().logFail(url+" : not valid link " + "[ Response
: " + respCode + "]");

BrokenLinkCount++;
}
else{
Logs.getLog().startLog().warn(url+" is a valid link");
}

} catch (Exception e) {
Logs.getLog().startLog().warn("NOT REACHABLE : " + url);
Report.getReport().logFail(url+" : not valid link[NOT
REACHABLE ]");

BrokenLinkCount++;
// e.printStackTrace();
}

//for finding broken images


while(iteratorImg.hasNext()){
url = iteratorImg.next().getAttribute("src");

Logs.getLog().startLog().warn("=>>>>>" +url);

if(url == null || url.isEmpty() || url.equals("#")){


Logs.getLog().startLog().warn("URL is either '_' / '#' / 'null'
");
Report.getReport().logFail(url+" : not valid Image link " );
BrokenImgCount++;
continue;
}

try {

try {
huc = (HttpURLConnection)(new URL(url).openConnection());

}
catch(Exception e) {
//file cant be considered as broken
// Logs.getLog().startLog().warn("File link in image");
// Report.getReport().logFail(url+" : not valid Image link " +
"[indicate file]");
// BrokenImgCount++;
continue;
}

huc.setRequestMethod("HEAD");
huc.connect();
respCode = huc.getResponseCode();
if(respCode >= 400){
Logs.getLog().startLog().warn(url+" is a broken image");
Report.getReport().logFail(url+" : not valid Image link " + "[" +
respCode + "]");
BrokenImgCount++;
}
else{
Logs.getLog().startLog().warn(url+" is a valid Image link");
}

} catch (Exception e) {
Report.getReport().logFail(url+" : not valid Image link[NOT
REACHABLE ]");
Logs.getLog().startLog().warn("NOT REACHABLE : " + url);
BrokenImgCount++;
}

if(BrokenLinkCount==0)
Report.getReport().logPass("No Broken link on this page");
else
Report.getReport().logFail("Total BrokenLinkCount===>" +
BrokenLinkCount);

if(BrokenImgCount==0)
Report.getReport().logPass("No Broken Image on this page");
else
Report.getReport().logFail("Total BrokenImageCount===>" +
BrokenImgCount);

Logs.getLog().startLog().info("Total BrokenLinkCount===>" +
BrokenLinkCount);
Logs.getLog().startLog().info("Total BrokenImagesCount===>" +
BrokenLinkCount);

--------------------------------------------
case "CheckBroken":
{
exec.isDataMissing(actionData, "CheckBroken");
if(actionData.getData().equals("${url}")) {

actionData.setData(Configurations.getInstance().getAttribute("url") );
}
exec.checkBrokenLinks(actionData.getData());
exec.waitForPageLoaded();

break;

You might also like