Quality Testing

Quality is delighting customers

How to verify whether test case is pass or fail in selenium webdriver.

How to verify whether test case is pass or fail in selenium webdriver.
Should use assert statement or should use if alse statements?

Views: 3385

Reply to This

Replies to This Discussion

there are different ways that you can check outcome with expected result.

  • Data (I mean values) - You can compare values with Assertion. Here is the link for an example http://software-testing-tutorials-automation.blogspot.co.uk/2014/03...
  • Text - In the same way same as values comparision that you can follow I assume. i.e, text comparision
  • Manual verification - Take a screenshot then verify it manually if there are images or if you dont know what should be the expected outcome.  Here is sample code for it: WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

Hopefully this helps you.

Would accept if there are any other ideas. Thanks

Happy testing


Thanks sam for your response. I think Assertion is good approach.

Hi pankaj,

By using if condition it is possible, if the test case is pass it will go to if statement and if the test case is fail it will go else statement. If you want to print the error u can use try catch in else statement or you can use take screenshot method.

for example:

public void test(){ 

WebElement submit = driver.findElement(By.id(""));
System.out.println("submit button is displayed");
} else {

} catch(Exception e){
System.out.println("submit button is not displayed displayed");
ExcelPaths.takeScreenshot(driver, "D:test//test.jpg");


public static void takeScreenshot(WebDriver driver, String FilePath) throws Exception {

TakesScreenshot SCRShot = ((TakesScreenshot)driver);

File FileScr = SCRShot.getScreenshotAs(OutputType.FILE);

File DestiFile = new File(FilePath);
FileUtils.copyFile(FileScr, DestiFile);

correct me if am wrong means...........:-)

Sudarshan , thanks for reply. writing empty try block is valid? or is this good practice?

 u can use like this




TTWT Magazine





© 2021   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service