Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the sample code for Appium automated screenshots?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report