What is the sample code for Appium automated screenshots?
The content of this article mainly revolves around Appium automation screenshot sample code is what to tell, the content of the article is clear and easy to understand, organized, very suitable for beginners to learn, worth reading. Interested friends can read along with Xiaobian. I hope everyone gets something out of this article!
public class Screenshot {
public static void Screenshot(AndroidDriver driver,String ScreenName)throws IOException{
//Set time format
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd-mm-ss");
//Generate timestamp
String dateString =formatter.format(new Date());
String dir_name=System.getProperty("user.dir")+"\\exception picture";
System.out.println("exception picture directory"+dir_name);
//Because there may be abnormal pictures and they may be deleted, it is necessary to determine whether the directory exists first.
if(! (new File(dir_name).isDirectory()));
{
//determine whether the directory exists
new File(dir_name).mkdir();
}
//call method to capture picture
File screen=driver.getScreenshotAs(OutputType.FILE);
//copy files to specified directory
//The path to the last image is generated by directory: dir_name + timestamp + test suite + test case + test step combination
System.out.println("Exception Picture Name"+dir_name+"\\"+dateString+ScreenName+".jpg");
FileUtils.copyFile(screen,new File(dir_name+"\\"+dateString+ScreenName+".jpg"));
}
}
//Test class
Screenshot(driver,"Demo")
You can also try.. catch
try{
swipe_1();
}catch(Exception e){
Screenshot(driver,"Demo")
}
Thank you for reading, I believe you have a certain understanding of "Appium automation screenshot sample code" this problem, quickly go to practice it, if you want to know more related knowledge points, you can pay attention to the website! The editor will continue to bring better articles to everyone!