简体   繁体   English

使用安装在服务器中的 jenkins 运行 selenium 脚本

[英]Run selenium scripts using jenkins installed in server

I already created a selenium script and I am able make it work.我已经创建了一个 selenium 脚本,我可以让它工作。 Also I tried to run this using jenkins installed in my local machine.我也尝试使用安装在本地机器上的 jenkins 来运行它。 Everything works fine.一切正常。 It was able launch my browser and everything.它能够启动我的浏览器和一切。 But when I try using jenkins installed in linux server ang access it through my machine I cant make it work.但是当我尝试使用安装在 linux 服务器中的 jenkins 并通过我的机器访问它时,我无法让它工作。 It got an error because it cant locate my chromedriver.它出现错误,因为它无法找到我的 chromedriver。

I'm only using this code to launch my browser.我只使用此代码来启动我的浏览器。 It works in my local machine even I remove the System.setProperty line.即使我删除了System.setProperty行,它也可以在我的本地机器上工作。

String driverPath = "C:\\Selenium\\chromedriver.exe";
public WebDriver driver;

@BeforeClass
public void launchBrowser(){
    System.setProperty("webdriver.chrome.driver", driverPath);
    driver = new ChromeDriver();
    driver.get("https://www.google.com/");

Can someone help me how to make it work.有人可以帮助我如何使它工作。 A step by step procedure would be very much help.一个循序渐进的过程会非常有帮助。

My local machine is on windows 7 and jenkins is installed in linux server.我的本地机器在 windows 7 上,jenkins 安装在 linux 服务器上。

I think the issue is that you are hard coding the driver path:我认为问题在于您对驱动程序路径进行了硬编码:

String driverPath = "C:\\Selenium\\chromedriver.exe";

So when you execute the script through Jenkins, the system tries to find the chrome driver in Jenkins machine.所以当你通过 Jenkins 执行脚本时,系统会尝试在 Jenkins 机器中找到 chrome 驱动程序。 You should write generalized code.您应该编写通用代码。 You can do that by:你可以这样做:

 String chromeDriver ="src/test/resources/driver/chromedriver.exe";

 System.setProperty("webdriver.chrome.driver", chromeDriver);

and check-in the latest drivers in the test Project only并仅在测试项目中签入最新的驱动程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM