コード例 #1
0
  /** Run before each test * */
  @Before
  public void setUp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.1.0");
    capabilities.setCapability("platformVersion", "7.1");
    capabilities.setCapability("platformName", "ios");
    capabilities.setCapability("deviceName", "iPhone Simulator");

    // Set job name on Sauce Labs
    capabilities.setCapability("name", "Java iOS tutorial " + date);
    String userDir = System.getProperty("user.dir");
    String localApp = "UICatalog6.1.app.zip";
    if (runOnSauce) {
      String user = auth.getUsername();
      String key = auth.getAccessKey();

      // Upload app to Sauce Labs
      SauceREST rest = new SauceREST(user, key);

      rest.uploadFile(new File(userDir, localApp), localApp);

      capabilities.setCapability("app", "sauce-storage:" + localApp);
      URL sauceURL = new URL("http://" + user + ":" + key + "@ondemand.saucelabs.com:80/wd/hub");
      driver = new AppiumDriver(sauceURL, capabilities);
    } else {
      String appPath = Paths.get(userDir, localApp).toAbsolutePath().toString();
      capabilities.setCapability("app", appPath);
      driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    sessionId = driver.getSessionId().toString();

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    Helpers.init(driver);
  }
コード例 #2
0
  /**
   * To run before each test. Here we want to define the CAPABILITIES of the target device, the APK
   * of the application to use, etc.
   */
  @Before
  public void setUp() throws Exception {

    /*
     * Step 1 : The capabilities  we want to have
     */
    final DesiredCapabilities CAPABILITIES = new DesiredCapabilities();
    CAPABILITIES.setCapability("appium-version", "1.1.0");
    CAPABILITIES.setCapability("platformName", "Android");
    CAPABILITIES.setCapability("deviceName", "Android");
    CAPABILITIES.setCapability("platformVersion", "4.3");

    // Set the job name on Sauce Labs if needed
    CAPABILITIES.setCapability("name", "Java Android Calculator " + date);
    String userDir = System.getProperty("user.dir");

    /*
     * Step 2 : Defines the APK to use, i.e. the name of the file to push on the device
     */
    final String LOCAL_APP = "app_calculator.apk";

    /*
     * Step 3 : The plateform of tests : cloud with Sauce or local ?
     */
    final URL SERVER_ADDRESS;
    // Upload app to Sauce Labs if run on Sauce
    if (runOnSauce) {
      String user = auth.getUsername();
      String key = auth.getAccessKey();
      SauceREST rest = new SauceREST(user, key);
      rest.uploadFile(new File(userDir, LOCAL_APP), LOCAL_APP);
      CAPABILITIES.setCapability("app", "sauce-storage:" + LOCAL_APP);
      SERVER_ADDRESS = new URL("http://" + user + ":" + key + "@ondemand.saucelabs.com:80/wd/hub");
      driver = new AndroidDriver(SERVER_ADDRESS, CAPABILITIES);
      // Starts tests on a local platform
    } else {
      String appPath = Paths.get(userDir, LOCAL_APP).toAbsolutePath().toString();
      CAPABILITIES.setCapability("app", appPath);
      SERVER_ADDRESS = new URL("http://127.0.0.1:4723/wd/hub");
      driver = new AndroidDriver(SERVER_ADDRESS, CAPABILITIES);
    }

    sessionId = driver.getSessionId().toString();

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    Helpers.init(driver, SERVER_ADDRESS);
  }