Search in sources :

Example 36 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities 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)

Example 37 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project selenium_java by sergueik.

the class AppiumTest method setUp.

@BeforeClass
public void setUp() throws MalformedURLException, InterruptedException {
    DesiredCapabilities capability = DesiredCapabilities.iphone();
    capability.setCapability("appiumVersion", appiumVersion);
    capability.setCapability("deviceName", deviceName);
    capability.setCapability("deviceOrientation", deviceOrientation);
    capability.setCapability("platformVersion", platformVersion);
    capability.setCapability("platformName", platformName);
    capability.setCapability("browserName", browserName);
    IOSDriver driver = new IOSDriver(new URL("http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"), capability);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
Also used : IOSDriver(io.appium.java_client.ios.IOSDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) BeforeClass(org.testng.annotations.BeforeClass)

Example 38 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project selenium_java by sergueik.

the class BrowserTest method setUp.

@BeforeClass
public void setUp() throws MalformedURLException, InterruptedException {
    DesiredCapabilities capability = new DesiredCapabilities();
    capability.setCapability("platform", platform);
    capability.setCapability("browserName", browserName);
    capability.setCapability("browserVersion", browserVersion);
    driver = new RemoteWebDriver(new URL("http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"), capability);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) BeforeClass(org.testng.annotations.BeforeClass)

Example 39 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project selenium_java by sergueik.

the class Select2WrapperTest method beforeSuite.

@BeforeSuite
@SuppressWarnings("deprecation")
public void beforeSuite() throws Exception {
    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<>();
        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);
        for (String optionAgrument : (new String[] { "allow-running-insecure-content", "allow-insecure-localhost", "enable-local-file-accesses", "disable-notifications", /* "start-maximized" , */
        "browser.download.folderList=2", "--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"  , */
        })) {
            options.addArguments(optionAgrument);
        }
        // options for headless
        /*
			for (String optionAgrument : (new String[] { "headless",
					"window-size=1200x600", })) {
				options.addArguments(optionAgrument);
			}
			*/
        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");
        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);
        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);
    /*
		System.setProperty("webdriver.chrome.driver",
				"c:/java/selenium/chromedriver.exe");
		driver = new ChromeDriver();
		*/
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
Also used : HashMap(java.util.HashMap) Actions(org.openqa.selenium.interactions.Actions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) 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) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 40 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project selenium_java by sergueik.

the class DragAndDropKendoUIGridTest method beforeSuiteMethod.

@SuppressWarnings("deprecation")
@BeforeSuite
public void beforeSuiteMethod() throws InterruptedException {
    System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions options = 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.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);
    driver.manage().deleteAllCookies();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("http://demos.telerik.com/kendo-ui/grid/index");
}
Also used : HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

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