【问题标题】:How to save screenshot to android device by appium+selenium如何通过appium + selenium将屏幕截图保存到Android设备
【发布时间】:2017-02-14 15:58:36
【问题描述】:

有人知道如何将appium + selenium从真实android设备截取的屏幕截图保存到设备本地存储吗? 在这里,我有可以从设备截取屏幕截图并将其保存到 PC 存储的方法。 但是如何设置路径以将它们保存在真实设备文件夹中(例如 deviceName\tablet\GUI\screenshots\screenshot.jpg ...或其他方式), 考虑到代码应该在 PC 上运行。

附言我的应用是混合应用,所以我将上下文切换到“NATIVE_APP”,然后返回到 WEBVIEW。

    public static void getScreenshot(String screenName) throws IOException {
    String contextName = AppiumConfigurationTest.driver.getContext();
    AppiumConfigurationTest.driver.context("NATIVE_APP");

    String Screenshotpath = "C:\\!automation\\build\\reports\\gui_screen_capture\\";
    File screenShot = AppiumConfigurationTest.driver.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenShot, new File(Screenshotpath + screenName+"_ " + "." + "jpg"));

    AppiumConfigurationTest.driver.context(contextName);


}

【问题讨论】:

    标签: android selenium automation screenshot appium


    【解决方案1】:

    您可以从您的代码中执行 adb 命令,在这种情况下,这将对您有所帮助:

    adb shell screencap -p /sdcard/screen.png
    

    注意:将屏幕截图保存在具有不同命名测试/构建的笔记本电脑上比保存在设备上更好。

    【讨论】:

      【解决方案2】:
      File scrFile = ((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE);
      
      BufferedImage originalImage=null;
      
      try {
          originalImage= ImageIO.read(((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE));
      }
      catch(Exception e) {
          System.out.println("\n\n\n\nbuffered image" + originalImage +"\n\n\n\n\n\n");
          Thread.sleep(5000);
          e.printStackTrace();
      }
      
      System.out.println("buffered image" + originalImage);
      BufferedImage.TYPE_INT_ARGB : originalImage.getType();
      BufferedImage resizedImage = CommonUtilities.resizeImage(originalImage, IMG_HEIGHT, IMG_WIDTH);
                  ImageIO.write(resizedImage, "jpg", new File(path + "/"+ testCaseId + "/img/" + index + ".jpg"));
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 2013-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      相关资源
      最近更新 更多