【发布时间】:2016-10-04 09:42:49
【问题描述】:
我在使用 Selenium WebDriver 时创建了一个测试框架,并且我想启动 chrome 浏览器,它工作正常,因为我通过 eclipse 运行相同的,但是当我尝试通过 jenkins 运行相同的脚本时它会出现以下错误:-
错误:-
T E S T S
-------------------------------------------------------
Running TestSuite
Starting ChromeDriver 2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf) on port 45706
Only local connections are allowed.
我启动浏览器的代码是:-
public class BrowserSelection {
public static WebDriver driver;
public FileInputStream fis;
public static File file;
public static Properties prop;
public String username;
public String password;
public static XSSFWorkbook wb;
public static XSSFSheet ws;
public static WebDriverWait wait;
public static Screen src;
public static Pattern prn;
@BeforeSuite()
public void browser() throws Exception{
//property file load
prop=new Properties();
file=new File(System.getProperty("user.dir")+"\\src\\main\\resources\\config\\config.properties");
fis=new FileInputStream(file);
prop.load(fis);
//excel file load
fis=new FileInputStream(System.getProperty("user.dir")+"\\src\\main\\resources\\excel\\data.xlsx");
wb=new XSSFWorkbook(fis);
file=new File("D:\\LoyalityFiles\\");
//File[] dir_contents=file.listFiles();
if (prop.getProperty("browser").equalsIgnoreCase("firefox")) {
/*ProfilesIni profile=new ProfilesIni();
FirefoxProfile myprofile=profile.getProfile(prop.getProperty("firefoxprofilename"));*/
FirefoxProfile myprofile=new FirefoxProfile();
myprofile.setPreference("browser.download.dir",prop.getProperty("firefoxfilesave"));
myprofile.setPreference("browser.download.folderList", 2);
myprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
driver=new FirefoxDriver(myprofile);
}else if (prop.getProperty("browser").equalsIgnoreCase("chrome")) {
System.setProperty("Webdriver.chrome.driver",System.getProperty("user.dir")+prop.getProperty("chromeexe"));
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", prop.getProperty("chromefileSave"));
DesiredCapabilities caps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("--disable-extensions");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver=new ChromeDriver(caps);
}
driver.get(prop.getProperty("testURL"));
//driver.manage().window().maximize();
driver.manage().window().setSize(new Dimension(1366, 768));
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
*这是基于 maven 的项目。
我认为 Jenkins 无法设置 chrome exe 路径。请建议!这个怎么解决.....
【问题讨论】:
标签: jenkins selenium-webdriver jenkins-plugins