• 【Selenium-WebDriver实战篇】ScreenRecorder的实际输出路径,自己的解决方案


    ==========================================================================================================

         写在前面:

         好久以前写的截屏和录屏的程序了,最近测广告曝光想录屏,就又拎起这部分内容了。

    ==========================================================================================================

    首先,在以前的自动化框架程序里,定义了共通类,来实现截屏和录屏的功能,代码如下:

    截屏代码:

        public static void TakeScreenShot(String strFileName) throws IOException {
            if (CommonConstants.SCREEN_SHORT_FLAG) {
                WebDriver driver = TestBase.getWebDriver();
                File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                // get local system time
                Date now = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                String strTimeStampFileName = dateFormat.format(now) + "_" + strFileName;
                // Use timestamp file name
                String strFilePath = CommonConstants.SCREENSHOT_PATH + strTimeStampFileName + ".jpg";
                FileUtils.copyFile(screenshot, new File(strFilePath));
            }
        }

    录屏初始化代码:

    public static void InitScreenRecorder(String strFileName) throws IOException, AWTException {
            if (CommonConstants.SCREEN_RECORDER_FLAG) {
                // video Save Path:C:users<<UserName>>Videos
                GraphicsConfiguration gconfig = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                        .getDefaultConfiguration();
                org.monte.media.Format fileFormat = new org.monte.media.Format(MediaTypeKey, MediaType.FILE, MimeTypeKey,
                        MIME_AVI);
                org.monte.media.Format screenFormat = new org.monte.media.Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,
                        ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                        DepthKey, (int) 24, FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey,
                        (int) (15 * 60));
                org.monte.media.Format mouseFormat = new org.monte.media.Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,
                        "black", FrameRateKey, Rational.valueOf(30));
                 screenRecorder = new ScreenRecorder(gconfig, fileFormat, screenFormat, mouseFormat, null);
    }
    }

    开始录屏:

        public static void startScreenRecorder() throws IOException {
            if (CommonConstants.SCREEN_RECORDER_FLAG) {
                // Start Capturing the Video
                screenRecorder.start();
            }
        }

    结束录屏:

        public static void stopScreenRecorder() throws IOException {
            if (CommonConstants.SCREEN_RECORDER_FLAG) {
                // Stop the ScreenRecorder
                screenRecorder.stop();
            }
        }

    由于默认的录屏工具,录完屏存储的地址是默认:

    C:users<<UserName>>Videos

    不满足我现在想存储在指定目录下的需求,所以就重新调用screenRecorder构造函数:

                // screenRecorder = new ScreenRecorder(gconfig, fileFormat,
                // screenFormat, mouseFormat, null);
    
                // get local system time
                Date now = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                String strTimeStampFileName = dateFormat.format(now) + "_" + strFileName;
                String strFilePath = CommonConstants.SCREENRECORD_PATH + strTimeStampFileName;
                File movieFolder = new File(strFilePath);
                screenRecorder = new ScreenRecorder(gconfig, null, fileFormat, screenFormat, mouseFormat, null,
                        movieFolder);

    将构造函数增加了movieFolder的参数,然后就可以想怎么存就怎么存取了。

  • 相关阅读:
    [AX]AX2012激活HTTP适配器AIF端口提示错误“The deployment web site was not found for port”
    [AX]AX2012 嵌套使用Data contract class
    [AX]AX2012 对SSRS报表参数分组
    [AX]AX2012 SSRS报表的语言本地化
    [AX]AX2012 Number sequence framework :(二)实现自定义模块的Number sequence
    [AX]AX3中使用LedgerBalanceSum计算科目余额期间发生额
    [AX]AX2012 域管理员组成员没有权限部署报表
    [C#] 在C#中使用HOOK监视鼠标消息的问题
    服务器端获取客户端信息(时间 etc..)
    MSBuild version 与 ToolsVersion 的区别
  • 原文地址:https://www.cnblogs.com/conquerorren/p/11848782.html
Copyright © 2020-2023  润新知