Example usage for org.openqa.selenium.remote DesiredCapabilities DesiredCapabilities

List of usage examples for org.openqa.selenium.remote DesiredCapabilities DesiredCapabilities

Introduction

In this page you can find the example usage for org.openqa.selenium.remote DesiredCapabilities DesiredCapabilities.

Prototype

public DesiredCapabilities() 

Source Link

Usage

From source file:CalculatorTest.java

License:Open Source License

@BeforeClass
public static void setup() {
    try {//from w  w w. j a v  a  2 s .c o  m
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
        capabilities.setCapability("platformName", "Windows");
        capabilities.setCapability("deviceName", "WindowsPC");
        CalculatorSession = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        CalculatorSession.findElementByXPath("//Button[starts-with(@Name, \"Menu\")]").click();
        CalculatorSession.findElementByXPath("//ListItem[@Name=\"Standard Calculator\"]").click();

        CalculatorSession.findElementByName("Clear").click();
        CalculatorSession.findElementByName("Seven").click();
        CalculatorResult = CalculatorSession.findElementByName("Display is  7 ");
        Assert.assertNotNull(CalculatorResult);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}

From source file:FirefoxConsoleExport.java

License:Open Source License

public FirefoxConsoleExport(int port) throws IOException {
    super(port);//w  ww.ja v a2  s  .  c  o  m
    start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
    ClassLoader classLoader = FirefoxConsoleExport.class.getClassLoader();
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    FirefoxProfile fp = new FirefoxProfile();
    File extensionToInstall = new File(classLoader.getResource("firebug-2.0.16-fx.xpi").getFile());
    File extension2 = new File(classLoader.getResource("consoleExport-0.5b5.xpi").getFile());

    fp.addExtension(extensionToInstall);
    fp.addExtension(extension2);

    fp.setPreference("extensions.firebug.currentVersion", "2.0");
    fp.setPreference("extensions.firebug.console.enableSites", "true");
    fp.setPreference("extensions.firebug.net.enableSites", "true");
    fp.setPreference("extensions.firebug.script.enableSites", "true");
    fp.setPreference("extensions.firebug.allPagesActivation", "on");
    fp.setPreference("extensions.firebug.consoleexport.active", "true");
    fp.setPreference("extensions.firebug.consoleexport.serverURL", "http://127.0.0.1:9999");

    cap.setCapability(FirefoxDriver.PROFILE, fp);
    driver = new FirefoxDriver(cap);

}

From source file:IosGameTest.java

License:Apache License

@Before
public void setup() throws Exception {
    File appDir = new File("/Users/johnny/Documents/workspace/xcode/GameTest");
    File app = new File(appDir, "GameTest.app");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
            "iPhone 6 (8.1 Simulator) [F26F3E2A-95FC-4C24-9AE0-318616F526BC]");
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    sessionId = driver.getSessionId().toString();
}

From source file:acceptance.SharedDriver.java

License:Open Source License

private static WebDriver createWebDriver() {
    String driverType = getWebDriverType();
    final WebDriver driver;
    switch (driverType.toLowerCase()) {
    case "htmlunit":
        driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24);
        break;//from   w ww . j  a  va2  s. c  om
    case "firefox":
        driver = new FirefoxDriver();
        break;
    case "phantomjs":
        String phantomjsBinaryPath = getPhantomjsBinaryPath();
        if (phantomjsBinaryPath.length() > 0) {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.setCapability("phantomjs.binary.path", phantomjsBinaryPath);
            driver = new PhantomJSDriver(desiredCapabilities);
        } else {
            driver = new PhantomJSDriver();
        }
        break;
    default:
        throw new RuntimeException(
                "WebDriver type not correctly configured. Unknown driver type: '" + driverType + "'");
    }
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    driver.manage().window().setSize(new Dimension(1280, 800));
    return driver;
}

From source file:app.fynd.Tests.AbstractBaseTests.TestBase.java

License:Open Source License

/**
 * This method runs before any other method.
 *
 * Appium follows a client - server model:
 * We are setting up our appium client in order to connect to Device Farm's appium server.
 *
 * We do not need to and SHOULD NOT set our own DesiredCapabilities
 * Device Farm creates custom settings at the server level. Setting your own DesiredCapabilities
 * will result in unexpected results and failures.
 *
 * @throws MalformedURLException An exception that occurs when the URL is wrong
 *///from  www .jav a2 s .  c  om
@BeforeSuite
public void setUpAppium() throws MalformedURLException {

    final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

    // final String URL_STRING = "http://192.168.10.102:4723/wd/hub";

    URL url = new URL(URL_STRING);

    //Use a empty DesiredCapabilities object
    DesiredCapabilities capabilities = new DesiredCapabilities();

    driver = new AndroidDriver<MobileElement>(url, capabilities);

    //Use a higher value if your mobile elements take time to show up
    driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
}

From source file:beseenium.controller.ActionDataFactory.ActionDataFactory.java

License:Open Source License

/**
 * default constructor, initialises internal map and populates it
 * @throws MalformedURLException //from w  w w  . j a  va 2s  .  c o m
 */
public ActionDataFactory() throws MalformedURLException {
    super();
    this.emptyActionData = new ActionData();
    this.ActionDataMap = new HashMap<String, MakeData>();
    this.capabilities = new DesiredCapabilities();
    this.mapEntries();
}

From source file:bi.com.seleniumgrid.PhantomJsTest.java

License:Apache License

@Test
public void test() {
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    // Configure our WebDriver to support JavaScript and be able to find the PhantomJS binary
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("takesScreenshot", false);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_BINARY);
    final WebDriver driver = new PhantomJSDriver(capabilities);
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    pageTitle = driver.getTitle().trim();
    Assert.assertEquals(pageTitle, "GoalQuest");

    System.out.println("Page title is: " + driver.getTitle());

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:cochrane343.journal.test.JournalStepDefinitions.java

License:Open Source License

@Given("^I have launched the app$")
public void i_have_launched_the_app() throws MalformedURLException {
    final File apkFile = new File("../journal/bin/journal.apk");
    final URL serverURL = new URL("http://localhost:4723/wd/hub");

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("app", apkFile.getAbsolutePath());
    capabilities.setCapability("appPackage", "cochrane343.journal");
    capabilities.setCapability("appActivity", ".MainActivity");

    driver = new AppiumDriver(serverURL, capabilities);
}

From source file:com.agomezmoron.tests.TestBase.java

License:Open Source License

/**
 * This method runs before any other method.
 *
 * Appium follows a client - server model: We are setting up our appium client in order to connect to Device Farm's
 * appium server.//  w w w.j  a  v a  2 s . c om
 *
 * We do not need to and SHOULD NOT set our own DesiredCapabilities Device Farm creates custom settings at the
 * server level. Setting your own DesiredCapabilities will result in unexpected results and failures.
 *
 * @throws MalformedURLException An exception that occurs when the URL is wrong
 */
@BeforeSuite
public void setUpAppium() throws MalformedURLException {
    // Load the file we'll use
    PropertiesHandler.getInstance().load("test.properties");

    final String URL_STRING = PropertiesHandler.getInstance().get("test.appiumLocation");

    URL url = new URL(URL_STRING);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", PropertiesHandler.getInstance().get("test.platform"));
    // Device name is not mandatory for cloud executions.
    if (StringUtils.isNotBlank(PropertiesHandler.getInstance().get("test.deviceName"))) {
        capabilities.setCapability("deviceName", PropertiesHandler.getInstance().get("test.deviceName"));
    }
    // By default the app should be located in the sme root folder. If it isn't, this capability should be changed.
    capabilities.setCapability("app", PropertiesHandler.getInstance().get("test.app.name"));
    capabilities.setCapability("appHybrid",
            Boolean.parseBoolean(PropertiesHandler.getInstance().get("test.app.hybrid")));

    // Checking if chromedriver is installed correctly.
    File file = new File("/usr/local/bin/chromedriver");
    if (file.exists()) {
        capabilities.setCapability("chromedriverExecutable", "/usr/local/bin/chromedriver");
    }
    // Use a empty DesiredCapabilities object.
    driver = AppiumHandledDriver.buildInstance(url, capabilities);

    // If the driver is not ready.
    assertTrue("The driver is nos ready to test!", driver.isDriverReadyToTest());
}

From source file:com.alarm.service.test.TestBase.java

License:Open Source License

/**
 * This method runs before any other method.
 *
 * Appium follows a client - server model:
 * We are setting up our appium client in order to connect to Device Farm's appium server.
 *
 * We do not need to and SHOULD NOT set our own DesiredCapabilities
 * Device Farm creates custom settings at the server level. Setting your own DesiredCapabilities
 * will result in unexpected results and failures.
 *
 * @throws MalformedURLException An exception that occurs when the URL is wrong
 *//* w w w  . jav  a 2 s . c  o  m*/
@BeforeSuite
public void setUpAppium() throws MalformedURLException {

    final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

    URL url = new URL(URL_STRING);

    //Use a empty DesiredCapabilities object
    driver = new AndroidDriver<MobileElement>(url, new DesiredCapabilities());

    //Use a higher value if your mobile elements take time to show up
    driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
}