Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities

The following are top voted examples for showing how to use org.openqa.selenium.remote.DesiredCapabilities. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NoraUi   File: DriverFactory.java   View source code 7 votes vote down vote up
/**
 * Sets the target browser binary path in chromeOptions if it exists in configuration.
 *
 * @param capabilities
 *            The global DesiredCapabilities
 */
private void setChromeOptions(final DesiredCapabilities capabilities, ChromeOptions chromeOptions) {

    // Set custom downloaded file path. When you check content of downloaded file by robot.
    HashMap<String, Object> chromePrefs = new HashMap<>();
    chromePrefs.put("download.default_directory", System.getProperty("user.dir") + File.separator + "downloadFiles");
    chromeOptions.setExperimentalOption("prefs", chromePrefs);

    // Set custom chromium (if you not use default chromium on your target device)
    String targetBrowserBinaryPath = Context.getWebdriversProperties("targetBrowserBinaryPath");
    if (targetBrowserBinaryPath != null && !"".equals(targetBrowserBinaryPath)) {
        chromeOptions.setBinary(targetBrowserBinaryPath);
    }

    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
}
 
Example 2
Project: SilkAppDriver   File: MultiWindowTests.java   View source code 7 votes vote down vote up
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();

	Map<String, Object> baseState = new HashMap<>();
	baseState.put("type", "NATIVE");
	baseState.put("executable", APP);
	baseState.put("locator", "//Window");

	capabilities.setCapability("appdriver-basestate", baseState);

	Map<String, Object> options = new HashMap<>();
	options.put("closeOnQuit", true);

	capabilities.setCapability("appdriver-options", options);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
 
Example 3
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   View source code 6 votes vote down vote up
public static WebDriver getFirefoxDriver()
            throws Exception
	{
        baseDir = new File(".").getPath();
        System.out.println("******** " + baseDir);

        String path = "src/test/resources/geckodriver";
        System.out.println("******** " + path);
		System.setProperty("webdriver.gecko.driver", path);

        DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
		capabilities.setCapability("marionette", true);
        capabilities.setCapability("networkConnectionEnabled", true);
        capabilities.setCapability("browserConnectionEnabled", true);


        WebDriver driver = new RemoteWebDriver(
                new URL("http://localhost:4444"),
                capabilities);

//		WebDriver driver = new MarionetteDriver(capabilities);

		return driver;
	}
 
Example 4
Project: delay-repay-bot   File: PhantomJSTest.java   View source code 6 votes vote down vote up
@Test
public void testDriver() throws IOException {
    WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.get(URL2);

    String response = driver.getPageSource();
    Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
    Elements scriptTags = doc.select("body");

    // get All functions


    try {
        String result = (String) engine.eval(response);
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    log.info("PageSource " + response);

    driver.quit();
}
 
Example 5
Project: bootstrap   File: AbstractSequentialSeleniumTest.java   View source code 6 votes vote down vote up
/**
 * Run a capability.
 */
private void runSequentialIndex(final WebDriver[] drivers, final boolean[] success, final int driverIndex, final DesiredCapabilities capability) {
	AbstractSequentialSeleniumTest seleniumTest = this;
	try {
		final WebDriver driver = getRemoteDriver(capability);
		drivers[driverIndex] = driver;
		seleniumTest = this.getClass().newInstance();
		cloneAndRun(seleniumTest, driver, capability);
		success[driverIndex] = true;
	} catch (final Exception e) {
		log.error("Unable to build the driver for requested capability, other tests are not interrupted : " + capability, e);
	} finally {
		cleanup();
		seleniumTest.cleanup();
	}
}
 
Example 6
Project: appium_tutorial   File: BaseDriver.java   View source code 6 votes vote down vote up
@Before
  public void setUp() throws Exception {
      File classpathRoot = new File(System.getProperty("user.dir"));
      File appDir = new File(classpathRoot, "/apps/");
      File app = new File(appDir.getCanonicalPath(), "Financius.v0.18.2.apk");
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("deviceName", ""); // device UID from adb
capabilities.setCapability("platformVersion", "6.0.1"); // android version
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.code44.finance"); // package name
capabilities.setCapability("appWaitActivity", "com.code44.finance.*"); // default activity

capabilities.setCapability("no-reset", "true"); 
capabilities.setCapability("full-reset", "false"); 
      driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  
  }
 
Example 7
Project: marathonv5   File: JavaDriverTest.java   View source code 6 votes vote down vote up
public void clickWithNativeEvents() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(new JavaProfile(), caps, caps);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    element1.click();
    AssertJUnit.assertTrue(buttonClicked);
    buttonClicked = false;
    new Actions(driver).click().perform();
    AssertJUnit.assertTrue(buttonClicked);
    AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
    buttonMouseActions.setLength(0);
    new Actions(driver).contextClick().perform();
    AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)")
            || buttonMouseActions.toString().contains("released(3-popup)"));
}
 
Example 8
Project: Cognizant-Intelligent-Test-Scripter   File: WebDriverFactory.java   View source code 6 votes vote down vote up
private static WebDriver createRemoteDriver(String url, DesiredCapabilities caps, Boolean checkForProxy,
        Properties props) {
    try {
        if (isAppiumNative(url, caps.asMap())) {
            if (isAndroidNative(caps.asMap())) {
                return new io.appium.java_client.android.AndroidDriver(new URL(url), caps);
            } else if (isIOSNative(caps.asMap())) {
                return new io.appium.java_client.ios.IOSDriver(new URL(url), caps);
            }
        }
        if (url == null) {
            return new RemoteWebDriver(caps);
        }
        if (checkForProxy) {
            return new RemoteWebDriver(RemoteProxy.getProxyExecutor(new URL(url), props), caps);
        }
        return new RemoteWebDriver(new URL(url), caps);
    } catch (MalformedURLException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return null;
}
 
Example 9
Project: marathonv5   File: DragAndDropTest.java   View source code 6 votes vote down vote up
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
Example 10
Project: bootstrap   File: AbstractParallelSeleniumTest.java   View source code 6 votes vote down vote up
/**
 * Prepare the thread instances.
 */
private Thread[] prepareThreads(final WebDriver[] drivers, final boolean[] success) { // NOPMD
	final Thread[] threads = new Thread[repeatedCapabilities.length]; // NOPMD -- thread
	for (int index = 0; index < repeatedCapabilities.length; index++) {
		final int driverIndex = index;
		final DesiredCapabilities capability = repeatedCapabilities[driverIndex];
		success[driverIndex] = false;
		try {
			final WebDriver driver = getRemoteDriver(capability);
			drivers[driverIndex] = driver;
			threads[driverIndex] = prepareThread(driver, driverIndex, success, capability);
		} catch (final Exception e) {
			log.error("Unable to connect the remote web driver, other tests are not interrupted : " + capability, e);
		} finally {
			cleanup();
		}
	}
	return threads;
}
 
Example 11
Project: Bytecoder   File: BytecoderUnitTestRunner.java   View source code 6 votes vote down vote up
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
 
Example 12
Project: NoraUi   File: DriverFactory.java   View source code 6 votes vote down vote up
/**
 * Generates a htmlunit webdriver.
 *
 * @return
 *         A htmlunit webdriver
 */
private WebDriver generateHtmlUnitDriver() {
    logger.info("Generating HtmlUnit driver...");
    final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    return new HtmlUnitDriver(capabilities);
}
 
Example 13
Project: webdriver-junit5-archetype   File: SuiteConfiguration.java   View source code 6 votes vote down vote up
public Capabilities getCapabilities() throws IOException {
  String capabilitiesFile = properties.getProperty("capabilities");

  Properties capsProps = new Properties();
  capsProps.load(SuiteConfiguration.class.getResourceAsStream(capabilitiesFile));

  DesiredCapabilities capabilities = new DesiredCapabilities();
  for (String name : capsProps.stringPropertyNames()) {
    String value = capsProps.getProperty(name);
    if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
      capabilities.setCapability(name, Boolean.valueOf(value));
    } else if (value.startsWith("file:")) {
      capabilities.setCapability(name, new File(".", value.substring(5)).getCanonicalFile().getAbsolutePath());
    } else {
      capabilities.setCapability(name, value);
    }
  }

  return capabilities;
}
 
Example 14
Project: WebAndAppUITesting   File: DriverFactory.java   View source code 6 votes vote down vote up
/**
 * 启动ios的safari浏览器
 * 
 * @param noReset
 */
private void createIOSSafariDriver(Boolean noReset) {

	capabilities = new DesiredCapabilities();

	capabilities.setCapability("platformName", property.getProperty("platformName"));
	capabilities.setCapability("platformVersion", property.getProperty("platformVersion"));
	capabilities.setCapability("deviceName", property.getProperty("deviceName"));
	capabilities.setCapability("browserName", property.getProperty("browserName", "Safari"));
	capabilities.setCapability("autoAcceptAlerts", property.getProperty("autoAcceptAlerts", "True"));
	// debug时,等待时间调大点!!
	capabilities.setCapability("newCommandTimeout", property.getProperty("newCommandTimeout"));
	capabilities.setCapability("noReset", noReset); // 不卸载、不重装
	capabilities.setCapability("noSign", "true");
	// 重置输入法,并且设置可以中文输入
	capabilities.setCapability("unicodeKeyboard", "True");
	capabilities.setCapability("resetKeyboard", "True");

	try {
		driver = new IOSDriver<MobileElement>(new URL(property.getProperty("remote.address")), capabilities);
	} catch (Exception e) {
		e.printStackTrace();
		AssertUtil.fail("初始化对象失败,e = " + e.getMessage());
	}
}
 
Example 15
Project: devtools-driver   File: NewSessionHandler.java   View source code 6 votes vote down vote up
private ServerSideSession safeStart(DesiredCapabilities cap) {
  ServerSideSession session = null;
  try {
    // init session
    session = getServer().createSession(cap);
    if (session == null) {
      throw new SessionNotCreatedException(
          "The server is currently shutting down and doesn't accept new tests.");
    }

    // start session
    session.start();
    return session;
  } catch (Exception e) {
    // TODO(user): Clean this up to meet logging best practices (should not log and throw).
    logger.atSevere().withCause(e).log("Error starting the session");
    if (session != null) {
      session.stop();
    }
    throw new SessionNotCreatedException(e.getMessage(), e);
  }
}
 
Example 16
Project: devtools-driver   File: GetSessionsHandler.java   View source code 6 votes vote down vote up
@Override
public Response handle() throws Exception {
  JSONArray res = new JSONArray();
  for (ServerSideSession s : getServer().getSessions()) {
    JSONObject session = new JSONObject();
    session.put("id", s.getSessionId());
    session.put("capabilities", new DesiredCapabilities());
    res.put(session);
  }

  Response resp = new Response();
  resp.setSessionId("dummy one");
  resp.setStatus(0);
  resp.setValue(res.toString());
  return resp;
}
 
Example 17
Project: selenide-appium   File: AndroidDriverProvider.java   View source code 6 votes vote down vote up
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
  Configuration.startMaximized = false;
  Configuration.captureJavascriptErrors = false;

  capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
  capabilities.setCapability("automationName", "Appium");
  capabilities.setCapability("platformName", "Android");
  capabilities.setCapability("deviceName", "0123456789ABCDEF");
  capabilities.setCapability(APP_PACKAGE, "com.android.calculator2");
  capabilities.setCapability(APP_ACTIVITY, "com.android.calculator2.Calculator");

  try {
    return new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
 
Example 18
Project: akita-testing-template   File: AkitaChromeDriverProvider.java   View source code 6 votes vote down vote up
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Map<String, Object> preferences = new Hashtable<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    String downloadsPath = System.getProperty("user.home") + "/Downloads";
    preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
    preferences.put("plugins.plugins_disabled", new String[]{
            "Adobe Flash Player", "Chrome PDF Viewer"});
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(capabilities);
}
 
Example 19
Project: colibri-ui   File: AbsDriverConfigurator.java   View source code 5 votes vote down vote up
protected DesiredCapabilities createCapabilities(DriversSettings driversSettings) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, driversSettings.getDeviceName());
    capabilities.setCapability(MobileCapabilityType.UDID, driversSettings.getUDID());
    String absolutePath = fileUtils.relativeToAbsolutePath(driversSettings.getFilePath());
    capabilities.setCapability(MobileCapabilityType.APP, absolutePath);
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, driversSettings.getNewCommandTimeoutInSeconds());
    capabilities.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);
    return capabilities;
}
 
Example 20
Project: bootstrap   File: AbstractSequentialSeleniumTest.java   View source code 5 votes vote down vote up
/**
 * Sequentially run the desired capabilities.
 */
protected void runSequential() { // NOPMD -- thread
	final WebDriver[] drivers = new WebDriver[repeatedCapabilities.length];
	final boolean[] success = new boolean[repeatedCapabilities.length];
	for (int index = 0; index < repeatedCapabilities.length; index++) {
		final int driverIndex = index;
		final DesiredCapabilities capability = repeatedCapabilities[driverIndex];
		success[driverIndex] = false;
		runSequentialIndex(drivers, success, driverIndex, capability);
	}

	final List<String> faillures = checkResults(success);
	Assert.assertTrue("All browsers test failed", faillures.size() != success.length);
	Assert.assertEquals("Some browsers test failed", 0, faillures.size());
}
 
Example 21
Project: colibri-ui   File: BaseIOSDriverConfigurator.java   View source code 5 votes vote down vote up
@Override
public AppiumDriver createDriver(DriversSettings driversSettings, AppSettings appSettings) {
    DesiredCapabilities capabilities = createCapabilities(driversSettings);
    additionalCapabilities(driversSettings, capabilities);
    IOSDriver iosDriver = new IOSDriver(getRemoteAddress(driversSettings.getAppiumRemoteUrl()), capabilities);
    iosDriver.manage().timeouts().implicitlyWait(driversSettings.getImplicitlyWaitInSeconds(), TimeUnit.SECONDS);
    return iosDriver;
}
 
Example 22
Project: Cognizant-Intelligent-Test-Scripter   File: IOSpy.java   View source code 5 votes vote down vote up
private static void startIOSSpy() {
    try {
        if (wd == null) {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            for (String key : caps.keySet()) {
                capabilities.setCapability(key, caps.get(key));
            }
            wd = new IOSDriver(new URL(url), capabilities);
        }
    } catch (Exception ex) {
        Logger.getLogger(IOSpy.class.getName()).log(Level.SEVERE, null, ex);
        Notification.show("Couldn't Connect to Device/Simulator Check Settings/Appium Logs");
    }
}
 
Example 23
Project: jspider   File: WebDriverFactory.java   View source code 5 votes vote down vote up
public WebDriverEx createWebDriver(DriverService driverService,
                                      DesiredCapabilities desiredCapabilities,
                                      SiteConfig siteConfig,
                                      DriverConfig driverConfig) throws IOException {
    driverService.start();

    //自定义HttpClientFactory用于设置命令超时时间
    ApacheHttpClient.Factory httpClientFactory = createHttpClientFactory(siteConfig, driverConfig);
    HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor(
            ImmutableMap.<String, CommandInfo>of(), driverService.getUrl(), httpClientFactory);
    WebDriverEx webDriver = new WebDriverEx(httpCommandExecutor, desiredCapabilities);
    webDriver.setDriverService(driverService);
    webDriver.setCreatedTime(new Date());

    webDriver.manage().timeouts().implicitlyWait(driverConfig.getImplicitlyWait(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().pageLoadTimeout(driverConfig.getPageLoadTimeout(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().setScriptTimeout(driverConfig.getScriptTimeout(), TimeUnit.MILLISECONDS);

    return webDriver;
}
 
Example 24
Project: jspider   File: WebDriverFactory.java   View source code 5 votes vote down vote up
public DesiredCapabilities createChromeDesiredCapabilities(SiteConfig siteConfig, DriverConfig driverConfig) {
    ChromeDesiredCapabilities capabilities = ChromeDesiredCapabilities.create();

    capabilities.setImagesEnabled(false);
    capabilities.setFlashEnabled(false);
    capabilities.setAutomaticDownloadsEnabled(false);
    capabilities.setJavascriptEnabled(true);

    return capabilities;
}
 
Example 25
Project: mobileAutomation   File: Driver.java   View source code 5 votes vote down vote up
/**
 * Get an instance of an WebDriver.
 * 
 * @param appiumServerUrl - servers URL
 * @param platformName - OS name (Android, IOS ...)
 * @param deviceName - device model name
 * @param app - mobile application to install/run
 * @return - an android driver connected via Appium
 */
public static AndroidDriver<?> driverStart(String appiumServerUrl, 
		String platformName,
		String deviceName,
		String app){
	
	
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("platformName", platformName);
	capabilities.setCapability("deviceName", deviceName);
	capabilities.setCapability("app", app);
	
	

	try {
		driver = new AndroidDriver<>(new URL(appiumServerUrl), capabilities);
	} catch (MalformedURLException e) {
		throw new TestCaseFailure("Could not start remote driver! ", e);
	}

	logger.log("WebDriver: " + driver.getClass().getCanonicalName());
	setDefaultImplicitWait();
	logger.log("implicit wait: " + defaultWait + "s");
	
	return driver;
}
 
Example 26
Project: phoenix.webui.framework   File: CapabilityConfig.java   View source code 5 votes vote down vote up
/**
 * @param engineCapMap 用于保存浏览器配置的返回结果
 * @param enginePro 引擎配置集合
 */
public CapabilityConfig(Map<String, DesiredCapabilities> engineCapMap,
		Properties enginePro)
{
	this.engineCapMap = engineCapMap;
	this.enginePro = enginePro;
}
 
Example 27
Project: phoenix.webui.framework   File: CapabilityConfig.java   View source code 5 votes vote down vote up
/**
 * 火狐浏览器配置
 */
private void firefox()
{
	DesiredCapabilities capability = DesiredCapabilities.firefox();
	capability.setCapability("marionette", true);
	engineCapMap.put(DRIVER_FIREFOX, capability);
}
 
Example 28
Project: msa-cucumber-appium   File: MobileApp.java   View source code 5 votes vote down vote up
private static ThreadLocal<WebDriver> getAndroidDriverThreadLocal(DesiredCapabilities... params) throws IOException {
        final Properties prop = new Properties();
        FileInputStream input = new FileInputStream("src/main/resources/config.properties");
        prop.load(input);

        System.out.println(prop.getProperty("appPath"));
        System.out.println(prop.getProperty("application"));
        System.out.println(prop.getProperty("device"));
        System.out.println(prop.getProperty("platform"));
        System.out.println(prop.getProperty("appiumServer"));

        System.out.println("********************InIt initiated ************");
        File appDir = new File(prop.getProperty("appPath"));
        File app = new File(appDir, prop.getProperty("application"));

        //mandatory capabilities
        capabilities.setCapability("deviceName", prop.getProperty("device"));
//        capabilities.setCapability("deviceName", "ba99f4b7");
        capabilities.setCapability("platformName", prop.getProperty("platform"));
        capabilities.setCapability("app", app.getAbsolutePath());
        //capabilities.setCapability("noReset",false);

        return new ThreadLocal<WebDriver>() {
            @Override
            protected WebDriver initialValue() {
                AndroidDriver<WebElement> androidDriver = null;
                try {
                    androidDriver = new AndroidDriver<WebElement>(new URL(prop.getProperty("appiumServer")), capabilities);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                return androidDriver;
            }
        };
    }
 
Example 29
Project: marathonv5   File: JavaDriver.java   View source code 5 votes vote down vote up
private static Capabilities dropCapabilities(Capabilities capabilities, String... keysToRemove) {
    if (capabilities == null) {
        return new DesiredCapabilities();
    }
    final Set<String> toRemove = Sets.newHashSet(keysToRemove);
    DesiredCapabilities caps = new DesiredCapabilities(Maps.filterKeys(capabilities.asMap(), new Predicate<String>() {
        @Override public boolean apply(String key) {
            return !toRemove.contains(key);
        }
    }));

    return caps;
}
 
Example 30
Project: marathonv5   File: JavaDriverLogsTest.java   View source code 5 votes vote down vote up
public void loggingWorks() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.INFO);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertEquals(2, all.size());
    AssertJUnit.assertTrue(all.get(0).getMessage().contains("A new session created. sessionID = "));
}
 
Example 31
Project: SWET   File: BrowserDriver.java   View source code 5 votes vote down vote up
private static DesiredCapabilities capabilitiesSafari() {
	DesiredCapabilities capabilities = DesiredCapabilities.safari();
	SafariOptions options = new SafariOptions();
	options.setUseCleanSession(true);
	capabilities.setCapability(SafariOptions.CAPABILITY, options);
	return capabilities;
}
 
Example 32
Project: opentest   File: AppiumHelper.java   View source code 5 votes vote down vote up
/**
 * Inject desired capabilities from configuration into the specified
 * DesiredCapabilities object.
 */
private static void injectCapsFromConfig(DesiredCapabilities caps) {
    Object capsFromConfig = config.get("appium.desiredCapabilities", null);

    if (capsFromConfig instanceof Map) {
        Map<String, Object> capsFromConfigMap = (Map) capsFromConfig;
        for (Map.Entry entry : capsFromConfigMap.entrySet()) {
            if (entry.getValue() != null) {
                caps.setCapability(entry.getKey().toString(), entry.getValue());
            }
        }
    }
}
 
Example 33
Project: bootstrap   File: TAbstractSeleniumITCase.java   View source code 5 votes vote down vote up
/**
 * Create the driver instance
 */
@Override
protected void prepareDriver() throws Exception {
	if (!isLocalTest()) {
		capability = DesiredCapabilities.phantomjs();
	}
	super.prepareDriver();
}
 
Example 34
Project: marathonv5   File: JavaDriverTest.java   View source code 5 votes vote down vote up
public void succeedsWhenRequestingNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(capabilities.is("nativeEvents"));
}
 
Example 35
Project: Actitime-Framework   File: DriverFactory.java   View source code 5 votes vote down vote up
protected void ieDriver() {
	DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
	capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
	capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
	capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
	capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
	capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
	capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	System.setProperty("webdriver.ie.driver","./src/main/resources/iedriver/IEDriverServer.exe");
	driver = new InternetExplorerDriver(capabilities);
	driver.manage().window().maximize();
}
 
Example 36
Project: marathonv5   File: LaunchJavaCommandLineTest.java   View source code 5 votes vote down vote up
@BeforeMethod public void createDriver() {
    System.setProperty(Constants.PROP_PROJECT_FRAMEWORK, Constants.FRAMEWORK_SWING);
    JavaProfile profile = new JavaProfile(LaunchMode.JAVA_COMMAND_LINE);
    File f = findFile();
    profile.addClassPath(f);
    profile.setRecordingPort(startRecordingServer());
    profile.setMainClass("com.sun.swingset3.SwingSet3");
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.5", Platform.ANY);
    driver = new JavaDriver(profile, caps, caps);
}
 
Example 37
Project: marathonv5   File: LaunchCommandLineTest.java   View source code 5 votes vote down vote up
@BeforeClass public void createDriver() {
    System.setProperty(Constants.PROP_PROJECT_FRAMEWORK, Constants.FRAMEWORK_SWING);
    JavaProfile profile = new JavaProfile(LaunchMode.COMMAND_LINE);
    File f = findFile();
    profile.setCommand(f.getAbsolutePath());
    profile.setRecordingPort(startRecordingServer());
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.5", Platform.ANY);
    driver = new JavaDriver(profile, caps, caps);
}
 
Example 38
Project: functional-programming-selenium-examples   File: Chrome.java   View source code 5 votes vote down vote up
@Override
public WebDriver getWebDriver()
{
	System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.2.27");
       DesiredCapabilities capabilities = DesiredCapabilities.chrome();
       return new ChromeDriver(capabilities);
}
 
Example 39
Project: functional-programming-selenium-examples   File: Firefox.java   View source code 5 votes vote down vote up
@Override
public WebDriver getWebDriver()
{
	System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver.v0.11.1.mac");
	DesiredCapabilities capabilities=DesiredCapabilities.firefox();
	WebDriver driver = new FirefoxDriver(capabilities);
       return driver;
}
 
Example 40
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   View source code 5 votes vote down vote up
public static WebDriver getFirefoxDriver(String pathToFirefoxExecutable)
{
       String path = "src/test/resources/geckodriver";
	System.setProperty("webdriver.gecko.driver", path);
	System.setProperty("webdriver.firefox.bin", pathToFirefoxExecutable);

	DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
       capabilities.setCapability("marionette", true);
       capabilities.setCapability("networkConnectionEnabled", true);
       capabilities.setCapability("browserConnectionEnabled", true);

	WebDriver driver = new MarionetteDriver(capabilities);

	return driver;
}