使用Selenium启动浏览器时出现Jenkins错误

时间:2016-09-19 05:54:49

标签: java selenium jenkins selenium-webdriver jenkins-pipeline

我正在尝试执行一个简单的selenium脚本,该脚本打开Chrome浏览器,导航到网址并在Jenkins中打印其Window标题。

执行上述操作时出现以下错误。但是,如果我只打印一份声明,那么它在詹金斯的工作正常。

请帮我解决这个问题。

错误:

Building in workspace C:\Users\ck\workspace\SampleProject
[SampleProject] $ cmd /c call C:\windows\TEMP\hudson3697205497891765709.bat

C:\Users\ck\workspace\SampleProject>sample_runme.bat

C:\Users\ck\workspace\SampleProject>set projectLocation=C:\Users\ck\workspace\SampleProject 

C:\Users\ck\workspace\SampleProject>cd C:\Users\ck\workspace\SampleProject 

C:\Users\ck\workspace\SampleProject>set classpath=C:\Users\ck\workspace\SampleProject\bin;C:\Users\ck\workspace\SampleProject\lib\* 

C:\Users\ck\workspace\SampleProject>java org.testng.TestNG C:\Users\ck\workspace\SampleProject\testng.xml 
[TestNG] Running:
  C:\Users\ck\workspace\SampleProject\testng.xml

******Welcome to the Jenkins Exe****
Starting ChromeDriver 2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1) on port 20571
Only local connections are allowed.

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

Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

Selenium脚本:

public class SampleClass {

	
	@Test
	public void testMethod(){

		System.out.println("******Welcome to the Jenkins Exe****");
		
		System.setProperty("webdriver.chrome.driver", "C:/Users/chetan.k.thimmanna/Documents/Selenium/Resources/chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("http://toolsqa.com/");
		System.out.println("Title"+driver.getTitle());
	}
}

2 个答案:

答案 0 :(得分:0)

URL下载最新的Chrome驱动程序。

设置下载的webdriver exe文件路径,例如:

System.setProperty("webdriver.chrome.driver", "<download path>\\Softwares\\chromedriver\\chromedriver.exe");

答案 1 :(得分:0)

尝试更改正斜杠以加倍反斜杠

System.setProperty("webdriver.chrome.driver", "C:\\Users\\chetan.k.thimmanna\\Documents\\Selenium\\Resources\\chromedriver.exe");