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

- 2、在执行时遇到错误,测试发现
最大化浏览器
时会造成浏览器异常退出,代码为
driver.manage().window().maximize();
修改为在启动浏览器时添加最大化参数:
public static WebDriver getChromeDriver() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized","--test-type");
return new ChromeDriver(options);
}
网友评论