如何使用Selenium Web驱动程序捕获服务器错误页面? [英] How to capture Server Error Pages using selenium Web driver?

查看:267
本文介绍了如何使用Selenium Web驱动程序捕获服务器错误页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Selenium Web驱动程序处理服务器错误页面时遇到问题.从一个页面导航到另一页面时,该页面崩溃了,并且我为获取适当位置的Web元素而编写的代码没有响应.

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;
        }


    }

因此,如何在使用硒Web驱动程序自动化时有效地跟踪此类页面错误或服务器错误问题

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

推荐答案

当未在预期页面上找到网络元素时,您的方案将失败.我要做的是添加一个After钩子(Cucumber JUnit),该钩子在失败的场景退出之前立即执行以捕获屏幕快照.

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();

}

这篇关于如何使用Selenium Web驱动程序捕获服务器错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆