Created
May 17, 2011 18:47
-
-
Save freynaud/977093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.openqa; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.support.events.EventFiringWebDriver; | |
import org.openqa.selenium.support.events.WebDriverEventListener; | |
import org.testng.annotations.BeforeMethod; | |
import org.testng.annotations.Test; | |
public class EventFiringTest { | |
private WebDriver driver = null; | |
@BeforeMethod | |
public void setup() throws MalformedURLException { | |
DesiredCapabilities ff = DesiredCapabilities.firefox(); | |
WebDriver underlyingDriver = new RemoteWebDriver(new URL("http://localhost:4444/grid/driver"), ff); | |
driver = new EventFiringWebDriver(underlyingDriver); | |
((EventFiringWebDriver)driver).register(new WebDriverEventListener() { | |
public void onException(Throwable throwable, WebDriver driver) { | |
// take screenshot + log | |
} | |
public void beforeNavigateTo(String url, WebDriver driver) { | |
// check some app scan on the URL ? | |
} | |
public void beforeNavigateForward(WebDriver driver) { | |
// check some app scan on the URL ? | |
} | |
// etc. Lots of events in the intf | |
} | |
}) | |
} | |
@Test | |
public void test() throws MalformedURLException, InterruptedException { | |
try { | |
driver.get("url"); | |
WebElement el = driver.findElement(By.id("text")); | |
el.click(); | |
} finally { | |
if (driver != null) { | |
driver.quit(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment