2017-06-22 9 views
2

ファイルタイプがfileのjavaメソッドを作成しました。このメソッドは、Ashotを使用してスクリーンショットを取得し、Screenshotオブジェクトに格納します。そのスクリーンショットオブジェクトをファイルオブジェクトに変換して、ファイルオブジェクトを返す必要があります。スクリーンショットオブジェクトをAshotセレニウムのファイルオブジェクトに変換する方法

public static File grabScreenshot() { 

    try {  

Thread.sleep(Integer.parseInt(Property.getProperty("screenshotDelay"))); 

    } catch (InterruptedException e) { 
     e.printStackTrace(); 

    } catch (NumberFormatException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 

     e.printStackTrace(); 
    }  

    File screenshot=null; //creating null file object to return 

    Screenshot screenshot1 = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver()); 

    //Here I have to typecast the screenshot1 to file type so that I can return 
    return screenshot; 
} 
+0

はあなたが私たちあなたのコード表示することができますトリックを行う必要がありますか? –

答えて

1

これは

// getImage() will give buffered image which can be used to write to file 
BufferedImage bi = new AShot() 
      .shootingStrategy(ShootingStrategies.viewportPasting(100)) 
      .takeScreenshot(driver).getImage(); 

File outputfile = new File("image.jpg"); 
try { 
    ImageIO.write(bi, "jpg", outputfile); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

// Print the absolute path to see where the file is created 
System.out.println(outputfile.getAbsolutePath()); 
+0

ありがとうSighil ....それは働いた.. – dgsanket

+0

@ dgsanket ..助けあれば親切に答えを受け入れる。 – Sighil

関連する問題