How to handle exception in Webdriver using TestNG

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to handle exception in Webdriver using TestNG

rangegowdaym
Hi Tarun, I am facing problem in handling exception in webdriver using TestNG. In the below highlighted code. I purposeful gave wrong xpath , so that my testcase will fail, but when i execute this code using TestNG, My testcase will pass Note: in the Eclipse console it displayed an exception saying that "org.openqa.selenium.NoSuchElementException". but in TestNG tab the testcase is pass. could you please help me in this. Thanks in advance @Test public void testLogIN() { try { WebDriver driver = new FirefoxDriver(); driver.navigate().to(URL); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.id("gosign")).click(); driver.switchTo().frame(driver.findElement(By.id("sky-sso-fancybox-frame"))); driver.findElement(By.id("txt-login-uid-login-sso")).sendKeys("aditigbp10"); driver.findElement(By.id("txt-login-pin-login-sso")).sendKeys("1212"); driver.findElement(By.id("btn-login-submit-log")).click(); driver.switchTo().defaultContent(); Assert.assertEquals("fxakfmxfqabmum", driver.findElement(By.linkText("fxakfmxfqabmumh")).getText()); } catch (Exception e) { Reporter.log(e.getMessage()); }
Reply | Threaded
Open this post in threaded view
|

Re: How to handle exception in Webdriver using TestNG

GopiJayaraj
Were you able to solve the problem, please reply the solution.
Reply | Threaded
Open this post in threaded view
|

Re: How to handle exception in Webdriver using TestNG

rangegowdaym
Hi Gopi,

public void testLoginLogout()
    {       
        try
        {
            String un = xllib.getExcelData("Login", 1, 0);
            String pw = xllib.getExcelData("Login", 1, 1);
            LoginPage lp = new LoginPage(driver);
            lp.login(un,pw);
            EnterTimeTrackPage ettp = new EnterTimeTrackPage(driver);
            ettp.logout();
            Reporter.getCurrentTestResult();
            Reporter.log("Log in is passed");
        }
        catch (Exception e)
        {
            Reporter.log("Log in is failed");
            e.printStackTrace();
            throw e;
        }
    }

It works for me

On Fri, Oct 10, 2014 at 6:16 PM, GopiJayaraj [via Manual and Automated Testing] <[hidden email]> wrote:
Were you able to solve the problem, please reply the solution.


To unsubscribe from How to handle exception in Webdriver using TestNG, click here.
NAML



--



 

Best Regards,

Rangegowda Y M | Test Engineer

(M) +91 954 342 6304 / 997 266 9841

(IM) Rangegowda Manjunath | Skype: rangegowda.manjunath1