【问题标题】:unable to open chrome browser in jenkins for selenium script无法在jenkins中为硒脚本打开chrome浏览器
【发布时间】: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


【解决方案1】:

很可能,这与您的 Selenium 测试和 Chrome 浏览器路径无关,而是与 Jenkins 从属和 Chrome 浏览器本身有关。 如果我错了,请纠正我,但您的 Jenkins 正在从 Windows 服务运行从属服务器并尝试打开 Chrome 浏览器。这意味着您已将 Chrome 进程作为 Jenkins Windows 服务的子进程启动,并且 Chrome 正试图摆脱这一点(也就是 Chrome 在会话 0 中无法正常工作)。

还有一个错误记录在here,您可以在其中阅读更多信息。

我的 TFS 运行测试也遇到了这种情况,其中测试代理设置为 Windows 服务,解决方案是将其设置为进程。

因此,最简单的解决方案是将 Jenkins 设置为进程,而不是服务。

【讨论】:

  • 有没有办法可以将 chrome 选项设置为作为进程而不是子进程运行?
猜你喜欢
  • 1970-01-01
  • 2017-01-06
  • 2019-08-22
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-19
相关资源
最近更新 更多