2016-04-06 2 views
1

appium + seleniumからデバイスのローカルストレージにリアルアンドロイドデバイスから取得したスクリーンショットを保存する方法を知っていますか? ここでは、デバイスからスクリーンショットを取得してPCストレージに保存する方法があります。 実際のデバイスフォルダ(deviceName \ tablet \ GUI \ screenshots \ screenshot.jpg ...など)に保存するパスを設定するには、 のコードをPCで実行する必要があります。appium + seleniumでアンドロイドデバイスにscreenshotを保存するには

p.s.私のアプリはハイブリッドなので、スイッチコンテキストを "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); 


} 

答えて

1

あなたは、これはあなたを助けるものとする場合には、あなたのコードからのadbコマンドを実行することができます

adb shell screencap -p /sdcard/screen.png 

は:異なる名前のテスト/ビルドでラップトップ上のスクリーンショットを保存すると、保存よりも優れていますデバイス上のそれら。

1
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")); 
+0

答えにいくつかの説明を追加することを検討してください。詳細は、http://stackoverflow.com/help/how-to-answerを参照してください。 –

+0

ImageIO.writeは画像をパスに保存します –

関連する問題