Jenkins执行selenium不能启动浏览器的解决方法

关于在Linux下,使用Jenkins执行selenium执行自动化测试任务时不能启动浏览器的解决方法:

  • 1、因为执行需要GUI环境,如果没有当然不能启动启动浏览器了。可以使用xvnc来解决。
    服务端安装后,并设置密码,不然jenkins下不能正确执行。在项目构建环境里勾选Run Xvnc during build
sudo apt-get install vnc4server
# Now start the VNC server once as the jenkins user and give it a password, 
# otherwise it'll try to ask Jenkins
su jenkins
[enter password: vncserver]

then kill that VNC session (for example "vncserver -kill :1")

《Jenkins执行selenium不能启动浏览器的解决方法》 1.png

  • 2、在执行时遇到错误,测试发现最大化浏览器时会造成浏览器异常退出,代码为
driver.manage().window().maximize();

修改为在启动浏览器时添加最大化参数:

public static WebDriver getChromeDriver() {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--start-maximized","--test-type");
        return new ChromeDriver(options);
    }
    原文作者:云谁之殇
    原文地址: https://www.jianshu.com/p/ba9bec6e7744
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞