无法在Jenkins上运行Selenium脚本,该脚本检查Web元素的可见性并获取网页的屏幕截图

时间:2019-02-27 06:59:20

标签: jenkins selenium-webdriver jenkins-plugins

我的目标是运行Selenium脚本,该脚本获取网页的屏幕截图并检查Web元素是否可见。我不知道如何在Jenkins上运行这种类型的脚本,因为Jenkins并未真正启动浏览器,然后它将如何检查Web元素是否存在以及如何获取网页的屏幕截图。当我在Jenkins上运行简单的Selenium脚本时,它很容易运行。但是当我运行使用网页截图的selenium脚本或检查可见性时,测试用例就失败了。

注意:每个测试用例都可以在Eclipse和命令行上正常运行

屏幕截图代码:

String timestamp = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss").format(new Date());
        String imgname = "mapscreenshot " + timestamp + ".png";
        String fileWithPath = "//home/dev2/Desktop/" + imgname;

        //TakesScreenshot ts = (TakesScreenshot) m1;

        //File source = ts.getScreenshotAs(OutputType.FILE);
        //File DestFile = new File(fileWithPath);
        //FileUtils.copyFile(source, DestFile);
         Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(m1);
         ImageIO.write(fpScreenshot.getImage(),"PNG",new File(fileWithPath));

        System.out.println("your screenshot is saved at location: " + fileWithPath);

    }
}

Jenkins控制台输出:

Xvfb starting$ /usr/bin/Xvfb :1 -fbdir /var/lib/jenkins/xvfb-6-..fbdir8662599402435191159
[seffcon] $ /bin/sh -xe /tmp/jenkins461101058399698797.sh
+ ./cd11.sh
[TestNG] Running:
  /home/dev2/eclipse-workspace/seffcon/cd11.xml

Starting ChromeDriver 2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5) on port 15301
Only local connections are allowed.
Feb 27, 2019 11:29:43 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Build step 'Execute shell' marked build as failure
Xvfb stopping
Finished: FAILURE

0 个答案:

没有答案