Skip to content

use Android Driver Element instead of Selenium #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions android/BrowserStackAndroid.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;

public class BrowserStackAndroid {

public static String accessKey = "BROWSERSTACK_USERNAME";
public static String userName = "BROWSERSTACK_ACCESS_KEY";

Expand All @@ -21,17 +22,17 @@ public static void main(String args[]) throws MalformedURLException, Interrupted
capabilities.setCapability("device", "Samsung Galaxy S7");
capabilities.setCapability("app", "bs://<hashed app-id>");

AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities);
AndroidDriver driver = new AndroidDriver<AndroidElement>(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities);

WebElement searchElement = new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(By.id("Search Wikipedia")));
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia")));
searchElement.click();
WebElement insertTextElement = new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(By.id("org.wikipedia.alpha:id/search_src_text")));
AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.id("org.wikipedia.alpha:id/search_src_text")));
insertTextElement.sendKeys("BrowserStack");
Thread.sleep(5000);

List<WebElement> allProductsName = driver.findElements(By.className("android.widget.TextView"));
List<AndroidElement> allProductsName = driver.findElementsByClassName("android.widget.TextView");
assert(allProductsName.size() > 0);

driver.quit();
Expand Down