Search in sources :

Example 31 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project Asqatasun by Asqatasun.

the class FirefoxDriverFactory method make.

/**
     * 
     * @param config
     * @return A FirefoxDriver.
     */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY));
    } else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getenv(DISPLAY_PROPERTY.toUpperCase()));
    }
    RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile);
    if (screenHeight != -1 && screenWidth != -1) {
        remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight));
    }
    return remoteWebDriver;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Dimension(org.openqa.selenium.Dimension)

Example 32 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project Asqatasun by Asqatasun.

the class FirefoxDriverPoolableObjectFactory method makeObject.

@Override
public FirefoxDriver makeObject() throws Exception {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY_KEY) != null) {
        Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + System.getProperty(DISPLAY_PROPERTY_KEY));
        ffBinary.setEnvironmentProperty("DISPLAY", System.getProperty(DISPLAY_PROPERTY_KEY));
    }
    FirefoxDriver fd = new FirefoxDriver(ffBinary, ProfileFactory.getInstance().getScenarioProfile());
    if (this.implicitelyWaitDriverTimeout != null) {
        fd.manage().timeouts().implicitlyWait(this.implicitelyWaitDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    if (this.pageLoadDriverTimeout != null) {
        fd.manage().timeouts().pageLoadTimeout(this.pageLoadDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    return fd;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary)

Example 33 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project ats-framework by Axway.

the class AbstractRealBrowserDriver method start.

@Override
@PublicAtsApi
public void start() {
    try {
        log.info("Starting selenium browser with " + this.getClass().getSimpleName());
        if (browserType == BrowserType.FireFox) {
            com.axway.ats.uiengine.FirefoxDriver firefoxDriver = new com.axway.ats.uiengine.FirefoxDriver(url, browserPath, remoteSeleniumURL);
            FirefoxProfile profile = null;
            if (firefoxDriver.getProfileName() != null) {
                profile = new ProfilesIni().getProfile(firefoxDriver.getProfileName());
                if (profile == null) {
                    throw new SeleniumOperationException("Firefox profile '" + firefoxDriver.getProfileName() + "' doesn't exist");
                }
            } else if (firefoxDriver.getProfileDirectory() != null) {
                File profileDirectory = new File(firefoxDriver.getProfileDirectory());
                profile = new FirefoxProfile(profileDirectory);
            } else {
                profile = new FirefoxProfile();
                String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
                // for default browser. Now will FIX this behavior
                if (downloadDir.endsWith("/") || downloadDir.endsWith("\\")) {
                    downloadDir = downloadDir.substring(0, downloadDir.length() - 1);
                }
                // Following options are described in http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
                profile.setPreference("browser.download.dir", downloadDir);
                profile.setPreference("browser.download.folderList", 2);
                profile.setPreference("browser.helperApps.neverAsk.saveToDisk", UiEngineConfigurator.getInstance().getBrowserDownloadMimeTypes());
                // set to  "Always Activate"
                profile.setPreference("plugin.state.java", 2);
                // set to  "Always Activate"
                profile.setPreference("plugin.state.flash", 2);
                profile.setAcceptUntrustedCertificates(true);
                profile.setEnableNativeEvents(true);
            }
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            setFirefoxProxyIfAvailable(capabilities);
            if (this.browserPath != null) {
                capabilities.setCapability(FirefoxDriver.BINARY, this.browserPath);
            }
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new FirefoxDriver(capabilities);
            }
        } else if (browserType == BrowserType.InternetExplorer) {
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.internetExplorer());
            } else {
                webDriver = new org.openqa.selenium.ie.InternetExplorerDriver();
            }
        } else if (browserType == BrowserType.Edge) {
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.edge());
            } else {
                webDriver = new org.openqa.selenium.edge.EdgeDriver();
            }
        } else if (browserType == BrowserType.Chrome) {
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            // apply Chrome options
            ChromeOptions options = UiEngineConfigurator.getInstance().getChromeDriverOptions();
            if (options == null) {
                options = new ChromeOptions();
            }
            /* set browser download dir for Chrome Browser */
            String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
            HashMap<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_settings.popups", 0);
            prefs.put("download.default_directory", downloadDir);
            options.setExperimentalOption("prefs", prefs);
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.chrome.ChromeDriver(capabilities);
            }
        } else if (browserType == BrowserType.Safari) {
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.safari());
            } else {
                webDriver = new org.openqa.selenium.safari.SafariDriver();
            }
        } else if (browserType == BrowserType.PhantomJS) {
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setJavascriptEnabled(true);
            capabilities.setCapability("acceptSslCerts", true);
            capabilities.setCapability("browserConnectionEnabled", true);
            capabilities.setCapability("takesScreenshot", true);
            // See: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#settings-object
            if (System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY) != null) {
                Map<String, String> settings = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY));
                for (Entry<String, String> capability : settings.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + capability.getKey(), capability.getValue());
                }
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-customHeaders
            if (System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY) != null) {
                Map<String, String> customHeaders = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY));
                for (Entry<String, String> header : customHeaders.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + header.getKey(), header.getValue());
                }
            }
            if (this.browserPath != null) {
                capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, this.browserPath);
                System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, // required from the create screenshot method
                this.browserPath);
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options
            List<String> cliArgsCapabilities = new ArrayList<String>();
            cliArgsCapabilities.add("--web-security=false");
            cliArgsCapabilities.add("--ignore-ssl-errors=true");
            if (System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY) != null) {
                cliArgsCapabilities.add("--ssl-protocol=" + System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY));
            } else {
                cliArgsCapabilities.add("--ssl-protocol=any");
            }
            if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
                cliArgsCapabilities.add("--cookies-file=" + PhantomJsDriver.cookiesFile);
            }
            // cliArgsCapabilities.add( "--local-to-remote-url-access=true" );
            setPhantomJSProxyIfAvailable(cliArgsCapabilities);
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCapabilities);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.phantomjs.PhantomJSDriver(capabilities);
            }
        }
        log.info("Openning URL: " + url);
        webDriver.get(url);
        if (this instanceof com.axway.ats.uiengine.PhantomJsDriver) {
            webDriver.manage().window().setSize(new Dimension(1280, 1024));
        } else if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().window().maximize();
        }
        int browserActionTimeout = UiEngineConfigurator.getInstance().getBrowserActionTimeout();
        if (browserActionTimeout > 0) {
            webDriver.manage().timeouts().setScriptTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().timeouts().pageLoadTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        // waiting for the "body" element to be loaded
        waitForPageLoaded(webDriver, UiEngineConfigurator.getInstance().getWaitPageToLoadTimeout());
    } catch (Exception e) {
        throw new SeleniumOperationException("Error starting Selenium", e);
    }
}
Also used : HashMap(java.util.HashMap) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) URL(java.net.URL) Entry(java.util.Map.Entry) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Dimension(org.openqa.selenium.Dimension) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) ProfilesIni(org.openqa.selenium.firefox.internal.ProfilesIni) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 34 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project Asqatasun by Asqatasun.

the class AbstractWebDriverTestClass method initialize.

/**
     *
     */
private void initialize() {
    // Mysql access parameters are passed as JVM argument
    //        dbUrl = System.getProperty(DB_URL_KEY);
    //        dbName = System.getProperty(DB_NAME_KEY);
    //        dbUser = System.getProperty(DB_USER_KEY);
    //        dbPassword = System.getProperty(DB_PASSWORD_KEY);
    //        initDb();
    // These parameters has to passed as JVM argument
    user = System.getProperty(USER_KEY);
    password = System.getProperty(PASSWORD_KEY);
    hostLocation = System.getProperty(HOST_LOCATION_KEY);
    xvfbDisplay = System.getProperty(XVFB_DISPLAY_KEY);
    pathToFirefox = System.getProperty(FIREFOX_PATH_KEY);
    //        createRootUserInDb();
    ResourceBundle parametersBundle = ResourceBundle.getBundle(BUNDLE_NAME);
    userFieldName = parametersBundle.getString(USER_FIELD_NAME_KEY);
    passwordFieldName = parametersBundle.getString(PASSWORD_FIELD_NAME_KEY);
    loginUrl = hostLocation + parametersBundle.getString(LOGIN_URL_KEY);
    logoutUrl = hostLocation + parametersBundle.getString(LOGOUT_URL_KEY);
    adminUrl = hostLocation + parametersBundle.getString(ADMIN_URL_KEY);
    addUserUrl = hostLocation + parametersBundle.getString(ADD_USER_URL_KEY);
    editUserUrl = hostLocation + parametersBundle.getString(EDIT_USER_URL_KEY);
    deleteUserUrl = hostLocation + parametersBundle.getString(DELETE_USER_URL_KEY);
    addContractUrl = hostLocation + parametersBundle.getString(ADD_CONTRACT_URL_KEY);
    contractUrl = hostLocation + parametersBundle.getString(CONTRACT_URL_KEY);
    auditPagesSetupUrl = hostLocation + parametersBundle.getString(AUDIT_PAGES_URL_KEY);
    auditSiteSetupUrl = hostLocation + parametersBundle.getString(AUDIT_SITE_URL_KEY);
    auditUploadSetupUrl = hostLocation + parametersBundle.getString(AUDIT_UPLOAD_URL_KEY);
    auditScenarioSetupUrl = hostLocation + parametersBundle.getString(AUDIT_SCENARIO_URL_KEY);
    addUserContractUrl = hostLocation + parametersBundle.getString(ADD_USER_CONTRACT_URL_KEY);
    editUserContractUrl = hostLocation + parametersBundle.getString(EDIT_USER_CONTRACT_URL_KEY);
    if (driver == null) {
        FirefoxBinary ffBinary = new FirefoxBinary(new File(pathToFirefox));
        if (xvfbDisplay != null) {
            Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + xvfbDisplay);
            ffBinary.setEnvironmentProperty("DISPLAY", xvfbDisplay);
        }
        driver = new FirefoxDriver(ffBinary, new FirefoxProfile());
    }
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ResourceBundle(java.util.ResourceBundle) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File)

Example 35 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project webpieces by deanhiller.

the class TestLesson4WithSelenium method setUp.

@Before
public void setUp() throws InterruptedException, ClassNotFoundException {
    driver = new FirefoxDriver();
    Asserts.assertWasCompiledWithParamNames("test");
    jdbc.dropAllTablesFromDatabase();
    //you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
    //mocks after every test and NOT drop tables but clear and re-populate
    Server webserver = new Server(new SeleniumOverridesForTest(), new AppOverridesModule(), new ServerConfig(0, 0, pUnit));
    webserver.start();
    httpPort = webserver.getUnderlyingHttpChannel().getLocalAddress().getPort();
    httpsPort = webserver.getUnderlyingHttpsChannel().getLocalAddress().getPort();
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) SeleniumOverridesForTest(org.webpieces.webserver.test.SeleniumOverridesForTest) Before(org.junit.Before)

Aggregations

FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)82 WebDriver (org.openqa.selenium.WebDriver)61 WebElement (org.openqa.selenium.WebElement)47 Actions (org.openqa.selenium.interactions.Actions)18 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 File (java.io.File)8 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)7 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 URL (java.net.URL)4 Before (org.junit.Before)4 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)4 Test (org.junit.Test)3 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2