美文网首页江梆梆我爱编程
Jenkins执行selenium不能启动浏览器的解决方法

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

作者: 云谁之殇 | 来源:发表于2018-04-06 20:32 被阅读710次

关于在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")
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);
    }

相关文章

网友评论

    本文标题:Jenkins执行selenium不能启动浏览器的解决方法

    本文链接:https://www.haomeiwen.com/subject/fsvshftx.html