Sunday 31 July 2016

Capture Screenshot of required element using Selenium


Usually, the selenium tests would capture the complete screenshot of the application. Capturing multiple screens would increase the size of reports or at times it is unnecessary to capture whole screen.

Ever thought of capturing only required web element?
Yes! we can. Follow the below process to capture the required element.

//Find the web element
WebElement elm = driver.findElement(xpath or any locator);
File compFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage image = ImageIO.read(compFile);

//get the image location & save to a file.
Point pnt = elm.getLocation();
BufferedImage elmImg = image.getSubimage(pnt.getX(), pnt.getY(), elm.getSize().getWidth(), elm.getSize().getHeight());
ImageIO.write(elmImg, "png", compFile);

FileUtils.copyFile(compFile, new File("filepath/filename" + ".png"));

Basic 'Broken Link Checker' using Selenium WebDriver


Link Health is very important for any website to reach its customers.
One can make sure if all the links of the website are broken or not, using various available open source or licensed tools.

Below is one of the basic way of validating the links on a particular page using Selenium WebDriver.
NOTE: Can be part of your various regression tests.


Sample Code:


Tuesday 26 July 2016

Test Video using Selenium WebDriver


Testing a video is always a challenging task. Most of the video based web sites are manually tested & are out of scope of automation.

However, the javascript executor in selenium webdriver will enable us to play around with the video components. Thus, few of the test scenarios w.r.t video testing can be automated using the below approach.


Sample Video: Video Component Sample
Video Component: JW Player, JW HTML5 Video Player

Test SVG Graphs Using Selenium WebDriver



At times, during functional testing validating the data in the graphs or charts become crucial to proceed further.On further analysis on dom structure, graph appears to be built on SVG. This complicates the automation testing.

Many a times, testers just leave the particular scenarios as not automatable saying Graphs / images are not automatable. But, that is not right. We'll have one or the other solution to automate everything. Yes! may not be 100 percent.

Sample SVG Graphs: SVG Sample Graphs


Below approach let you know a way to automate SVG graphs using Selenium WebDriver.