Selenium provides an API for various events that occur when our scripts are executed like click, switch to a window, navigation, onException, etc. and these can be registered using WebDriverEventListener interface or EventFiringWebDriver class. These events play a pivotal role in analyzing results and in debugging issues (if any).
EventFiringWebDriver class takes care of all events that are occurred while the execution of your script. EventFiringWebDriver class can be bind to more than one listener but all event listeners should be registered with the EventFiringWebDriver class so that it can be notified.
EventFiringWebDriver eventFiring =new EventFiringWebDriver(driver);
FirstEventCapture firstListener =new FirstEventCapture(); //FirstEventCapture implements WebDriverEventListener
SecondEventCapture secondListener =new SecondEventCapture(); //SecondEventCapture implements WebDriverEventListener
eventFiring.register(firstListener);
eventFiring.register(secondListener);
Check this link to know details about all the methods in WebDriverEventListener Interface: https://selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/events/WebDriverEventListener.html
Note* WebDriver listener (WebDriverEventListener) is doing a similar job like TestNG listeners i.e. of logging/reporting things but both work on different events. WebDriverEventListener works on different automation events like click, navigation, etc. whereas TestNG works on different test's related events like onStart(), beforeStart(), etc.
selenium testautomation automationtesting eventListener
1) Using Java (Lengthy way) : Create a utility and use it:>> import java.io.BufferedOutputStream; import org.openqa.selenium.io.Zip; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class UnzipUtil { private static final int BUFFER_SIZE = 4096; public void unzip (String zipFilePath, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { destDir.mkdir(); } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); // to iterates over entries in the zip folder while (en...
Comments
Post a Comment