Professional Documents
Culture Documents
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
=================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);
Iterator<WebElement> it = links.iterator();
Iterator<WebElement> iteratorImg = images.iterator();
while(it.hasNext()){
url = it.next().getAttribute("href");
Logs.getLog().startLog().warn("=>>>>>" +url);
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();
}
Logs.getLog().startLog().warn("=>>>>>" +url);
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;