[英]How to verify the toast message via appium with uiautomator2?
我写了一个包含一个按钮的应用程序,它将显示一个吐司消息。
public void onClickShowToast(View view) {
Toast.makeText(getBaseContext(), "Change port successfully", Toast.LENGTH_LONG).show();
}
然后,我用appium编写了一个测试用例,试图对其进行验证。
//APPIUM Version: 1.6.3;
//JAVA: 1.8;
//JAVA Client: 5.0.0;
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
driver.findElementByXPath("//*[contains(@text,'Button')]").click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[contains(@text, 'port')]")))
但是,结果是失败:
org.openqa.selenium.TimeoutException:预期条件失败:等待元素的存在:By.xpath:// *包含(@ text,'port')
诀窍是找到正确的XPath 。 我使用以下方法之一对此进行了管理:
//android.widget.Toast
//android.widget.Toast[@text='toast text']
您可以这样捕获烤面包:
WebElement toastView = androidDriver.findElement(By.xpath("//android.widget.Toast[1]")); String text = toastView.getAttribute("name");
这是我的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.