WebDriverEventListener不跟踪浏览器事件

时间:2017-07-03 06:39:48

标签: selenium-webdriver

我正在尝试在程序中实现WebDriverEventListener来跟踪事件。但是,我无法看到任何被跟踪的内容。如果我错过了这里的某些内容,请告诉我。

以下是实现WebDriverEventListener

的EventHandler类
public class EventHandler implements WebDriverEventListener {

    public void afterChangeValueOf(WebElement arg0, WebDriver arg1) {
        // TODO Auto-generated method stub

        System.out.println("inside method afterChangeValueOf on " + arg0.toString());
    }

    public void afterClickOn(WebElement arg0, WebDriver arg1) {
        // TODO Auto-generated method stub
        System.out.println("inside method afterClickOn on " + arg0.toString());
    }

    public void afterFindBy(By arg0, WebElement arg1, WebDriver arg2) {
        // TODO Auto-generated method stub
        System.out.println("Find happened on " + arg1.toString() 
                + " Using method " + arg0.toString());
    }

    public void afterNavigateBack(WebDriver arg0) {
        // TODO Auto-generated method stub

        System.out.println("Inside the after navigateback to " + arg0.getCurrentUrl());
    }

    public void afterNavigateForward(WebDriver arg0) {
        // TODO Auto-generated method stub
        System.out.println("Inside the afterNavigateForward to " + arg0.getCurrentUrl());
    }

    public void afterNavigateTo(String arg0, WebDriver arg1) {
        // TODO Auto-generated method stub
        System.out.println("Inside the afterNavigateTo to " + arg0);
    }
}

这是我正在实施测试用例的程序:

public class TestProgram4 {

    EventFiringWebDriver e_driver;
    EventHandler eventListener;
    WebDriver driver;

    //Copy text from Browser and paste to a file
    @Test
    public void testMethod4(){



        String data = null;
        String pathGeckoDriver = System.getProperty("user.dir")+"\\executables\\geckodriver.exe";
        System.out.println(pathGeckoDriver);
        System.setProperty("webdriver.gecko.driver",pathGeckoDriver);
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        driver = new MarionetteDriver(capabilities); 
//      driver = new FirefoxDriver();

        e_driver = new EventFiringWebDriver(driver);
        eventListener = new EventHandler();
        e_driver.register(eventListener);

        driver.get("file:\\C:\\Users\\AXM1033183\\Desktop\\Sample.html");
//      driver.get("http://www.google.com");
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        try {
            Thread.sleep(2000);
        } catch (Exception e1) {
        }
        WebElement element = driver.findElement(By.xpath("//input"));
        element.click();
        element.sendKeys("Test");
        element.sendKeys(Keys.CONTROL,"a");
        element.sendKeys(Keys.CONTROL,"c");

}

}

1 个答案:

答案 0 :(得分:0)

问题已解决。我必须在我的测试脚本中使用e_driver而不是驱动程序来执行浏览器操作。