如何在 Selenium webdriver 中录制视频?
我们可以使用 Selenium 来录制视频。Selenium 中没有录制视频的默认技术。可以通过以下过程捕获视频-
需要下载 ATUTestRecorder.jar 和 ATUReporter_Selenium_testNG.jar 文件并将其保存在项目文件夹中。
接下来,将这两个 jar 添加到项目的构建路径。右键单击项目->单击属性->选择 Java 构建路径->单击库选项卡->单击添加外部 Jar->浏览并选择 ATUTestRecorder.jar 和 ATUReporter_Selenium_testNG.jar->单击应用->单击确定。
新建一个文件夹来保存项目中的视频。
示例
@BeforeMethod public void bmethod(Method m){ // format of the date and time defined DateFormat d = new SimpleDateFormat("yy−mm−dd HH−mm−ss"); // get the current date Date dt = new Date(); try { // video capture file name recorder = new ATUTestRecorder(System.getProperty("userdir") + "\TestVideos\" , m.getName() + "_" + d.format(dt), false); } catch (Exception e){ Log.error("Error capturing videos"); } //begin recording try { recorder.start(); } catch (Exception e){ Log.error("Error in beginning videos"); } }
示例
@AfterMethod public void amethod(iTestResult result) { try { recorder.stop(); } catch (Exception e){ Log.error("Error in stopping videos"); } }
对于 Maven 项目,pom.xml 应该有以下设置 −
广告