Created
February 21, 2019 08:54
-
-
Save oradkovsky/421574ac813593baade5a82bad0bf07e to your computer and use it in GitHub Desktop.
androiddriver setup and simple use case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BasicTests { | |
private static final String PACKAGE_NAME = "com.noname.pharma"; | |
private AndroidDriver<AndroidElement> driver; | |
@Before | |
public void setup() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("deviceName", "emulator-5554"); | |
capabilities.setCapability("platformVersion", "7.1.1"); | |
capabilities.setCapability("appPackage", PACKAGE_NAME); | |
capabilities.setCapability("appActivity", ".MasterActivity"); | |
capabilities.setCapability("unicodeKeyboard", "true"); | |
capabilities.setCapability("resetKeyboard", "true"); | |
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); | |
driver.resetApp(); | |
} | |
@After | |
public void tearDown() { | |
driver.quit(); | |
} | |
@Test | |
public void test1() { | |
driver.findElementById(PACKAGE_NAME + ":id/tetUserName").setValue("ror"); | |
driver.findElementById(PACKAGE_NAME + ":id/tetPassword").setValue("ror"); | |
driver.findElementById(PACKAGE_NAME + ":id/btnSubmit").click(); | |
//matching is case-sensitive | |
List<AndroidElement> elementsWithText = driver.findElementsByAndroidUIAutomator("new UiSelector().text(\"Sign Up\")"); | |
//let's check if we are on signup screen | |
Assert.assertEquals("Wrong number of texts found", 1, elementsWithText.size()); | |
driver.findElementById(wrap("tetUserName")).setValue("John"); | |
driver.findElementById(wrap("tetPassword")).setValue("12345"); | |
driver.findElementById(wrap("tetPasswordRepeat")).setValue("12345"); | |
driver.findElementById(wrap("btnSignup")).click(); | |
elementsWithText = driver.findElementsByAndroidUIAutomator("new UiSelector().text(\"Manage Users\")"); | |
//assert we are indeed logged in now | |
Assert.assertEquals(1, elementsWithText.size()); | |
//let's click Manage Users if so | |
elementsWithText.get(0).click(); | |
} | |
//to help with specifying qualified ID's | |
private String wrap(String id) { | |
return PACKAGE_NAME + ":id/" + id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment