簡體   English   中英

如何使用uiautomator2通過appium驗證烤面包消息?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM