toast是什么?安卓页面上弹出的提示框,这种提示框出现在屏幕上大概3秒左右就会消失。用uiautomatorviewer根本定位不到。

准备环境,Appium版本需要1.6.3以上。

代码

初始化设置

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2); 

方法

message为toast提示信息

public void assertToast(String message){
           final WebDriverWait wait = new WebDriverWait(driver, 10);
           Assert.assertNotNull(wait.until(
                 ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[contains(@text,'"+message+"')]"))));
     }
ps:不要去定位toast,尽量不要用element去接收这个元素。我们取这个提示一般来说都是来做判断比对的,所以这里直接用assert
 
再次强调:不要尝试取定位它!!!!

 

 

相关文章:

  • 2021-10-05
  • 2022-12-23
  • 2021-10-30
  • 2021-05-30
  • 2022-12-23
  • 2021-09-13
  • 2022-01-28
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2021-07-02
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案