我无法触发EventFiringWebDriver

时间:2018-03-21 23:19:18

标签: java selenium-webdriver webdriver remotewebdriver

我无法触发EventFiringWebDriver。 Selenium没有触发logs.It只显示默认的log4j日志。我试过搜索遍布谷歌和stackoverflow仍然无法解决问题。由于没有错误,我无法进行任何重新搜索,我感到困惑。 请参阅下面的课程,这些课程对我到目前为止所做的工作提供了一些想法。我坚持这个问题。请指教。

我已在我的浏览器类中声明了EventFiringWebDriver,如下所示。

import org.openqa.selenium.support.events.EventFiringWebDriver;
public class BrowserFactory {

    // test comment
    static WebDriver driver;
    public  static EventFiringWebDriver e_driver;
    public static WebEventListener eventListener;

    public static WebDriver selectBrowser(String browserName) {
        String workingDir = System.getProperty("user.dir");

        switch (browserName) {
        case "ie":
            System.setProperty("webdriver.ie.driver", workingDir+ "\\Drivers\\MicrosoftWebDriver.exe");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            DesiredCapabilities.internetExplorer();
            driver = new InternetExplorerDriver(capabilities);

            break;

        case "chrome":
            System.setProperty("webdriver.chrome.driver",workingDir+ "\\Drivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("chrome.switches", "--disable-extensions");
                    break;
                    }

                    e_driver = new EventFiringWebDriver(driver);
        // Now create object of EventListerHandler to register it with EventFiringWebDriver
        eventListener = new WebEventListener();
        e_driver.register(eventListener);
        driver = e_driver;


        if (driver == null) {
            System.out.println("you have given browser name as " + browserName);
        } else {
            driver.manage().window().maximize();
            // waiting for each next element in the DOM
            driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
        }
        return driver;
    }

}

我的WebEventListener如下

   import java.io.IOException;

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



    public class WebEventListener implements WebDriverEventListener {

        public void beforeNavigateTo(String url, WebDriver driver) {
            System.out.println("Before navigating to: '" + url + "'");
        }

        public void afterNavigateTo(String url, WebDriver driver) {
            System.out.println("Navigated to:'" + url + "'");
        }

        public void beforeChangeValueOf(WebElement element, WebDriver driver) {
            System.out.println("Value of the:" + element.toString() + " before any changes made");
        }

        public void afterChangeValueOf(WebElement element, WebDriver driver) {
            System.out.println("Element value changed to: " + element.toString());
        }

        public void beforeClickOn(WebElement element, WebDriver driver) {
            System.out.println("Trying to click on: " + element.toString());
        }

        public void afterClickOn(WebElement element, WebDriver driver) {
            System.out.println("Clicked on: " + element.toString());
        }

        public void beforeNavigateBack(WebDriver driver) {
            System.out.println("Navigating back to previous page");
        }

        public void afterNavigateBack(WebDriver driver) {
            System.out.println("Navigated back to previous page");
        }

        public void beforeNavigateForward(WebDriver driver) {
            System.out.println("Navigating forward to next page");
        }

        public void afterNavigateForward(WebDriver driver) {
            System.out.println("Navigated forward to next page");
        }

        public void onException(Throwable error, WebDriver driver) {
            System.out.println("Exception occurred: " + error);

        }

        public void beforeFindBy(By by, WebElement element, WebDriver driver) {
            System.out.println("Trying to find Element By : " + by.toString());
        }

        public void afterFindBy(By by, WebElement element, WebDriver driver) {
            System.out.println("Found Element By : " + by.toString());
        }

        /*
         * non overridden methods of WebListener class
         */
        public void beforeScript(String script, WebDriver driver) {
        }

        public void afterScript(String script, WebDriver driver) {
        }

        public void beforeAlertAccept(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void afterAlertAccept(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void afterAlertDismiss(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void beforeAlertDismiss(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void beforeNavigateRefresh(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void afterNavigateRefresh(WebDriver driver) {
            // TODO Auto-generated method stub

        }

        public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
            // TODO Auto-generated method stub

        }

        public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
            // TODO Auto-generated method stub

        }

我的主要课程如下

public class ReportFormatting {
private EventFiringWebDriver driver;
    openreport = new OpenReport(driver);
    createContentMenuButton = new ContentMenuButton(driver);
    reportView = new ViewForReport(driver);
    chartTitle = new ChartTitle(driver);
    iMaps = new ImageMaps(driver);
    chartSettings = new ChartSettings(driver);
    chartValidation = new ChartValidationHelper(driver);
    reportFormattingPage = new ReportFormattingPage(driver);

}

@Parameters({ "userName", "passsword", "viewName", "rf1", "rf2", "rf3", "rf4", "rf5", "fontType" ,"fontSize"})
@Test(testName = "validateDataSection", enabled = true, groups = {"Report Formatting : Data"}, alwaysRun = true, priority=1)
public void ValidateDataSection(String username, String password, String viewName, String r1, String r2, String r3, String r4, String r5, String ftype, String fsize) throws InterruptedException, AWTException {
    log.info("****************************** starting test case *****************************************");
    login.loginToTenant(username, password);
    // select view from content menu button
    createContentMenuButton.setContentMenuButton();
    // choose view
    reportView.selectView(viewName);
    // create the report in report builder
    createChart.createReport(r1, r2, r3, r4, r5);

    //Checks the style "Font Type, Font Size, Bold Italic"
    reportFormattingPage.DataSection(ftype,fsize);

    // Access Row Highlight
    reportFormattingPage.RowHighlight();

    logout.performLogout();
    log.info("****************************** ending test case *****************************************");

}

0 个答案:

没有答案