我尝试用Appium 1.6.3在Android设备上测试获取toast消息,但是对我来说很失望,纠正得到toast的速度非常低。有人帮我吗?
答案 0 :(得分:0)
1.这取决于动态数据的来源。 2.如果你想在刷卡时获取吐司数据,那么很难获得准确的数据。
答案 1 :(得分:0)
Step 1:
public static BufferedImage getTOASTSnapShot(AppiumDriver appiumDriver, String event) {
BufferedImage originalImage=null;
BufferedImage resizedImage=null;
{
try {
System.out.println("Starting\n\n\n\n");
scrFile = ((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE);
System.out.println("after scrfile\n\n\n\n");
originalImage = ImageIO.read(scrFile);
System.out.println("after originalFile\n\n\n");
} catch (Exception) {
e.printStackTrace();
}
}
return originalImage;
Step 2 :
public BufferedImage clickfortoast(String element)
{
try{
WebElement webElement = appiumDriver.findElement(By.xpath(element));
webElement.click();
BufferedImage Toast= Report.getTOASTSnapShot(appiumDriver, "Click: " );
System.out.println("Click element: " +element);
return Toast;
}
catch(Exception exception)
{
exception.printStackTrace();
return null;
}
}
Step 3 :
BufferedImage bufferedImage=dummyPage.clickfortoastimage(PROFILE_PAGE_LOGIN_TO_WALLET_PAGE_SIGN_IN);
String result1=dummyPage.togettext_out_of_toast(bufferedImage);
String TOAST_MESSAGE_WRONG_CREDENTIALS= " " ;
String mes2=" Toast message to be checked for to be checked";
boolean check = StringUtils.containsIgnoreCase(result1,mes1);
System.out.println(check);
boolean check1=StringUtils.containsIgnoreCase(result1,mes2);
答案 2 :(得分:0)
请参阅此示例代码段以使用appium uiautomator2驱动程序验证Toast消息
assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[@text='Clicked popup menu item Search']"))));