Selenium : Unable to take a screenshot of failed Login Page

so for taking the screenshots for the failed tests in selenium I have used the following code :

@AfterMethod
    public void tearDown(ITestResult testResult) throws IOException{
        if(ITestResult.FAILURE==testResult.getStatus()){
            AppUtils.screenshotOnTestFailure();
        }

So what is happening if just for testing purpose I intentionally failed my test by giving the wrong located for username and then if i ran i get the login screenshot. But if I am passing the credentials for the username as incorrect then the test is getting passed and I am unable to get the screenshot. But what happens in the login screen is that if fills username (which is incorrect), password and clicks on login button and then shows a error message "You must specify a valid username and password". Now I can't login but it is showing it as a passed test , please present your thoughts on this. Thanks

**XML File:**
<suite name="vTigerAutomation" verbose="1">

    <!-- ** These listeners are required for ReportNG report generation while 
        default report is turned off in TestNg prop** -->
    <listeners>
        <listener class-name="org.uncommons.reportng.HTMLReporter" />
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
    </listeners>

    <test name="testOnChrome" preserve-order="true">
        <parameter name="BrowserName" value="ch" />
        <parameter name="url" value="http://localhost:8888" />
        <parameter name="username" value="admin" />
        <parameter name="password" value="admi" />

        <classes>
            <class name="tiger.SampleProject.MyHomepageTestCases.HomeTestCases" />
            <methods>
                <include name="tc_loginIntoApp" />
                <exclude name="tc_countOfElements" />
                <exclude name="tc_enterDataIntoFindBox" />
            </methods>


**HomeTestCases Class:**

@Parameters({"username","password"})                            //passing Username n pass from xml to LoginPage class
    @Test
    public void tc_loginIntoApp(String username, String password) throws IOException {


         homeObj=lpobj.appLogin(username,password,driver);          

**LoginPage class:**

public Home appLogin(String username, String password, WebDriver driver)
            throws IOException {                       

            AppUtils.typeValue(username_WE, username);
            AppUtils.typeValue(password_WE, password); 
            AppUtils.clickElement(clk_LoginButton);

        Home hpObj = PageFactory.initElements(driver, Home.class);
        return hpObj;
    }

Home Class

public class Home {

private static Logger log=Logger.getLogger(Home.class);
    public static CalenderPage cpObj=null;

    @FindBy(linkText="Calendar")
    private static WebElement clk_Calender;

    @FindBy(name="query_string")
    private static WebElement enter_FindBox;

    @FindBy(linkText="Home")
    private static WebElement homeHeader;

    public void enterDataIntoSearchBox(){
        AppUtils.typeValue(enter_FindBox, "testdata");

        String Text=enter_FindBox.getAttribute("name");
链接地址: http://www.djcxy.com/p/67400.html

上一篇: 使用Selenium 3.6截图

下一篇: Selenium:无法截取失败的登录页面