【问题标题】:How to verify the toast message via appium with uiautomator2?如何使用 uiautomator2 通过 appium 验证 toast 消息?
【发布时间】:2018-09-10 15:13:44
【问题描述】:

我编写了一个应用程序,其中包含一个按钮,它将显示一条 toast 消息。

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')

【问题讨论】:

    标签: java appium


    【解决方案1】:

    诀窍在于找到正确的 XPath。我使用以下方法之一进行了管理:

    //android.widget.Toast
    //android.widget.Toast[@text='toast text']
    

    【讨论】:

      【解决方案2】:

      您可以像这样捕获吐司:

      WebElement toastView = androidDriver.findElement(By.xpath("//android.widget.Toast[1]")); String text = toastView.getAttribute("name");

      Here 是我的解决方案。

      【讨论】:

        猜你喜欢
        • 2020-06-16
        • 2018-09-12
        • 1970-01-01
        • 1970-01-01
        • 2014-09-06
        • 2021-11-06
        • 2021-05-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多