Search in sources :

Example 1 with FirefoxProfile

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

the class ScenarioLoaderImpl method run.

@Override
public void run() {
    try {
        LOGGER.debug("Launch Scenario " + scenario);
        FirefoxProfile firefoxProfile;
        if (isScenarioOnlyLoadPage(scenario)) {
            LOGGER.debug("Audit page script");
            firefoxProfile = profileFactory.getOnlineProfile();
        } else {
            LOGGER.debug("Scenario script, images are loaded and implicitly " + "wait timeout set");
            implicitelyWaitDriverTimeout = SCENARIO_IMPLICITELY_WAIT_TIMEOUT;
            firefoxProfile = profileFactory.getScenarioProfile();
        }
        Script script = getScriptFromScenario(scenario, firefoxProfile);
        try {
            if (script.run()) {
                LOGGER.debug(webResource.getURL() + " succeeded");
            } else {
                LOGGER.debug(webResource.getURL() + " failed");
            }
        } catch (TestRunException tre) {
            // The TestRunException is caught but not as runtime, to audit
            // at least pages already fetched
            LOGGER.warn(tre.getMessage());
        } catch (RuntimeException re) {
            LOGGER.warn(re.getMessage());
            throw new ScenarioLoaderException(re);
        }
        profileFactory.shutdownFirefoxProfile(firefoxProfile);
    } catch (IOException | JSONException | SuiteException ex) {
        LOGGER.warn(ex.getMessage());
        throw new ScenarioLoaderException(ex);
    }
}
Also used : Script(com.sebuilder.interpreter.Script) ScenarioLoaderException(org.asqatasun.scenarioloader.exception.ScenarioLoaderException) SuiteException(com.sebuilder.interpreter.factory.ScriptFactory.SuiteException) JSONException(org.json.JSONException) IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) TestRunException(org.asqatasun.sebuilder.interpreter.exception.TestRunException)

Example 2 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project kotlin by JetBrains.

the class SeleniumFireFox method createFirefoxDriver.

public static FirefoxDriver createFirefoxDriver() {
    FirefoxProfile profile = new FirefoxProfile();
    FirefoxDriver answer = new FirefoxDriver(profile);
    return answer;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 3 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project jlineup by otto-de.

the class BrowserUtils method getFirefoxProfileWithDisabledAnimatedGifs.

private FirefoxProfile getFirefoxProfileWithDisabledAnimatedGifs() {
    FirefoxProfile firefoxProfileHeadless = new FirefoxProfile();
    firefoxProfileHeadless.setPreference("image.animation_mode", "none");
    return firefoxProfileHeadless;
}
Also used : FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 4 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project selenium_java by sergueik.

the class AppTest method setup.

@BeforeClass
public static void setup() throws IOException {
    // System.out.println(System.getProperty("user.dir"));
    FirefoxProfile profile = new FirefoxProfile();
    try {
        profile.addExtension(new File(System.getProperty("user.dir") + "/src/main/resources/firefox"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    // http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
    // http://www.atetric.com/atetric/javadoc/org.seleniumhq.selenium/selenium-firefox-driver/2.43.1/src-html/org/openqa/selenium/firefox/FirefoxProfile.html
    profile.setPreference("app.update.enabled", false);
    // Setting preferences
    // profile.setPreference("extensions.firebug.currentVersion", "2.0");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("firefox");
    capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new RemoteWebDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 5 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project selenium_java by sergueik.

the class BaseTest method setupTestClass.

@BeforeClass
public void setupTestClass(ITestContext context) throws IOException {
    getOsName();
    if (browser.equals("chrome")) {
        System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
        chromePrefs.put("download.default_directory", downloadFilepath);
        chromePrefs.put("enableNetwork", "true");
        options.setExperimentalOption("prefs", chromePrefs);
        options.addArguments("allow-running-insecure-content");
        options.addArguments("allow-insecure-localhost");
        options.addArguments("enable-local-file-accesses");
        options.addArguments("disable-notifications");
        // options.addArguments("start-maximized");
        options.addArguments("browser.download.folderList=2");
        options.addArguments("--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");
        options.addArguments("browser.download.dir=" + downloadFilepath);
        // options.addArguments("user-data-dir=/path/to/your/custom/profile");
        capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        driver = new ChromeDriver(capabilities);
    } else if (browser.equals("firefox")) {
        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);
        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();
    context.setAttribute("driver", driver);
    context.setAttribute("config", config);
    // 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)

Aggregations

FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)41 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)25 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)17 File (java.io.File)16 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)10 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)10 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 IOException (java.io.IOException)7 WebDriverException (org.openqa.selenium.WebDriverException)7 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)7 Actions (org.openqa.selenium.interactions.Actions)7 HashMap (java.util.HashMap)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 URL (java.net.URL)5 Dimension (org.openqa.selenium.Dimension)5 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)5 WebDriver (org.openqa.selenium.WebDriver)5 TakesScreenshot (org.openqa.selenium.TakesScreenshot)3 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)3 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)3