forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidSelectorsTest.java
More file actions
64 lines (55 loc) · 2.66 KB
/
AndroidSelectorsTest.java
File metadata and controls
64 lines (55 loc) · 2.66 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
import java.util.List;
public class AndroidSelectorsTest extends BaseTest {
private AndroidDriver<WebElement> driver;
private static AppiumDriverLocalService service;
private final String PACKAGE = "io.appium.android.apis";
@BeforeSuite
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterSuite
public void tearDown() {
driver.quit();
}
@Test
public void testFindElementsByAccessibilityId () {
// Look for element by accessibility. In Android this is the "content-desc"
List<WebElement> searchParametersElement = (List<WebElement>) driver.findElementsByAccessibilityId("Content");
Assert.assertEquals(searchParametersElement.size(), 1);
}
@Test
public void testFindElementsById () {
// Look for element by ID. In Android this is the "resource-id"
List<WebElement> actionBarContainerElements = (List<WebElement>) driver.findElementsById("android:id/action_bar_container");
Assert.assertEquals(actionBarContainerElements.size(), 1);
}
@Test
public void testFindElementsByClassName () {
// Look for elements by the class name. In Android this is the Java Class Name of the view.
List<WebElement> linearLayoutElements = (List<WebElement>) driver.findElementsByClassName("android.widget.FrameLayout");
Assert.assertTrue(linearLayoutElements.size() > 1);
};
@Test
public void testFindElementsByXPath () {
// Find elements by XPath
List<WebElement> linearLayoutElements = (List<WebElement>) driver.findElementsByXPath("//*[@class=\"android.widget.FrameLayout\"]");
Assert.assertTrue(linearLayoutElements.size() > 1);
};
}