我想测试Toast消息而不进行屏幕截图。还有其他方法可以自动执行Toast消息吗?
答案 0 :(得分:1)
您可以获取吐司消息并定义成功/失败操作:
By toastContainer = By.xpath("//div[@id='toast-container']//*");
By toastMessageDA = By.xpath("//div[@class='toast-message']");
public String toastUtility() throws Exception {
toast_container_flag = false;
try {
if (driver.findElement(toastContainer).isEnabled()) {
toast_container_flag = true;
List<WebElement> findData = driver.findElements(toastContainer);
for (WebElement element : findData) {
if (element.getAttribute("class").toString().contains("toast toast")) {
toast_success_fail = element.getAttribute("class").toString();
}
}
validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));
if (toastr_success_fail.equals("toast toast-success")) {
System.out.println("Success Message");
} else if (toastr_success_fail.equals("toast toast-error")) {
System.out.println("Fail Message");
} else {
System.out.println("Other Message");
}
System.out.println(validationMessage);
testResult = validationMessage;
}
} catch (Exception e2) {
testResult = "Toast message is not generated.";
testlog.info(testResult);
System.out.println(testResult);
}
return testResult;
}
答案 1 :(得分:0)
Android已支持检索烤面包消息。请查看以下 Android 发行说明。
https://github.com/appium/appium/releases/tag/v1.6.3
您需要使用UIAutomator2在Android中处理吐司消息。
希望这会有所帮助。
答案 2 :(得分:0)
这对我在 python 中非常有效。
control = False
xmlFormat = self.driver.page_source
if xmlFormat.find("your toast message") != -1:
control = True
self.assertEqual(True,control)