I am new to Appium. I try to test the OnClick function of a button. The Activity includes a Button and a TextView. When I click the Button, the text of the TextView changes (only 1 time - not toggle). However, the OnClick funtions does not work. This is my Test:
@Test
public void click_button() {
AndroidElement text = (AndroidElement)((AndroidDriver)driver).findElementById(package_ + "text");
AndroidElement button = (AndroidElement)((AndroidDriver)driver).findElementById(package_ + "button");
String prevTest = text.getText();
wait.until(ExpectedConditions.visibilityOf(button));
//attemp 1
button.click();
driver.findElement(MobileBy.className("android.widget.Button")).click();
//attempt 2
Actions actions = new Actions(driver);
actions.click(button);
actions.perform();
//attempt 3
AndroidTouchAction touch = new AndroidTouchAction ((PerformsTouchActions) driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (button)))
.perform ();
String postTest = text.getText();
assertNotEquals(prevTest, postTest);
}
This is my OnClick Function:
public void buttonClick(View view) {
textView.setText("Clicked");
}
The test case fails. How do I fix this? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire