Skip to content

Commit

Permalink
Event Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jul 11, 2019
1 parent 48f9406 commit c10914a
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 2 deletions.
144 changes: 144 additions & 0 deletions webdriver_java/src/main/java/utils/EventReporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package utils;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.WebDriverEventListener;

public class EventReporter implements WebDriverEventListener {
@Override
public void beforeAlertAccept(WebDriver webDriver) {

}

@Override
public void afterAlertAccept(WebDriver webDriver) {

}

@Override
public void afterAlertDismiss(WebDriver webDriver) {

}

@Override
public void beforeAlertDismiss(WebDriver webDriver) {

}

@Override
public void beforeNavigateTo(String s, WebDriver webDriver) {

}

@Override
public void afterNavigateTo(String s, WebDriver webDriver) {

}

@Override
public void beforeNavigateBack(WebDriver webDriver) {

}

@Override
public void afterNavigateBack(WebDriver webDriver) {

}

@Override
public void beforeNavigateForward(WebDriver webDriver) {

}

@Override
public void afterNavigateForward(WebDriver webDriver) {

}

@Override
public void beforeNavigateRefresh(WebDriver webDriver) {

}

@Override
public void afterNavigateRefresh(WebDriver webDriver) {

}

@Override
public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {

}

@Override
public void afterFindBy(By by, WebElement webElement, WebDriver webDriver) {

}

@Override
public void beforeClickOn(WebElement webElement, WebDriver webDriver) {
System.out.println("Clicking on " + webElement.getText());
}

@Override
public void afterClickOn(WebElement webElement, WebDriver webDriver) {

}

@Override
public void beforeChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {

}

@Override
public void afterChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {

}

@Override
public void beforeScript(String s, WebDriver webDriver) {

}

@Override
public void afterScript(String s, WebDriver webDriver) {

}

@Override
public void beforeSwitchToWindow(String s, WebDriver webDriver) {

}

@Override
public void afterSwitchToWindow(String s, WebDriver webDriver) {

}

@Override
public void onException(Throwable throwable, WebDriver webDriver) {

}

@Override
public <X> void beforeGetScreenshotAs(OutputType<X> outputType) {

}

@Override
public <X> void afterGetScreenshotAs(OutputType<X> outputType, X x) {

}

@Override
public void beforeGetText(WebElement webElement, WebDriver webDriver) {

}

@Override
public void afterGetText(WebElement webElement, WebDriver webDriver, String s) {

}
}
7 changes: 5 additions & 2 deletions webdriver_java/src/test/java/base/BaseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import pages.HomePage;
import utils.EventReporter;
import utils.WindowManager;

import java.io.File;
import java.io.IOException;

public class BaseTests {

private WebDriver driver;
private EventFiringWebDriver driver;
protected HomePage homePage;

@BeforeClass
public void setUp(){
System.setProperty("webdriver.chrome.driver", "resources/chromedriver");
driver = new ChromeDriver();
driver = new EventFiringWebDriver(new ChromeDriver());
driver.register(new EventReporter());
goHome();
}

Expand Down

0 comments on commit c10914a

Please sign in to comment.