04
Oct

Hacks with Selenium reporting

11. Don't Be Afraid to Hack Selenium When Time Demands
Smart work is appreciated, so don't be afraid to hack Selenium Webdriver to make an effective automation scripting.

There are two lines in particular that you can use as shortcuts.

Hack #1: TestNG report – Screenshot Linking
Use the following code for screenshot linking to a TestNG report. This will become a hyperlink allowing you to open the captured screenshot.

Reporter.log("<a href="+"E:\\screenshot\\"+screenshot_timestamp+".png"+">)click to open


Hack #2: Check the Existence of A Web Element
The code given below will let you check the code size of the web object and identify the presence of a particular web element.

driver.findElements(By.id("element-id")).size()!=0