APP——自动化——java——截图到桌面

package csgc;


import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;




import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;

public class ces 
{

    public static void main(String[] args) throws InterruptedException, IOException 
    {

        DesiredCapabilities capabilities = new DesiredCapabilities();  

        capabilities.setCapability("platformName", "Android");  
        capabilities.setCapability("deviceName","8DF6R17503000072");  
        capabilities.setCapability("platformVersion", "8.0.0"); 
        
        capabilities.setCapability("unicodeKeyboard","True");
        capabilities.setCapability("resetKeyboard","True");
        
        capabilities.setCapability("autoGrantPermissions", "True");  
        
     //   capabilities.setCapability("app", "C:\\Users\\del\\Desktop\\b\\jsq.apk");  
        
        capabilities.setCapability("appPackage", "com.youba.calculate");  
        capabilities.setCapability("appActivity", "com.youba.calculate.MainActivity");  
        
        capabilities.setCapability("automationName", "uiautomator2"); 
        
        
        AppiumDriver driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        
        
        driver.manage().timeouts().implicitlyWait(500, TimeUnit.SECONDS);
        
        
        Thread.sleep(5000);
        
        DateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd-------HH-mm-ss");  //创建一个data format对象
        Date date = new Date();  //利用Date()获取当前时间            
        String date1 = dateformat.format(date);    //格式化时间,并用String对象存储        
        System.out.println(date1);   //打印格式化时间到控制台
        
        
        File src02= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);  // 调用截图方法
        FileUtils.copyFile(src02, new File("C:\\Users\\del\\Desktop", date1 + ".png"));

       

        
        Thread.sleep(5000);
        
        driver.quit();
        
        

    }

}

 

 

 

执行结果:

 

2020-06-27-------17-03-27

 

 

APP——自动化——java——截图到桌面

 

APP——自动化——java——截图到桌面

上一篇:iOS设计尺寸


下一篇:【JavaScript】 call、apply重写bind方法