2016-10-04 12 views
1

Selenium WebDriverを使用してテストフレームワークを作成しましたが、クロームブラウザを起動したいのですが、これはEclipseで同じように動作します。ジェンキンス経由で同じスクリプトを実行するには: -セレンスクリプトのジェンキンでクロムブラウザを開くことができません

エラー: -

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のベースのプロジェクトです。

ジェンキンスはchrome exeパスを設定できないと思います。 plsは提案する!これを解決する方法.....

+0

https://wiki.jenkins.io/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines+on+Windows?focusedCommentId=59510810 –

答えて

0

おそらく、これはあなたのSeleniumテストとChromeブラウザパスとは関係ありませんが、JenkinsスレーブとChromeブラウザ自体とは関係ありません。 私が間違っている場合は私を修正しますが、JenkinsはWindowsサービスからスレーブを実行し、Chromeブラウザを開こうとします。これは、Jenkins WindowsサービスのサブプロセスとしてChromeプロセスを開始し、Chromeがこれから離れようとしていることを意味します(別名セッション0ではChromeが正常に動作しません)。

さらに詳しく読むことができるhereのバグが記録されています。

テストエージェントがWindowsサービスとして設定されていて、解決策がプロセスとして設定されているTFSランテストでもこの問題が発生しました。

したがって、最も簡単な解決策は、Jenkinsをサービスではなくプロセスとして設定することです。

関連する問題