Search in sources :

Example 56 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project scout.rt by eclipse.

the class SeleniumDriver method setUpDriver.

public static WebDriver setUpDriver() {
    // web-driver executable
    String webdriverChromeDriver = System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
    if (StringUtility.isNullOrEmpty(webdriverChromeDriver)) {
        webdriverChromeDriver = OS.isFamilyWindows() ? "/seleniumDrivers/chromedriver.exe" : "/seleniumDrivers/chromedriver";
    }
    File chromeDriver = new File(webdriverChromeDriver);
    if (!chromeDriver.exists()) {
        System.out.println("Chrome driver executable not found at path: " + chromeDriver);
        URL webdriverChromeDriverResource = SeleniumDriver.class.getResource(webdriverChromeDriver);
        if (webdriverChromeDriverResource != null) {
            chromeDriver = new File(webdriverChromeDriverResource.getFile());
            webdriverChromeDriver = chromeDriver.getAbsolutePath();
        }
    }
    if (!StringUtility.matches(webdriverChromeDriver, ".+\\.exe", Pattern.CASE_INSENSITIVE) && chromeDriver.exists() && !chromeDriver.canExecute()) {
        chromeDriver.setExecutable(true);
    }
    System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    logProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    // log-file for web-driver
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    File logFile = new File(tmpDir, "webdriver.log");
    String logFilePath = logFile.getAbsolutePath();
    System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    logProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    // set web-driver in verbose mode
    System.setProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    logProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    // Prepare options
    ChromeOptions options = new ChromeOptions();
    String chromeBinary = System.getProperty("chrome.binary");
    logProperty("chrome.binary", chromeBinary);
    if (StringUtility.hasText(chromeBinary)) {
        options.setBinary(chromeBinary);
    }
    options.addArguments("--lang=en");
    options.addArguments("--verbose");
    options.addArguments("--disable-infobars");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    // Set logging preferences (see BrowserLogRule)
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    // TODO [7.0] BSH Remove workaround, when Chrome bug is fixed
    // <WORKAROUND> https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552
    Map<String, String> env = new HashMap<>();
    env.put("LANG", "en_US.UTF-8");
    System.out.println("Using custom environment variables for driver: " + new JSONObject(env).toString(2));
    RemoteWebDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingAnyFreePort().withEnvironment(// <--
    env).build(), capabilities);
    // RemoteWebDriver driver = new ChromeDriver(options)
    // </WORKAROUND>
    driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);
    // Set window size roughly to the minimal supported screen size
    // (1280x1024 minus some borders for browser toolbar and windows taskbar)
    // Add extra 50 pixel height, because of yellow bar "Chrome is being controlled..." which comes up since v 65.0.3325
    // even tough the disable-infobars property is set - doesn't work anymore :-(
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(1200, 900 + 50));
    Capabilities caps = driver.getCapabilities();
    System.out.println("Selenium driver configured with driver=" + driver.getClass().getName() + " browser.name=" + caps.getBrowserName() + " browser.version=" + caps.getVersion());
    return driver;
}
Also used : HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) URL(java.net.URL) JSONObject(org.json.JSONObject) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 57 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project carina by qaprosoft.

the class IECapabilities method getCapability.

public DesiredCapabilities getCapability(String testName) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities = initBaseCapabilities(capabilities, BrowserType.IE, testName);
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
    return capabilities;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities)

Example 58 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project carina by qaprosoft.

the class MobileCapabilies method getCapability.

@Override
public DesiredCapabilities getCapability(String testName) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    // add capabilities based on dynamic _config.properties variables
    capabilities = initCapabilities(capabilities);
    return capabilities;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities)

Example 59 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project ANNIS by korpling.

the class AcceptanceTest method runKickstarter.

@BeforeClass
public static void runKickstarter() {
    try {
        runner = new KickstartRunner(WEB_PORT, SERVICE_PORT);
        runner.startService();
        runner.startJetty();
        // get all installed corpora
        for (AnnisCorpus c : runner.getCorpora()) {
            corpora.add(c.getName());
        }
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("takesScreenshot", true);
        driver = new PhantomJSDriver(caps);
        driver.manage().window().setSize(new Dimension(1024, 768));
    } catch (Exception ex) {
        log.error(null, ex);
        runner = null;
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) AnnisCorpus(annis.service.objects.AnnisCorpus) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) KickstartRunner(de.hu_berlin.german.korpling.annis.kickstarter.KickstartRunner) Dimension(org.openqa.selenium.Dimension) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 60 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project vertx-openshift-it by cescoffier.

the class PhantomJSDeployment method connectToWebService.

public WebDriver connectToWebService() {
    DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
    driver = new RemoteWebDriver(getUrl(), capabilities);
    driver.manage().window().setSize(new Dimension(1920, 1080));
    return driver;
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Dimension(org.openqa.selenium.Dimension)

Aggregations

DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)173 File (java.io.File)55 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)40 HashMap (java.util.HashMap)33 URL (java.net.URL)32 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)29 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)28 Test (org.testng.annotations.Test)22 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)20 BeforeClass (org.junit.BeforeClass)19 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)18 TestSetup (com.coveros.selenified.utilities.TestSetup)17 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)15 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)14 Before (org.junit.Before)13 Test (org.junit.Test)13 MalformedURLException (java.net.MalformedURLException)12 WebDriver (org.openqa.selenium.WebDriver)12 Actions (org.openqa.selenium.interactions.Actions)12 Dimension (org.openqa.selenium.Dimension)11