Showing posts with label How to take Screenshots if Test Case fales?. Show all posts
Showing posts with label How to take Screenshots if Test Case fales?. Show all posts

How to take Screenshots if Test Case fails?


One basic question which comes in everyone's mind is : What happens if test case fails? Where was the error in script and How can we capture it?

So, the solutions is always (at least in most of the cases) to take screenshots of webpage when the test run fails.

With one look at the screenshot we can get an idea of where exactly the script got failed. Moreover reading screenshot is easier compare to reading 100's of console errors

To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block we should paste the screenshot code:

public class TakeScreenshot {
 
   WebDriver driver;
 
 @BeforeTest
 public void start(){
  driver = new FirefoxDriver();
 }


How to write dynamic Xpath to identify elements on Webpage?


We always have concerns about writing Dynamic Xpath. So, I've listed below some ways to write xpath with example. If you face any problem, Contact Us:

1) Based on location
2) Using Single Attributes
3) Using Multiple Attributes
4) Using functions


All examples are based on following HTML Code:

input class="search-field" name="s" placeholder="Search …" title="Search for:" type="search" value=""

Run your script in Internet Explorer (IE)


 public static void main(String[] args) throws InterruptedException { DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); System.setProperty("webdriver.ie.driver", "C:/IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(ieCapabilities); driver.get("http://google.com"); Thread.sleep(5000); driver.quit(); }

- Download IE Driver by Clicking Here