Search in sources :

Example 11 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project browsermator by pcalkins.

the class RunASingleTest method RunSingleTest.

public void RunSingleTest(Procedure bugtorun, ProcedureView thisbugview, String TargetBrowser, String OSType) {
    STAppFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    File thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
    switch(TargetBrowser) {
        case "Firefox-Marionette":
            if ("Windows".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win32"+File.separator+"geckodriver.exe");
            }
            if ("Windows32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win32"+File.separator+"geckodriver.exe");
            }
            if ("Windows64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win64" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win64"+File.separator+"geckodriver.exe");
            }
            if ("Mac".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-osx" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-osx"+File.separator+"geckodriver");
            }
            if ("Linux-32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux32" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-linux32"+File.separator+"geckodriver");
            }
            if ("Linux-64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux64" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-linux64"+File.separator+"geckodriver");
            }
            if (firefox_path != null) {
                System.setProperty("webdriver.firefox.bin", firefox_path);
            }
            try {
                // FirefoxProfile profile = new FirefoxProfile();
                // DesiredCapabilities cap = DesiredCapabilities.firefox();
                // cap.setJavascriptEnabled(true);
                // cap.setCapability("marionette", false);
                // profile.setPreference("dom.max_script_run_time", 1);
                driver = new FirefoxDriver();
            // driver =  new MarionetteDriver();
            } catch (Exception ex) {
                System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Marionette driver, will fallback to HTMLUnitDriver", false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Firefox":
            if ("Windows".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            }
            if ("Windows32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            }
            if ("Windows64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win64" + File.separator + "geckodriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-win64"+File.separator+"geckodriver.exe");
            }
            if ("Mac".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-osx" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-osx"+File.separator+"geckodriver");
            }
            if ("Linux-32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux32" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver",BMPATH+File.separator+ "lib"+File.separator+"geckodriver-linux32"+File.separator+"geckodriver");
            }
            if ("Linux-64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux64" + File.separator + "geckodriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-linux64"+File.separator+"geckodriver");
            }
            if (firefox_path != null) {
                System.setProperty("webdriver.firefox.bin", firefox_path);
            }
            try {
                // DesiredCapabilities cap = DesiredCapabilities.firefox();
                // cap.setJavascriptEnabled(false);
                // FirefoxProfile profile = new FirefoxProfile();
                // DesiredCapabilities cap = DesiredCapabilities.firefox();
                // cap.setJavascriptEnabled(true);
                // cap.setCapability("marionette", true);
                // profile.setPreference("dom.max_script_run_time", 30);
                driver = new FirefoxDriver();
            // driver =  new MarionetteDriver();
            } catch (Exception ex) {
                System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Marionette driver, will fallback to HTMLUnitDriver", false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Silent Mode (HTMLUnit)":
            driver = new HtmlUnitDriver();
            break;
        case "Internet Explorer-32":
            thisDriver = new File(WEBDRIVERSDIR + "iedriverserver_win32" + File.separator + "IEDriverServer.exe");
            setPermissions(thisDriver);
            System.setProperty("webdriver.ie.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.ie.driver", BMPATH+File.separator+"lib"+File.separator+"iedriverserver_win32"+File.separator+"IEDriverServer.exe");
            try {
                driver = new InternetExplorerDriver();
            } catch (Exception ex) {
                System.out.println("Exception launching Internet Explorer driver: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the IEdriver, will fallback to HTMLUnitDriver", false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Internet Explorer-64":
            thisDriver = new File(WEBDRIVERSDIR + "iedriverserver_win64" + File.separator + "IEDriverServer.exe");
            setPermissions(thisDriver);
            System.setProperty("webdriver.ie.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.ie.driver",BMPATH+File.separator+ "lib"+File.separator+"iedriverserver_win64"+File.separator+"IEDriverServer.exe");
            try {
                driver = new InternetExplorerDriver();
            } catch (Exception ex) {
                System.out.println("Exception launching Internet Explorer-64 driver: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the IEdriver, will fallback to HTMLUnitDriver", false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Chrome":
            // legacy support
            ChromeOptions options = new ChromeOptions();
            if (chrome_main_path != null) {
                options.setBinary(chrome_main_path);
            }
            if ("Windows".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Windows32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Windows64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Mac".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_mac64" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_mac64"+File.separator+"chromedriver");
            }
            if ("Linux-32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux32" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver",BMPATH+File.separator+ "lib"+File.separator+"chromedriver_linux32"+File.separator+"chromedriver");
            }
            if ("Linux-64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux64" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_linux64"+File.separator+"chromedriver");
            }
            try {
                driver = new ChromeDriver(options);
            } catch (Exception ex) {
                System.out.println("Problem launching Chromedriver: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Chromedriver, will fallback to HTMLUnitDriver: " + ex.toString(), false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Chrome 49":
            ChromeOptions options49 = new ChromeOptions();
            if (chrome_path != null) {
                options49.setBinary(chrome_path);
            }
            thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver-winxp.exe");
            setPermissions(thisDriver);
            System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            try {
                driver = new ChromeDriver(options49);
            } catch (Exception ex) {
                System.out.println("Problem launching Chromedriver 49: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Chrome 49 driver, will fallback to HTMLUnitDriver: " + ex.toString(), false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        case "Edge":
            thisDriver = new File(WEBDRIVERSDIR + "edgedriver" + File.separator + "MicrosoftWebDriver.exe");
            setPermissions(thisDriver);
            System.setProperty("webdriver.edge.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.edge.driver", BMPATH+File.separator+"lib"+File.separator+"edgedriver"+File.separator+"MicrosoftWebDriver.exe");
            try {
                driver = new EdgeDriver();
            } catch (Exception ex) {
                System.out.println("Problem launching EdgeDriver: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Edge Driver, will fallback to HTMLUnitDriver: " + ex.toString(), false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
            break;
        default:
            if ("Windows".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver",BMPATH+File.separator+ "lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Windows32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", WEBDRIVERSDIR+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Windows64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver",BMPATH+File.separator+ "lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
            }
            if ("Mac".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_mac64" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_mac64"+File.separator+"chromedriver");
            }
            if ("Linux-32".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux32" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_linux32"+File.separator+"chromedriver");
            }
            if ("Linux-64".equals(OSType)) {
                thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux64" + File.separator + "chromedriver");
                setPermissions(thisDriver);
                System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
            // System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_linux64"+File.separator+"chromedriver");
            }
            try {
                driver = new ChromeDriver();
            } catch (Exception ex) {
                System.out.println("Problem launching Chromedriver: " + ex.toString());
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Chromedriver, will fallback to HTMLUnit Driver: " + ex.toString(), false, 0, 0);
                FallbackDriver("HTMLUnit");
            }
    }
    int WaitTime = 0;
    WaitTime = STAppData.getWaitTime();
    // timeouts still buggy.. removed
    // int Timeout = SiteTest.getTimeout();
    // int Timeout = 5;
    // driver.manage().timeouts().implicitlyWait(Timeout, TimeUnit.SECONDS);
    // driver.manage().timeouts().pageLoadTimeout(Timeout, TimeUnit.SECONDS);
    // driver.manage().timeouts().setScriptTimeout(Timeout, TimeUnit.SECONDS);
    int totalpause = WaitTime * 1000;
    if (!"Dataloop".equals(thisbugview.Type)) {
        for (Action ThisAction : bugtorun.ActionsList) {
            if (STAppData.cancelled) {
                publish(bugtorun.index);
                break;
            }
            if (!ThisAction.Locked) {
                try {
                    if (totalpause > 0) {
                        try {
                            Thread.sleep(totalpause);
                        } catch (Exception ex) {
                            System.out.println("Exception when sleeping: " + ex.toString());
                            ThisAction.Pass = false;
                            break;
                        }
                    }
                    String varfieldname = "";
                    if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                        varfieldname = ThisAction.Variable2;
                        int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                        // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                        String fieldname = varfieldname.substring(22, indexof_end_tag);
                        ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
                        ThisAction.RunAction(driver);
                        ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                    } else {
                        if ("Pause with Continue Button".equals(ThisAction.Type)) {
                            int nothing = ThisAction.RunAction(driver, "Actions Paused...", STAppData, 0, 0);
                        } else {
                            ThisAction.RunAction(driver);
                        }
                    }
                    if (!"".equals(ThisAction.tostore_varvalue)) {
                        STAppData.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
                    }
                    if (ThisAction.tostore_varlist.size() > 0) {
                        STAppData.VarLists.put(ThisAction.Variable2, ThisAction.tostore_varlist);
                    }
                } catch (Exception ex) {
                    break;
                }
            } else {
                ThisAction.Pass = true;
            }
        }
    } else {
        int number_of_rows = thisbugview.DataTable.getRowCount();
        for (int x = 0; x < number_of_rows; x++) {
            int changex = -1;
            for (Action ThisAction : bugtorun.ActionsList) {
                if (STAppData.cancelled) {
                    publish(bugtorun.index);
                    break;
                }
                String original_value1 = ThisAction.Variable1;
                String original_value2 = ThisAction.Variable2;
                if (!ThisAction.Locked) {
                    DataLoopVarParser var1Parser = new DataLoopVarParser(ThisAction.Variable1);
                    DataLoopVarParser var2Parser = new DataLoopVarParser(ThisAction.Variable2);
                    if (var1Parser.hasDataLoopVar == false && var2Parser.hasDataLoopVar == false) {
                        if ("Pause with Continue Button".equals(ThisAction.Type)) {
                            String pause_message = "Paused at record " + (x + 1) + " of " + number_of_rows;
                            changex = ThisAction.RunAction(driver, pause_message, STAppData, x, number_of_rows);
                        } else
                            try {
                                if (totalpause > 0) {
                                    try {
                                        Thread.sleep(totalpause);
                                    } catch (Exception ex) {
                                        System.out.println("Exception when sleeping: " + ex.toString());
                                        ThisAction.Pass = false;
                                        publish(bugtorun.index);
                                        break;
                                    }
                                }
                                String varfieldname = "";
                                if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                                    varfieldname = ThisAction.Variable2;
                                    int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                                    // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                    String fieldname = varfieldname.substring(22, indexof_end_tag);
                                    ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
                                    ThisAction.RunAction(driver);
                                    ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                                } else {
                                    ThisAction.RunAction(driver);
                                }
                                if (!"".equals(ThisAction.tostore_varvalue)) {
                                    STAppData.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
                                }
                            } catch (Exception ex) {
                                ThisAction.Variable1 = original_value1;
                                ThisAction.Variable2 = original_value2;
                                break;
                            }
                    } else {
                        String concat_variable = "";
                        String concat_variable2 = "";
                        if ("urllist".equals(bugtorun.DataLoopSource)) {
                            concat_variable = var1Parser.GetFullValueFromURLList(x, bugtorun.URLListData);
                        }
                        if ("file".equals(bugtorun.DataLoopSource)) {
                            concat_variable = var1Parser.GetFullValueFromFile(x, bugtorun.RunTimeFileSet);
                        }
                        if (var1Parser.hasDataLoopVar) {
                            ThisAction.Variable1 = concat_variable;
                            if ("".equals(ThisAction.Variable1)) {
                                ThisAction.Variable1 = " ";
                            }
                        }
                        if ("urllist".equals(bugtorun.DataLoopSource)) {
                            concat_variable2 = var2Parser.GetFullValueFromURLList(x, bugtorun.URLListData);
                        }
                        if ("file".equals(bugtorun.DataLoopSource)) {
                            concat_variable2 = var2Parser.GetFullValueFromFile(x, bugtorun.RunTimeFileSet);
                        }
                        if (var2Parser.hasDataLoopVar) {
                            ThisAction.Variable2 = concat_variable2;
                            if ("".equals(ThisAction.Variable2)) {
                                ThisAction.Variable2 = " ";
                            }
                        }
                        try {
                            if (totalpause > 0) {
                                try {
                                    Thread.sleep(totalpause);
                                } catch (Exception ex) {
                                    System.out.println("Exception when sleeping: " + ex.toString());
                                    ThisAction.Pass = false;
                                    break;
                                }
                            }
                            ThisAction.RunAction(driver);
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                        } catch (Exception ex) {
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                            break;
                        }
                    }
                } else {
                    ThisAction.Pass = true;
                }
            }
            if (changex != x) {
                if (changex == -1) {
                } else {
                    x = changex - 1;
                }
            }
        }
    }
    if (STAppData.getPromptToClose()) {
        Prompter thisContinuePrompt = new Prompter(STAppData.short_filename + " - Prompt to close webdriver", "Close webdriver/browser?", false, 0, 0);
        while (thisContinuePrompt.isVisible() == true) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                System.out.println("pause exception: " + e.toString());
            }
        }
        try {
            driver.close();
        } catch (Exception e) {
            System.out.println(e.toString());
            try {
                driver.quit();
            } catch (Exception ex) {
                System.out.println(ex.toString());
            }
        }
        driver.quit();
    }
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 12 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project browsermator by pcalkins.

the class RunAllTests method FallbackDriver.

public void FallbackDriver(String fallbackdriver) {
    if ("HTMLUnit".equals(fallbackdriver)) {
        STAppData.setTargetBrowser("Silent Mode (HTMLUnit)");
        if (RUNWITHGUI) {
            STAppFrame.setTargetBrowserView("Silent Mode (HTMLUnit)");
        }
        driver = new HtmlUnitDriver();
    } else {
        STAppData.setTargetBrowser("Chrome 49");
        if (RUNWITHGUI) {
            STAppFrame.setTargetBrowserView("Chrome 49");
        }
        ChromeOptions optionsfallback49 = new ChromeOptions();
        optionsfallback49.setBinary(chrome_path);
        System.setProperty("webdriver.chrome.driver", WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver-winxp.exe");
        driver = new ChromeDriver(optionsfallback49);
    }
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 13 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project survey by markoniemi.

the class PollServiceWebDriverIT method setUp.

@Before
public void setUp() {
    // create HtmlUnitDriver or FireFoxDriver
    browser = new HtmlUnitDriver(true);
    // get tomcat port from system property
    httpPort = System.getProperty("http.port", "8082");
    httpProtocol = System.getProperty("http.protocol", "http");
}
Also used : HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Before(org.junit.Before)

Example 14 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project cucumber-jvm by cucumber.

the class RentACarSupport method createCars.

public void createCars(int availableCars) {
    WebDriver driver = new HtmlUnitDriver();
    try {
        driver.get(BASE_URL + "create");
        WebElement numberOfCarsToCreate = driver.findElement(By.id("numberOfCars"));
        numberOfCarsToCreate.clear();
        numberOfCarsToCreate.sendKeys("" + availableCars);
        WebElement createButton = driver.findElement(By.id("createButton"));
        createButton.click();
    } finally {
        driver.close();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 15 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project twitter4j by yusuke.

the class OAuthTest method getAccessToken.

private AccessToken getAccessToken(Twitter twitter, String url, RequestToken rt, String screenName, String password, boolean pinRequired) throws TwitterException {
    BrowserVersion browserVersion = BrowserVersion.getDefault();
    browserVersion.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15");
    HtmlUnitDriver driver = new HtmlUnitDriver(browserVersion);
    driver.get(rt.getAuthorizationURL());
    driver.findElement(By.name("session[username_or_email]")).sendKeys(screenName);
    driver.findElement(By.name("session[password]")).sendKeys(password);
    driver.findElement(By.id("allow")).click();
    if (pinRequired) {
        return twitter.getOAuthAccessToken(rt, driver.findElementsByTagName("code").get(0).getText());
    } else {
        String oauthVerifier = driver.getCurrentUrl().replaceFirst(".*&oauth_verifier=([a-zA-Z0-9]+)$", "$1");
        return twitter.getOAuthAccessToken(rt, oauthVerifier);
    }
}
Also used : BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Aggregations

HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)39 WebDriver (org.openqa.selenium.WebDriver)12 WebElement (org.openqa.selenium.WebElement)10 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)9 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)9 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 Before (org.junit.Before)5 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)5 Test (org.junit.Test)4 SafariDriver (org.openqa.selenium.safari.SafariDriver)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 File (java.io.File)3 URL (java.net.URL)3 TimeoutException (org.openqa.selenium.TimeoutException)3 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)3 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3