0

我尝试使用 Appium 1.6.3 在 android 设备上测试获取 toast 消息,但对我来说很失望,正确获取 toast 的比率非常低。有人帮我吗?

4

3 回答 3

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);
于 2017-02-24T04:29:50.080 回答
0

1.这取决于动态数据是如何来的。2.如果您想在刷卡时获取toast数据,则很难获得准确的数据。

于 2017-02-23T06:57:02.567 回答
0

请参考此示例代码片段以使用 appium uiautomator2 驱动程序验证 toast 消息

assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
            By.xpath("//*[@text='Clicked popup menu item Search']"))));

https://github.com/appium/java-client/blob/72b9e6a70d3ebfba9bf6b74813e9644b2f2a9e08/src/test/java/io/appium/java_client/android/UIAutomator2Test.java#L94

于 2017-03-20T04:20:25.493 回答