|
| 1 | +package io.appium.java_client.pagefactory_tests; |
| 2 | + |
| 3 | +import io.appium.java_client.android.AndroidDriver; |
| 4 | +import io.appium.java_client.pagefactory.AndroidFindBy; |
| 5 | +import io.appium.java_client.pagefactory.AppiumFieldDecorator; |
| 6 | +import io.appium.java_client.pagefactory.SelendroidFindAll; |
| 7 | +import io.appium.java_client.pagefactory.SelendroidFindBy; |
| 8 | +import io.appium.java_client.pagefactory.SelendroidFindBys; |
| 9 | +import io.appium.java_client.remote.MobileCapabilityType; |
| 10 | +import org.openqa.selenium.WebElement; |
| 11 | +import java.io.File; |
| 12 | +import java.net.URL; |
| 13 | +import java.util.List; |
| 14 | +import java.util.concurrent.TimeUnit; |
| 15 | +import org.junit.After; |
| 16 | +import org.junit.Assert; |
| 17 | +import org.junit.Before; |
| 18 | +import org.junit.Test; |
| 19 | +import org.openqa.selenium.WebDriver; |
| 20 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 21 | +import org.openqa.selenium.support.FindBy; |
| 22 | +import org.openqa.selenium.support.PageFactory; |
| 23 | + |
| 24 | +public class SelendroidModeTest { |
| 25 | + |
| 26 | + private WebDriver driver; |
| 27 | + |
| 28 | + @SelendroidFindBy(id = "text1") |
| 29 | + private WebElement textId; |
| 30 | + |
| 31 | + @AndroidFindBy(id = "Invalid Identifier") |
| 32 | + @SelendroidFindBy(id = "text1") |
| 33 | + private WebElement textSelendroidId; |
| 34 | + |
| 35 | + @SelendroidFindBy(name = "Accessibility") |
| 36 | + private WebElement textName; |
| 37 | + |
| 38 | + @AndroidFindBy(name = "Accessibility") |
| 39 | + private WebElement textNameAndroid; |
| 40 | + |
| 41 | + @FindBy(name = "Accessibility") |
| 42 | + private WebElement textNameDefault; |
| 43 | + |
| 44 | + @SelendroidFindBy(xpath = "//TextView[@value='Accessibility']") |
| 45 | + private WebElement textXpath; |
| 46 | + |
| 47 | + @SelendroidFindBys({ |
| 48 | + @SelendroidFindBy(id = "text1")}) |
| 49 | + private WebElement textIds; |
| 50 | + |
| 51 | + @SelendroidFindAll({ |
| 52 | + @SelendroidFindBy(id = "text1")}) |
| 53 | + private WebElement textAll; |
| 54 | + |
| 55 | + @SelendroidFindAll({ |
| 56 | + @SelendroidFindBy(id = "text1")}) |
| 57 | + private List<WebElement> textsAll; |
| 58 | + |
| 59 | + @SelendroidFindBy(className = "android.widget.TextView") |
| 60 | + private WebElement textClass; |
| 61 | + |
| 62 | + @SelendroidFindBy(tagName = "TextView") |
| 63 | + private WebElement textTag; |
| 64 | + |
| 65 | + @Before |
| 66 | + public void setUp() throws Exception { |
| 67 | + File appDir = new File("src/test/java/io/appium/java_client"); |
| 68 | + File app = new File(appDir, "ApiDemos-debug.apk"); |
| 69 | + DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 70 | + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); |
| 71 | + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); |
| 72 | + capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Selendroid"); |
| 73 | + driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); |
| 74 | + |
| 75 | + //This time out is set because test can be run on slow Android SDK emulator |
| 76 | + PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this); |
| 77 | + } |
| 78 | + |
| 79 | + @After |
| 80 | + public void tearDown() throws Exception { |
| 81 | + driver.quit(); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void findByIdElementTest() { |
| 86 | + Assert.assertNotEquals(null, textId.getAttribute("text")); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void findBySelendroidSelectorTest() { |
| 91 | + Assert.assertNotEquals(null, textSelendroidId.getAttribute("text")); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void findByElementByNameTest() { |
| 96 | + Assert.assertEquals("Accessibility", textName.getText()); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + public void findByElementByNameAndroidTest() { |
| 101 | + Assert.assertEquals("Accessibility", textNameAndroid.getText()); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void findByElementByNameDefaultTest() { |
| 106 | + Assert.assertEquals("Accessibility", textNameDefault.getText()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void findByElementByXpathTest() { |
| 111 | + Assert.assertEquals("Accessibility", textXpath.getText()); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void findByElementByIdsTest() { |
| 116 | + Assert.assertNotNull(textIds.getText()); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void findByElementByTestAllTest() { |
| 121 | + Assert.assertNotNull(textAll.getText()); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void findByElementByTextsAllTest() { |
| 126 | + Assert.assertTrue(textsAll.size() > 1); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void findByElementByCalssTest() { |
| 131 | + Assert.assertNotEquals(null, textClass.getAttribute("text")); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + public void findByElementByTagTest() { |
| 136 | + Assert.assertNotEquals(null, textTag.getAttribute("text")); |
| 137 | + } |
| 138 | + @Test |
| 139 | + public void findBySelendroidAnnotationOnlyTest() { |
| 140 | + Assert.assertNotEquals(null, textSelendroidId.getAttribute("text")); |
| 141 | + } |
| 142 | + |
| 143 | +} |
0 commit comments