Search in sources :

Example 21 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project selenium_java by sergueik.

the class MinimalTest method setup.

@BeforeClass
public static void setup() throws IOException {
    getOsName();
    System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath() : "/home/vagrant/chromedriver");
    ChromeOptions options = new ChromeOptions();
    options.setBinary(osName.toLowerCase().startsWith("windows") ? (new File("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")).getAbsolutePath() : "/usr/bin/google-chrome");
    options.addArguments("headless");
    options.addArguments("disable-gpu");
    driver = new ChromeDriver(options);
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 22 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project selenium_java by sergueik.

the class SampleTest method setup.

@BeforeClass
public static void setup() throws IOException {
    System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();
    HashMap<String, Object> chromePrefs = new HashMap<>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
    chromePrefs.put("download.default_directory", downloadFilepath);
    chromePrefs.put("enableNetwork", "true");
    options.setExperimentalOption("prefs", chromePrefs);
    for (String optionAgrument : (new String[] { "allow-running-insecure-content", "allow-insecure-localhost", "enable-local-file-accesses", "disable-notifications", /* "start-maximized" , */
    "browser.download.folderList=2", "--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf", String.format("browser.download.dir=%s", downloadFilepath) /* "user-data-dir=/path/to/your/custom/profile"  , */
    })) {
        options.addArguments(optionAgrument);
    }
    capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    driver = new ChromeDriver(capabilities);
    driver.manage().window().setSize(new Dimension(width, height));
    driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS).implicitlyWait(implicitWait, TimeUnit.SECONDS).setScriptTimeout(10, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
Also used : HashMap(java.util.HashMap) Actions(org.openqa.selenium.interactions.Actions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) Dimension(org.openqa.selenium.Dimension) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 23 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project teammates by TEAMMATES.

the class Browser method createWebDriver.

private WebDriver createWebDriver() {
    System.out.print("Initializing Selenium: ");
    String browser = TestProperties.BROWSER;
    if ("firefox".equals(browser)) {
        System.out.println("Using Firefox.");
        String firefoxPath = TestProperties.FIREFOX_PATH;
        if (!firefoxPath.isEmpty()) {
            System.out.println("Custom path: " + firefoxPath);
            System.setProperty("webdriver.firefox.bin", firefoxPath);
        }
        // Allow CSV files to be download automatically, without a download popup.
        // This method is used because Selenium cannot directly interact with the download dialog.
        // Taken from http://stackoverflow.com/questions/24852709
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.panel.shown", false);
        profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/vnd.ms-excel");
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel");
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", System.getProperty("java.io.tmpdir"));
        return new FirefoxDriver(profile);
    } else if ("chrome".equals(browser)) {
        System.out.println("Using Chrome with driver path: " + TestProperties.CHROMEDRIVER_PATH);
        System.setProperty("webdriver.chrome.driver", TestProperties.CHROMEDRIVER_PATH);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--allow-file-access-from-files");
        return new ChromeDriver(options);
    }
    System.out.println("Using " + browser + " is not supported!");
    return null;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 24 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project browsermator by pcalkins.

the class RunASingleTest method FallbackDriver.

public void FallbackDriver(String fallbackdriver) {
    if ("HTMLUnit".equals(fallbackdriver)) {
        STAppData.setTargetBrowser("Silent Mode (HTMLUnit)");
        STAppFrame.setTargetBrowserView("Silent Mode (HTMLUnit)");
        driver = new HtmlUnitDriver();
    } else {
        STAppData.setTargetBrowser("Chrome 49");
        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 25 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions 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)

Aggregations

ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)50 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)39 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)28 File (java.io.File)20 HashMap (java.util.HashMap)19 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)16 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)8 WebDriver (org.openqa.selenium.WebDriver)7 Actions (org.openqa.selenium.interactions.Actions)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 URL (java.net.URL)5 WebDriverException (org.openqa.selenium.WebDriverException)5 LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 ArrayList (java.util.ArrayList)4 BeforeClass (org.junit.BeforeClass)4 TakesScreenshot (org.openqa.selenium.TakesScreenshot)4 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)4