/** * 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); }
/** A wrapper for the helpers wait() function */ public static WebElement wait(By locator) { return Helpers.wait(locator); }