Search in sources :

Example 26 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Example 27 with HtmlUnitDriver

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

the class FileServiceWebDriverIT method setUp.

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

Example 28 with HtmlUnitDriver

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

the class UserServiceWebDriverIT method setUp.

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

Example 29 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver 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 30 with HtmlUnitDriver

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

the class RentACarSupport method getAvailableNumberOfCars.

public int getAvailableNumberOfCars() {
    WebDriver driver = new HtmlUnitDriver();
    try {
        driver.get(BASE_URL + "available");
        WebElement availableCars = driver.findElement(By.id("availableCars"));
        String availableCarsString = availableCars.getText();
        return Integer.parseInt(availableCarsString);
    } finally {
        driver.close();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Aggregations

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