zoukankan      html  css  js  c++  java
  • java+selenium+new——格式化时间——截图——时间名文件夹——时间名文件

    package rjcs;
    
    
    
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.awt.*;
    import java.awt.datatransfer.StringSelection;
    import java.awt.event.KeyEvent;
    import java.io.File;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.support.*;
    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;
    
    public class xinkaishi 
    {
    
        
        public static void main(String[] args)
        
        {
             System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //设置火狐的安装路径,防止系统找不到
                
             FirefoxDriver driver = new FirefoxDriver();        //初始化FireFox浏览器实例,并打开浏览器
             
            try
            {
                 driver.manage().window().maximize();         //最大化窗口
                 
                 driver.navigate().to("https://www.baidu.com"); 
                 
                 Thread.sleep(5000);
                 
                 
                 DateFormat dateformat1= new SimpleDateFormat("yyyy-MM-dd");  //创建一个data format对象
                 Date date1 = new Date();  //利用Date()获取当前时间            
                 String datex = dateformat1.format(date1);    //格式化时间,并用String对象存储        
                 System.out.println(datex);   //打印格式化时间到控制台
                 
    
                 DateFormat dateformat2= new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  //创建一个data format对象
                 Date date2 = new Date();  //利用Date()获取当前时间            
                 String datey = dateformat2.format(date2);    //格式化时间,并用String对象存储        
                 System.out.println(datey);   //打印格式化时间到控制台
                 
                 
                 
                 DateFormat dateformat3= new SimpleDateFormat("HH-mm-ss");  //创建一个data format对象
                 Date date3 = new Date();  //利用Date()获取当前时间            
                 String dateu = dateformat3.format(date3);    //格式化时间,并用String对象存储        
                 System.out.println(dateu);   //打印格式化时间到控制台
                 
                 
                 File src02= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);  // 调用截图方法
                 FileUtils.copyFile(src02, new File("C:\\Users\\del\\Desktop\\"+datex, dateu + ".png"));
                 
                 
                 Thread.sleep(5000);
                 
                 
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
        }
        
        
        
    }

    执行结果:

    2020-02-11
    2020-02-11-20-44-54
    20-44-54

  • 相关阅读:
    SQL语句在数据库中可以执行在mybatis执行不了
    spring_08aop原理及案例
    spring_07使用spring的特殊bean、完成分散配置
    spring_06装配bean_2
    spring_05装配bean
    spring_03ApplicationContext三种经常用到的实现
    spring_04bean的生命周期
    spring_02工具及接口案例
    深入理解Ribbon之源码解析
    深入理解Feign之源码解析
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12296688.html
Copyright © 2011-2022 走看看