1

I had an issue with handling the server error page using selenium web driver.While navigating from one page to the other the webpage got crashed and the code which I wrote for fetching the Web Element which were in place is not responding.

//Function Call by passing the arguments 

commFunction.ElementTitleValidation(driver,props,"CustomerPricing_SubMenu_Title");


  //Method for ElementTitleValidation

     public void ElementTitleValidation(WebDriver driver, Properties props,String MenuTitle) 
     {  
        boolean ElementTitle;
        ElementTitle=ValidationHelper.isElementPresent(driver, By.xpath(LocatorModule(props,MenuTitle)));
        System.out.println("The Visibility of Element title  is "+MenuTitle+" and it is matching"); 
        if(ElementTitle==false)
        {
            Assert.fail("ElementTitle Not Found !!!!");
            System.out.println("ElementTitle Not Found !!!!");
        }


  //Method for Checking the WebElement Present or Not

    public static boolean isElementPresent(WebDriver driver , By by){
      WebElement ElementPresent=driver.findElement(by);
        if( ElementPresent != null)
        {
            return true;

        }
        else{
            return false;
        }


    }

So how to efficiently track such Page error or Server error issues while automating with selenium webdriver

Baburaj
  • 41
  • 2
  • 7
  • What do you mean by Page error and Server error? Are they http status code 404, 500, 503, ...? – Buaban Feb 19 '16 at 08:47
  • @Buaban Page Error I mean the http status cod 404,500 etc and Server error means error which throw this message -->'Server Error in '/' Application' as header – Baburaj Feb 19 '16 at 08:51
  • Selenium cannot check status code. You'd better use other tools such as RESTSharp or SoapUI. Otherwise, you have to implement proxy on your machine and configure the webdriver to use that proxy. For Server Error, I think you can just check the message in body. Do you have any example application that I can access? So I can give you some example code. – Buaban Feb 19 '16 at 08:56
  • You can (of course), but you should **not** be testing for server errors. As a tester you should be raising server errors as bugs and working on clean, stable test environments - finding bugs, not working around existing ones. That's the developers' job. – Andrew Regan Feb 19 '16 at 21:18
  • @AndrewRegan All I need to do is to fail the testcase if I get any error page mentioned above.In short I need to call Assert.fail for the scenarios – Baburaj Feb 22 '16 at 07:40

1 Answers1

0

Your scenario will fail when webelements on the expected page are not found. What I would do is add an after hook (Cucumber JUnit) that executes just before the failing scenario exits to capture a screen shot.

@After
/**
 * Embed a screenshot in test report if test is marked as failed
 */
public void embedScreenshot(Scenario scenario) {

    if(scenario.isFailed()) {
    try {
         scenario.write("Current Page URL is " + driver.getCurrentUrl());
         //            byte[] screenshot = getScreenshotAs(OutputType.BYTES);
        byte[] screenshot =  (TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
        scenario.embed(screenshot, "image/png");
    } catch (WebDriverException somePlatformsDontSupportScreenshots) {
        System.err.println(somePlatformsDontSupportScreenshots.getMessage());
    }

    }
    driver.quit();

}
MikeJRamsey56
  • 2,779
  • 1
  • 20
  • 34