Created
August 24, 2012 06:52
-
-
Save krmahadevan/3446856 to your computer and use it in GitHub Desktop.
A sample program that shows EventFiringWebDriver doesnt generate events with Actions class
This file contains hidden or 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 raw.selenium; | |
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.interactions.Actions; | |
import org.openqa.selenium.internal.WrapsElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.support.events.AbstractWebDriverEventListener; | |
import org.openqa.selenium.support.events.EventFiringWebDriver; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
public class EventFiringWebDriverDemo { | |
private EventFiringWebDriver efd = null; | |
@Test | |
public void testMethod() { | |
efd.get("http://cgi-lib.berkeley.edu/ex/fup.html"); | |
WebElement element = efd.findElement(By.name("note")); | |
//The below 4 lines which relies on Action doesnot trigger events | |
Actions action = new Actions(efd.getWrappedDriver()); | |
WrapsElement wrappedElement = (WrapsElement)element; | |
action.sendKeys(wrappedElement.getWrappedElement(), "Hello world").build().perform(); | |
//However the below line which uses the regular way of clicking does work | |
element.sendKeys("Hello world"); | |
} | |
@BeforeClass | |
public void beforeClass() throws MalformedURLException { | |
DesiredCapabilities dc = new DesiredCapabilities(); | |
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); | |
URL url = new URL("http://localhost:4444/wd/hub"); | |
RemoteWebDriver rwd = new RemoteWebDriver(url, dc); | |
efd = new EventFiringWebDriver(rwd); | |
efd.register(new MyEventListener()); | |
} | |
@AfterClass | |
public void afterClass() { | |
efd.quit(); | |
} | |
public static class MyEventListener extends AbstractWebDriverEventListener { | |
@Override | |
public void afterChangeValueOf(WebElement element, WebDriver driver) { | |
super.afterChangeValueOf(element, driver); | |
System.out.println("afterChangeValueOf was invoked"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment