Tuesday, May 21, 2013

How to fail test case in TestNG with Selenium

Q. How do I fail or report a failed test case?
Ans. You can use Assert statement to report a failure.

              org.testng.Assert.fail("Test Case Failed!");

you can use Assert in If Else statement to check for failure, quick example below, I am using selenium code snippet here!  
   
  if(convert.contains(blah)) 
 {
    Reporter.log("Pass");
 }
   else
 {
    org.testng.Assert.fail("Fail");
 }

Monday, May 13, 2013

Basic Automation Framework

Simple basic automation framework with base components, one can always make it as complicated as they want. But over the years this has been the basic structure for me.

Components:
1) Data Files: You store your test data here in XML, JSON, or any other format that you are going to read it from.
2) Test Script: This will store your scripts/code that you wish to execute/run using the Data Files.
3) Reporting and Logging: This is where you will receive your debug, error and reporting logs. You can define these as checkpoints in your script/code.
4) Client: This is where all the fun takes place(automated script execution), I call it sit and watch place!