Refine search
public void swipeLeft() { AppiumDriver appiumDriver = (AppiumDriver) driver; appiumDriver.context("NATIVE_APP"); Dimension size = appiumDriver.manage().window().getSize(); int startx = (int) (size.width * 0.8); int endx = (int) (size.width * 0.20); int starty = size.height / 2; appiumDriver.swipe(startx, starty, endx, starty, 1000); }
@Test public void scrollingToSubElement() { driver.findElementByAccessibilityId("Views").click(); AndroidElement list = driver.findElement(By.id("android:id/list")); MobileElement radioGroup = list .findElement(MobileBy .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().text(\"Radio Group\"));")); assertNotNull(radioGroup.getLocation()); }
AppiumDriver appiumDriver = new AppiumDriver(); String originalContext = appiumDriver.getContext(); Point coordinate = element.getLocation(); Dimension loc = element.getSize(); int centerX = loc.getWidth() / 2 + coordinate.getX(); int centerY = loc.getHeight() / 2 + coordinate.getY(); appiumDriver.context("NATIVE_APP"); appiumDriver.tap(1, centerX, centerY, 2); appiumDriver.context(originalContext);
@Test public void findByAndroidUIAutomatorFromDriverTest() { assertNotEquals(driver .findElement(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); assertNotEquals(driver .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); assertNotEquals(driver .findElements(MobileBy .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); }
@Ignore @Test public void whenIOSHybridAppIsLaunched() { assertTrue(check(serverAppCapabilitiesSupplier, appFileSupplierFunction.apply(webViewApp), (by, aClass) -> { new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); new WebDriverWait(driver, 30) .until(ExpectedConditions .presenceOfElementLocated(AccessibilityId("Webview"))); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } driver.getContextHandles().forEach((handle) -> { if (handle.contains("WEBVIEW")) { driver.context(handle); } }); return commonPredicate.test(by, aClass); }, partialLinkText("login"), IOSElement.class)); }
@Test void testWithAndroid(AppiumDriver<WebElement> android) { String context = android.getContext(); android.context("NATIVE_APP"); android.findElement(By.id("com.android.chrome:id/terms_accept")) .click(); android.findElement(By.id("com.android.chrome:id/negative_button")) .click(); android.context(context); android.get("https://bonigarcia.github.io/selenium-jupiter/"); assertTrue(android.getTitle().contains("JUnit 5 extension")); }
originalContext = appiumDriver.getContext(); if (appiumDriver.getContextHandles().size() > 1 && !originalContext.equalsIgnoreCase(NATIVE_APP)) { appiumDriver.context(NATIVE_APP); } else { originalContext = null; ScreenOrientation orientation = appiumDriver.getOrientation(); return orientation == ScreenOrientation.LANDSCAPE; } catch (Exception e) { } finally { if (originalContext != null) { appiumDriver.context(originalContext);
private void tapElement(AppiumDriver appiumDriver, WebElement element) { // Locate center of element Point location = element.getLocation(); Dimension size = element.getSize(); int tapX = location.getX() + (size.getWidth() / 2); int tapY = location.getY() + (size.getHeight() / 2); // Execute tap String originalContext = appiumDriver.getContext(); appiumDriver.context("NATIVE_APP"); TouchAction action = new TouchAction(appiumDriver); action.tap(tapX, tapY).perform(); appiumDriver.context(originalContext); }
driver.context(webContext); Assert.assertNotEquals(driver.getTitle(), title); driver.context("NATIVE_APP"); input.sendKeys("https://google.com"); WebElement navigate = driver.findElement(navigateBtn); navigate.click(); driver.switchTo().alert().accept(); driver.findElement(clearBtn).click(); input.sendKeys("https://appiumpro.com"); navigate.click(); driver.context(webContext); wait.until(ExpectedConditions.titleIs(title)); } catch (InterruptedException ign) { } finally { driver.quit();
public static WebElement findElement( AppiumDriver<?> driver, UiElement uiElement ) { // switch the context if needed String context = getElementContext(uiElement); if (context != null && !context.equals(driver.getContext())) { driver.context(context); } // find the element if (uiElement.getElementProperty("xpath") != null) { return driver.findElement(By.xpath(uiElement.getElementProperty("xpath"))); } else if (uiElement.getElementProperty("id") != null) { return driver.findElement(By.id(uiElement.getElementProperty("id"))); } else if (uiElement.getElementProperty("name") != null) { return driver.findElement(By.name(uiElement.getElementProperty("name"))); } else if (uiElement.getElementProperty("text") != null) { return driver.findElement(By.linkText(uiElement.getElementProperty("text"))); } else if (uiElement.getElementProperty("partialText") != null) { return driver.findElement(By.partialLinkText(uiElement.getElementProperty("partialText"))); } return null; }
@After public void tearDown() { if (driver != null) { driver.quit(); } driver = null; }
@Test public void testPushNotifications() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "iOS"); capabilities.setCapability("platformVersion", "11.2"); capabilities.setCapability("deviceName", "iPhone 6s"); capabilities.setCapability("app", APP); capabilities.setCapability("udid", "auto"); capabilities.setCapability("xcodeOrgId", XCODE_ORG_ID); capabilities.setCapability("xcodeSigningId", "iPhone Developer"); capabilities.setCapability("updatedWDABundleId", WDA_BUNDLE_ID); driver = new IOSDriver(new URL("http://localhost:4723/wd/hub"), capabilities); try { // get screen size so we can swipe correctly screenSize = driver.manage().window().getSize(); // close app and wait for push notification to arrive driver.terminateApp(BUNDLE_ID); // here is where your code should trigger the push notification and wait a bit // now pull down the notification shade, check for the message we're expecting, and // then close the shade again ('TWITTER' is just an example of an expected message) showNotifications(); driver.findElement(By.xpath("//XCUIElementTypeCell[contains(@label, 'TWITTER')]")); hideNotifications(); // finally, we can reactivate our app in order to verify that the message is present, // or whatever we need to do driver.activateApp(BUNDLE_ID); } finally { driver.quit(); } }
public void tapAtCoordinates(int x, int y) throws Exception { if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate(x, y, 1); } else if (platform.equals(PlatformType.ANDROID)){ Dimension size = driver.manage().window().getSize(); if(y > size.getHeight() || x > size.getWidth()){ log("using adb tap at " + x + ", " + y); try{ //run eclipse from commandline to get path variable correct and find adb Process p = Runtime.getRuntime().exec("adb -s " + udid + " shell input tap " + x + " " + y); p.waitFor(); } catch (Exception e) { log(e.toString()); } } else { driver.tap(1, x, y, 1); } } else { driver.tap(1, x, y, 1); } }
public void actualTest(AppiumDriver driver) { // Set up default wait WebDriverWait wait = new WebDriverWait(driver, 10); try { driver.get("http://appiumpro.com/contact"); wait.until(ExpectedConditions.visibilityOfElementLocated(EMAIL)) .sendKeys("foo@foo.com"); driver.findElement(MESSAGE).sendKeys("Hello!"); driver.findElement(SEND).click(); String response = wait.until(ExpectedConditions.visibilityOfElementLocated(ERROR)).getText(); // validate that we get an error message involving a captcha, which we didn't fill out Assert.assertThat(response, CoreMatchers.containsString("Captcha")); } finally { driver.quit(); } } }
public void gameCenterLogin() throws Exception { if (driver.getPageSource().contains("Sign in")) { log("Google Plus sign in shown..."); log(driver.getPageSource()); takeScreenshot("google_plus_sign_in_shown"); while (driver.getPageSource().contains("Sign in")) if (automationName.equalsIgnoreCase("selendroid")) { driver.findElement(By.xpath("//LinearLayout/Button[@text='Sign in']")).click(); } else if (platform.equals(PlatformType.ANDROID)) { driver.findElement(By.xpath("//android.widget.Button[@text='Sign in']")).click(); } else { //we are on ios driver.findElementByAccessibilityId("Sign In").click(); } takeScreenshot("after_clicking_sign_in"); } }
private void automateClipboard(AppiumDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 5); try { wait.until(ExpectedConditions.presenceOfElementLocated(clipboardNav)).click(); String text = "Hello World"; ((HasClipboard) driver).setClipboardText(text); wait.until(ExpectedConditions.presenceOfElementLocated(refreshClipboardBtn)).click(); By clipboardText = MobileBy.AccessibilityId(text); Assert.assertEquals(driver.findElement(clipboardText).getText(), text); text = "Hello World Again"; driver.findElement(clipboardInput).sendKeys(text); try { driver.hideKeyboard(); } catch (Exception ign) {} driver.findElement(setTextBtn).click(); Assert.assertEquals(((HasClipboard) driver).getClipboardText(), text); } finally { driver.quit(); } } }
/** * Checks if web description is loaded. * * Note: Will fail if Android version is < 4.4 or >= 6.0. Hybrid views are not compatible with * versions < 4.4 and Appium context switching is currently buggy on devices running versions >= 6.0. * * @return true if it is, else false. */ public boolean webDescriptionIsLoaded() throws InterruptedException { Object[] contextHandles = driver.getContextHandles().toArray(); String androidVersion = driver.getCapabilities().getCapability("platformVersion").toString(); if (versionLessThan(androidVersion, "4.4")) { return true; } else if (versionGreaterThanOrEqual(androidVersion, "6.0")) { return false; } String webViewContent = (String) contextHandles[contextHandles.length - 1]; WebDriver webDriver = driver.context(webViewContent); try { WebDriverWait wait = new WebDriverWait(webDriver, MAX_WEBSITE_LOAD_TIME); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(WEB_HEADER_CSS_NAME))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(WEB_HEADER_CSS_NAME))); } catch (TimeoutException e) { return false; // MAX_WEBSITE_LOAD_TIME timeout exceeded - bad internet connection. } WebElement webHeader = webDriver.findElement(By.cssSelector(WEB_HEADER_CSS_NAME)); return webHeader.isDisplayed(); }
@Test public void replaceValueTest() { String originalValue = "original value"; Activity activity = new Activity("io.appium.android.apis", ".view.Controls1"); startsActivity.startActivity(activity); AndroidElement editElement = driver .findElement(MobileBy .AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")")); editElement.sendKeys(originalValue); assertEquals(originalValue, editElement.getText()); String replacedValue = "replaced value"; editElement.replaceValue(replacedValue); assertEquals(replacedValue, editElement.getText()); }