Search in sources :

Example 76 with ChromeDriver

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

the class Settings method setUp.

public void setUp() {
    File file = new File(DRIVER_FILE_PATH);
    System.setProperty(DRIVER_NAME, file.getAbsolutePath());
    HashMap<String, Object> chromeOptions = new HashMap<>();
    chromeOptions.put("profile.default_content_settings.popups", 0);
    chromeOptions.put("download.default_directory", downloadFolder);
    chromeOptions.put("download.prompt_for_download", false);
    chromeOptions.put("--no-startup-window", true);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromeOptions);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(cap);
    builder = new Actions(driver);
    LOG.info("Driver setUp complete.");
}
Also used : HashMap(java.util.HashMap) Actions(org.openqa.selenium.interactions.Actions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 77 with ChromeDriver

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

the class BaseTest method beforeClass.

@SuppressWarnings("deprecation")
@BeforeClass
public void beforeClass() throws IOException {
    /*	 TODO: TripadvisorTest: observed user agent problem with firefox - mobile version of
				 page is rendered, and the toast message displayed with the warning:
				 "We noticed that you're using an unsupported browser. The TripAdvisor
		     website may not display properly.We support the following browsers:
				 Windows: Internet Explorer, Mozilla Firefox, Google Chrome. Mac:
				 Safari".
		*/
    System.err.println("Launching " + browser);
    if (browser.equals("chrome")) {
        System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeOptions chromeOptions = new ChromeOptions();
        Map<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.prompt_for_download", "false");
        chromePrefs.put("download.directory_upgrade", "true");
        chromePrefs.put("plugins.always_open_pdf_externally", "true");
        chromePrefs.put("download.default_directory", downloadFilepath);
        chromePrefs.put("enableNetwork", "true");
        chromeOptions.setExperimentalOption("prefs", chromePrefs);
        for (String optionAgrument : (new String[] { "--user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0", "--allow-running-insecure-content", "--allow-insecure-localhost", "--enable-local-file-accesses", "--disable-notifications", "--disable-save-password-bubble", /* "start-maximized" , */
        "--browser.download.folderList=2", "--disable-web-security", "--no-proxy-server", "--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"  , */
        })) {
            chromeOptions.addArguments(optionAgrument);
        }
        // chromeOptions.addArguments("user-data-dir=/path/to/your/custom/profile");
        // options for headless
        /*
			for (String optionAgrument : (new String[] { "headless",
					"window-size=1200x600", })) {
				options.addArguments(optionAgrument);
			}
			*/
        capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
        capabilities.setCapability(org.openqa.selenium.chrome.ChromeOptions.CAPABILITY, chromeOptions);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        loadChromeExtensionsBase64Encoded(chromeOptions);
        // see also:
        // https://github.com/pulkitsinghal/selenium/blob/master/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java
        // For use with RemoteWebDriver
        /*
			RemoteWebDriver driver = new RemoteWebDriver(
			     new URL("http://localhost:4444/wd/hub"), capabilities);
			  */
        driver = new ChromeDriver(capabilities);
    } else if (browser.equals("firefox")) {
        // https://developer.mozilla.org/en-US/Firefox/Headless_mode
        // 3.5.3 and later
        System.setProperty("webdriver.gecko.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/geckodriver.exe").getAbsolutePath() : "/tmp/geckodriver");
        System.setProperty("webdriver.firefox.bin", osName.toLowerCase().startsWith("windows") ? new File("c:/Program Files (x86)/Mozilla Firefox/firefox.exe").getAbsolutePath() : "/usr/bin/firefox");
        // https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        // use legacy FirefoxDriver
        capabilities.setCapability("marionette", false);
        // http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
        capabilities.setCapability("locationContextEnabled", false);
        capabilities.setCapability("acceptSslCerts", true);
        capabilities.setCapability("elementScrollBehavior", 1);
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAcceptUntrustedCertificates(true);
        profile.setAssumeUntrustedCertificateIssuer(true);
        profile.setEnableNativeEvents(false);
        // optional
        /* 
			 profile.setPreference("general.useragent.override",
			 		"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0");
			*/
        // System.out.println(System.getProperty("user.dir"));
        capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        try {
            driver = new FirefoxDriver(capabilities);
        } catch (WebDriverException e) {
            e.printStackTrace();
            throw new RuntimeException("Cannot initialize Firefox driver");
        }
    }
    actions = new Actions(driver);
    driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
    // Declare a wait time
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    screenshot = ((TakesScreenshot) driver);
    js = ((JavascriptExecutor) driver);
    // driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS);
    // Go to URL
    driver.get(baseURL);
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) HashMap(java.util.HashMap) Actions(org.openqa.selenium.interactions.Actions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) TakesScreenshot(org.openqa.selenium.TakesScreenshot) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) BeforeClass(org.testng.annotations.BeforeClass)

Example 78 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project irida by phac-nml.

the class IntegrationUITestListener method startWebDriver.

/**
 * Start the web driver.
 */
public static void startWebDriver() {
    ChromeOptions options = new ChromeOptions();
    /*
		 * Run chrome in no sandbox mode. Only use this option for running tests
		 * in docker containers.
		 */
    String noSandbox = System.getProperty("irida.it.nosandbox");
    if (noSandbox != null && noSandbox.equals("true")) {
        logger.warn("Running Chrome in no sandbox mode");
        options.addArguments("--no-sandbox");
    }
    // Run chrome in headless mode
    String headless = System.getProperty("irida.it.headless");
    if (headless != null && headless.equals("true")) {
        logger.info("Running Chome in headless mode");
        options.addArguments("headless");
    } else {
        logger.info("Running Chome in no headless (normal) mode");
    }
    options.addArguments("window-size=1400x900");
    driver = new ChromeDriver(options);
    driver.manage().timeouts().implicitlyWait(DRIVER_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 79 with ChromeDriver

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

the class RunAllTests method RunAllActions.

public void RunAllActions(SeleniumTestTool STAppFrame, SeleniumTestToolData STAppData, String TargetBrowser, String OSType) {
    STAppData.TimeOfRun = LocalDateTime.now();
    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 Marionette driver:" + ex.toString(), false, 0, 0);
            }
            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: " + ex.toString(), false, 0, 0);
            }
            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) {
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch IEdriver:" + ex.toString(), false, 0, 0);
            }
            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) {
                Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch IEdriver: " + ex.toString(), false, 0, 0);
            }
            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." + ex.toString(), false, 0, 0);
            }
            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." + ex.toString(), false, 0, 0);
            }
            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. " + ex.toString(), false, 0, 0);
            }
            break;
    }
    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;
    int thisbugindex = 0;
    for (Procedure thisbug : STAppData.BugArray) {
        String bugtitle = STAppData.BugArray.get(thisbugindex).getBugTitle();
        if (RUNWITHGUI) {
            LoudCall<Void, String> procMethod = new LoudCall<Void, String>() {

                @Override
                public Void call() throws Exception {
                    shoutOut(bugtitle);
                    Thread.sleep(100);
                    return null;
                }
            };
            (new ListenerTask<Void, String>(procMethod) {

                @Override
                protected void process(List<String> chunks) {
                    STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                }
            }).execute();
            STAppFrame.BugViewArray.get(thisbugindex).JButtonRunTest.setText("Running...");
        }
        int bug_INT = thisbugindex + 1;
        String bug_ID = Integer.toString(bug_INT);
        int action_INT = 0;
        String action_ID = "";
        if (!"Dataloop".equals(thisbug.Type)) {
            action_INT = 0;
            for (Action ThisAction : thisbug.ActionsList) {
                if (STAppData.cancelled) {
                    publish(thisbugindex);
                    break;
                }
                waitWhenPaused();
                action_INT++;
                action_ID = Integer.toString(action_INT);
                if (!ThisAction.Locked) {
                    if (RUNWITHGUI) {
                        String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
                        LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {

                            @Override
                            public Void call() throws Exception {
                                shoutOut(action_title);
                                Thread.sleep(100);
                                return null;
                            }
                        };
                        (new ListenerTask<Void, String>(actMethod) {

                            @Override
                            protected void process(List<String> chunks) {
                                if (chunks.size() > 0) {
                                    STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                                }
                            }
                        }).execute();
                    }
                    if (totalpause > 0) {
                        try {
                            Thread.sleep(totalpause);
                        } catch (Exception ex) {
                            System.out.println("Exception when sleeping: " + ex.toString());
                            ThisAction.Pass = false;
                            if (RUNWITHGUI) {
                                ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                                thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
                                publish(thisbugindex);
                            }
                            break;
                        }
                    }
                    String varfieldname = "";
                    if (ThisAction.Variable2.contains("[stored_varname-start]") || ThisAction.Variable1.contains("[stored_varname-start]")) {
                        if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                            varfieldname = ThisAction.Variable1;
                            // indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
                            // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                            String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
                            String fieldname = split_testfield_end[0].substring(22);
                            ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
                            ThisAction.RunAction(driver);
                            ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                        } else {
                            if (ThisAction.Variable1.contains("[stored_varname-start]")) {
                                varfieldname = ThisAction.Variable1;
                                // indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
                                // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
                                String fieldname = split_testfield_end[0].substring(22);
                                ThisAction.Variable1 = STAppData.GetStoredVariableValue(fieldname);
                                ThisAction.RunAction(driver);
                                ThisAction.Variable1 = "[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 (RUNWITHGUI) {
                            ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                            thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
                        }
                    }
                    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);
                    }
                    if (STAppData.getIncludeScreenshots()) {
                        try {
                            File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                            full_scrn.deleteOnExit();
                            ThisAction.ScreenshotBase64 = "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>";
                        } catch (Exception ex) {
                            ThisAction.ScreenshotBase64 = "Screenshot Failed";
                        // System.out.println("Exception creating screenshot: " + ex.toString());
                        }
                    } else {
                        ThisAction.ScreenshotBase64 = "";
                    }
                } else {
                    ThisAction.ScreenshotBase64 = "";
                    ThisAction.Pass = true;
                }
                if (RUNWITHGUI) {
                    ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                    thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
                }
            }
            int actionspassed = 0;
            for (Action thisaction : thisbug.ActionsList) {
                Boolean passvalue = thisaction.Pass;
                if (passvalue) {
                    actionspassed++;
                }
            }
            int sizeof = thisbug.ActionsList.size();
            if (actionspassed == sizeof) {
                thisbug.Pass = true;
            } else {
                thisbug.Pass = false;
            }
        } else {
            int number_of_rows = 0;
            if ("urllist".equals(thisbug.DataLoopSource)) {
                if (thisbug.getLimit() > 0 || thisbug.getRandom()) {
                    thisbug.setURListRunTimeData(STAppData.RandomizeAndLimitURLList(thisbug.URLListName, thisbug.getLimit(), thisbug.getRandom()), thisbug.URLListName);
                } else {
                    thisbug.setURListRunTimeData(STAppData.VarLists.get(thisbug.URLListName), thisbug.URLListName);
                }
                number_of_rows = thisbug.URLListRunTimeEntries.size();
                if (RUNWITHGUI) {
                    if (number_of_rows > 0) {
                        ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                        thisbugview.setJTableSourceToURLList(thisbug.URLListRunTimeEntries, thisbug.URLListName);
                    }
                }
            } else {
                if ("file".equals(thisbug.DataLoopSource)) {
                    if (thisbug.getLimit() > 0 || thisbug.getRandom()) {
                        if (STAppData.getDataSetByFileName(thisbug.DataFile).size() > 0) {
                            List<String[]> randomList = STAppData.RandomizeAndLimitFileList(STAppData.getDataSetByFileName(thisbug.DataFile), thisbug.getLimit(), thisbug.getRandom());
                            thisbug.setRunTimeFileSet(randomList);
                        }
                    } else {
                        thisbug.setRunTimeFileSet(STAppData.getDataSetByFileName(thisbug.DataFile));
                    }
                    number_of_rows = thisbug.RunTimeFileSet.size();
                }
            }
            for (Action ThisAction : thisbug.ActionsList) {
                ThisAction.InitializeLoopTestVars(number_of_rows);
            }
            for (int x = 0; x < number_of_rows; x++) {
                int changex = -1;
                action_INT = 0;
                for (Action ThisAction : thisbug.ActionsList) {
                    if (STAppData.cancelled) {
                        publish(thisbugindex);
                        break;
                    }
                    waitWhenPaused();
                    action_INT++;
                    action_ID = Integer.toString(action_INT) + "-" + Integer.toString(x);
                    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);
                                ThisAction.loop_pass_values.set(x, ThisAction.Pass);
                                ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
                                if (STAppData.getIncludeScreenshots()) {
                                    ThisAction.loop_ScreenshotsBase64.set(x, "<img id = \"Screenshot" + bug_ID + "-" + action_ID + "\" class = \"report_screenshots\" style = \"display: none;\" src=\"\"></img>");
                                } else {
                                    ThisAction.loop_ScreenshotsBase64.set(x, "");
                                }
                            } else {
                                try {
                                    if (totalpause > 0) {
                                        try {
                                            Thread.sleep(totalpause);
                                        } catch (Exception ex) {
                                            System.out.println("Exception when sleeping: " + ex.toString());
                                            ThisAction.Pass = false;
                                            publish(thisbugindex);
                                            if (RUNWITHGUI) {
                                                ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                                                thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
                                            }
                                            break;
                                        }
                                    }
                                    String varfieldname = "";
                                    if (ThisAction.Variable2.contains("[stored_varname-start]") || ThisAction.Variable1.contains("[stored_varname-start]")) {
                                        if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                                            varfieldname = ThisAction.Variable1;
                                            // indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
                                            // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                            String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
                                            String fieldname = split_testfield_end[0].substring(22);
                                            ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
                                            String action_title3 = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
                                            if (RUNWITHGUI) {
                                                LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {

                                                    @Override
                                                    public Void call() throws Exception {
                                                        shoutOut(action_title3);
                                                        Thread.sleep(100);
                                                        return null;
                                                    }
                                                };
                                                (new ListenerTask<Void, String>(actMethod) {

                                                    @Override
                                                    protected void process(List<String> chunks) {
                                                        if (chunks.size() > 0) {
                                                            STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                                                        }
                                                    }
                                                }).execute();
                                            }
                                            ThisAction.RunAction(driver);
                                            ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                                        } else {
                                            if (ThisAction.Variable1.contains("[stored_varname-start]")) {
                                                varfieldname = ThisAction.Variable1;
                                                // indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
                                                // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                                String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
                                                String fieldname = split_testfield_end[0].substring(22);
                                                ThisAction.Variable1 = STAppData.GetStoredVariableValue(fieldname);
                                                if (RUNWITHGUI) {
                                                    String action_title2 = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
                                                    LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {

                                                        @Override
                                                        public Void call() throws Exception {
                                                            shoutOut(action_title2);
                                                            Thread.sleep(100);
                                                            return null;
                                                        }
                                                    };
                                                    (new ListenerTask<Void, String>(actMethod) {

                                                        @Override
                                                        protected void process(List<String> chunks) {
                                                            if (chunks.size() > 0) {
                                                                STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                                                            }
                                                        }
                                                    }).execute();
                                                }
                                                ThisAction.RunAction(driver);
                                                ThisAction.Variable1 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                                            }
                                        }
                                    } else {
                                        if (RUNWITHGUI) {
                                            String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
                                            LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {

                                                @Override
                                                public Void call() throws Exception {
                                                    shoutOut(action_title);
                                                    Thread.sleep(100);
                                                    return null;
                                                }
                                            };
                                            (new ListenerTask<Void, String>(actMethod) {

                                                @Override
                                                protected void process(List<String> chunks) {
                                                    if (chunks.size() > 0) {
                                                        STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                                                    }
                                                }
                                            }).execute();
                                        }
                                        ThisAction.RunAction(driver);
                                    }
                                    if (!"".equals(ThisAction.tostore_varvalue)) {
                                        STAppData.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
                                    }
                                    ThisAction.loop_pass_values.set(x, ThisAction.Pass);
                                    ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
                                } catch (Exception ex) {
                                    ThisAction.loop_pass_values.set(x, false);
                                    ThisAction.loop_time_of_test.set(x, LocalDateTime.now());
                                    if (RUNWITHGUI) {
                                        publish(thisbugindex);
                                        ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                                        thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
                                    }
                                    break;
                                }
                                if (STAppData.getIncludeScreenshots()) {
                                    try {
                                        File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                                        full_scrn.deleteOnExit();
                                        ThisAction.loop_ScreenshotsBase64.set(x, "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>");
                                    } catch (Exception ex) {
                                        ThisAction.loop_ScreenshotsBase64.set(x, "Screenshot Failed");
                                    // System.out.println("Exception creating screenshot: " + ex.toString());
                                    }
                                } else {
                                    ThisAction.loop_ScreenshotsBase64.set(x, "");
                                }
                            }
                        } else {
                            String concat_variable = "";
                            String concat_variable2 = "";
                            if ("urllist".equals(thisbug.DataLoopSource)) {
                                concat_variable = var1Parser.GetFullValueFromURLList(x, thisbug.URLListRunTimeEntries);
                            }
                            if ("file".equals(thisbug.DataLoopSource)) {
                                concat_variable = var1Parser.GetFullValueFromFile(x, thisbug.RunTimeFileSet);
                            }
                            if (var1Parser.hasDataLoopVar) {
                                ThisAction.Variable1 = concat_variable;
                                if ("".equals(ThisAction.Variable1)) {
                                    ThisAction.Variable1 = " ";
                                }
                            }
                            if ("urllist".equals(thisbug.DataLoopSource)) {
                                concat_variable2 = var2Parser.GetFullValueFromURLList(x, thisbug.URLListRunTimeEntries);
                            }
                            if ("file".equals(thisbug.DataLoopSource)) {
                                concat_variable2 = var2Parser.GetFullValueFromFile(x, thisbug.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;
                                        if (RUNWITHGUI) {
                                            publish(thisbugindex);
                                            ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                                            thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
                                        }
                                        break;
                                    }
                                }
                                if (RUNWITHGUI) {
                                    String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
                                    LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {

                                        @Override
                                        public Void call() throws Exception {
                                            shoutOut(action_title);
                                            Thread.sleep(100);
                                            return null;
                                        }
                                    };
                                    (new ListenerTask<Void, String>(actMethod) {

                                        @Override
                                        protected void process(List<String> chunks) {
                                            if (chunks.size() > 0) {
                                                STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
                                            }
                                        }
                                    }).execute();
                                }
                                ThisAction.RunAction(driver);
                                ThisAction.Variable1 = original_value1;
                                ThisAction.Variable2 = original_value2;
                                ThisAction.loop_pass_values.set(x, ThisAction.Pass);
                                ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
                                if (STAppData.getIncludeScreenshots()) {
                                    try {
                                        File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                                        full_scrn.deleteOnExit();
                                        ThisAction.loop_ScreenshotsBase64.set(x, "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>");
                                    } catch (Exception ex) {
                                        ThisAction.loop_ScreenshotsBase64.set(x, "Screenshot Failed");
                                    // System.out.println("Exception creating screenshot: " + ex.toString());
                                    }
                                } else {
                                    ThisAction.loop_ScreenshotsBase64.set(x, "");
                                }
                            } catch (Exception ex) {
                                ThisAction.Variable1 = original_value1;
                                ThisAction.Variable2 = original_value2;
                                ThisAction.loop_pass_values.set(x, false);
                                ThisAction.loop_time_of_test.set(x, LocalDateTime.now());
                                if (RUNWITHGUI) {
                                    ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                                    thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
                                    publish(thisbugindex);
                                }
                                break;
                            }
                        }
                    } else {
                        ThisAction.Pass = true;
                        ThisAction.loop_pass_values.set(x, ThisAction.Pass);
                        ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
                    }
                    if (RUNWITHGUI) {
                        ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
                        thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
                    }
                }
                if (changex != x) {
                    if (changex == -1) {
                    } else {
                        x = changex - 1;
                    }
                }
            }
            // check if all actions passed
            int actions_passed = 0;
            for (Action ThisAction : thisbug.ActionsList) {
                ThisAction.Pass = false;
                int loop_actions_passed = 0;
                if (ThisAction.loop_pass_values.size() > 0) {
                    for (Boolean passvalue : ThisAction.loop_pass_values) {
                        if (passvalue) {
                            loop_actions_passed++;
                        }
                    }
                }
                if (loop_actions_passed == ThisAction.loop_pass_values.size()) {
                    ThisAction.Pass = true;
                }
                if (ThisAction.Pass) {
                    actions_passed++;
                }
            }
            int sizeof = thisbug.ActionsList.size();
            if (actions_passed == sizeof) {
                thisbug.Pass = true;
            } else {
                thisbug.Pass = false;
            }
        }
        publish(thisbugindex);
        thisbugindex++;
    }
    if (STAppData.getPromptToClose() && driver != null) {
        PromptToClose thisContinuePrompt = new PromptToClose(STAppData.short_filename + " - Prompt to close webdriver", "Close webdriver/browser?");
        thisContinuePrompt.addjButtonRunAgainActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                RunAgain = true;
                thisContinuePrompt.dispose();
                boolean closecaught = false;
                try {
                    if (driver != null) {
                        driver.close();
                    }
                } catch (Exception e) {
                    closecaught = true;
                    System.out.println(e.toString());
                    try {
                        driver.quit();
                    } catch (Exception exce) {
                        System.out.println("Exception quitting" + exce.toString());
                    }
                }
                if (closecaught) {
                } else {
                    try {
                        driver.quit();
                    } catch (Exception ex) {
                    // don't worry it should close
                    }
                }
            }
        });
        thisContinuePrompt.addjButtonCloseActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                RunAgain = false;
                thisContinuePrompt.dispose();
            }
        });
        while (thisContinuePrompt.isVisible() == true) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                System.out.println("pause exception: " + e.toString());
            }
        }
        if (RunAgain) {
            RunAllActions(STAppFrame, STAppData, targetbrowser, OSType);
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ArrayList(java.util.ArrayList) List(java.util.List) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) TakesScreenshot(org.openqa.selenium.TakesScreenshot) ActionListener(java.awt.event.ActionListener) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File)

Example 80 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project chrome_page_performance_sqlite_java by sergueik.

the class ChromePagePerformanceUtil method getLoadTime.

public double getLoadTime(String endUrl) {
    WebDriver driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, flexibleWait);
    driver.navigate().to(endUrl);
    waitPageToLoad(driver, wait);
    setTimer(driver);
    return calculateLoadTime();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)91 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)41 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)39 File (java.io.File)33 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)27 WebDriver (org.openqa.selenium.WebDriver)24 HashMap (java.util.HashMap)21 Before (org.junit.Before)13 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)13 URL (java.net.URL)11 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)11 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)11 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)11 Test (org.junit.Test)10 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)9 Actions (org.openqa.selenium.interactions.Actions)9 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)9 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)7 SafariDriver (org.openqa.selenium.safari.SafariDriver)7