-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathBrowserStackAndroid.java
More file actions
39 lines (30 loc) · 1.62 KB
/
BrowserStackAndroid.java
File metadata and controls
39 lines (30 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;
import io.appium.java_client.android.AndroidDriver;
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";
public static void main(String args[]) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("realMobile", true);
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);
WebElement searchElement = new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(By.id("Search Wikipedia")));
searchElement.click();
WebElement insertTextElement = new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(By.id("org.wikipedia.alpha:id/search_src_text")));
insertTextElement.sendKeys("BrowserStack");
Thread.sleep(5000);
List<WebElement> allProductsName = driver.findElements(By.className("android.widget.TextView"));
assert(allProductsName.size() > 0);
driver.quit();
}
}