2017-01-09 307 views
0

我一直在試圖讓Jenkins在我的自動化測試中使用Chrome。當我在本地運行測試時,我可以通過TestNG的JDK VM選項中的-Dbrowser = chrome來使用C​​hrome。配置Jenkins使用Chrome - Selenium 3.0.1 Maven TestNG

enter image description here

出於某種原因,它似乎是停留在使用Firefox不管我怎麼努力。

這裏是我以前的方法

@BeforeMethod(
    alwaysRun = true 
) 
public static void configureBrowserBeforeTest(Method testMethod) { 
    try { 
     ((Driver)driver.get()).resetBrowser(); 
     wait.set(newDefaultWait()); 
     userAgent = determineUserAgent(); 
     initialiseNewScreenshotCapture(testMethod); 
    } catch (Exception var2) { 
     logger.error("Failed to configure browser.", var2); 
     throw new RuntimeException("Failed to configure browser.", var2); 
    } 
} 

及POM文件

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.frameworkium</groupId> 
    <artifactId>Frameworkium</artifactId> 
    <packaging>jar</packaging> 
    <version>2.0.5</version> 

    <name>Frameworkium</name> 
    <description> 
     A template designed to get up and running quickly with Selenium and Appium. 
    </description> 
    <url/> 
    <inceptionYear/> 
    <organization/> 
    <licenses/> 

    <developers/> 
    <contributors/> 

    <prerequisites> 
     <maven>3.1.1</maven> 
    </prerequisites> 

    <modules/> 

    <scm/> 
    <issueManagement/> 
    <ciManagement/> 
    <distributionManagement/> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <env.config>local</env.config> 
     <threads>1</threads> 
     <groups/> 
     <aspectj.version>1.8.9</aspectj.version> 
    </properties> 

    <repositories> 
     <repository> 
      <id>jitpack.io</id> 
      <url>https://jitpack.io</url> 
     </repository> 
    </repositories> 

    <dependencies> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.9.8</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.11</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>com.github.Frameworkium</groupId> 
      <artifactId>frameworkium-core</artifactId> 
      <version>2.3.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-remote-driver</artifactId> 
      <version>3.0.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-server</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
     <testSourceDirectory>src/test/java</testSourceDirectory> 
     <resources> 
      <resource> 
       <directory> 
        src/main/resources 
       </directory> 
      </resource> 
     </resources> 
    </build> 
    <profiles> 
     <profile> 
      <id>tests</id> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <build> 

       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-compiler-plugin</artifactId> 
         <version>3.5.1</version> 
         <configuration> 
          <source>1.8</source> 
          <target>1.8</target> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-surefire-plugin</artifactId> 
         <version>2.19.1</version> 
         <configuration> 
          <parallel>methods</parallel> 
          <threadCount>${threads}</threadCount> 
          <systemProperties> 
           <screenshotDirectory> 
            ${project.build.directory}/screenshots 
           </screenshotDirectory> 
           <allure.issues.tracker.pattern> 
            /browse/%s 
           </allure.issues.tracker.pattern> 
          </systemProperties> 
          <suiteXmlFiles> 
           <suiteXmlFile>testng.xml</suiteXmlFile> 
          </suiteXmlFiles> 
          <includes> 
           <include>**/Test*.java</include> 
           <include>**/*Tests*.java</include> 
           <include>**/*Tests.java</include> 
           <include>**/*Test.java</include> 
           <include>**/*TestCase.java</include> 
          </includes> 
          <groups>${groups}</groups> 
          <testFailureIgnore>false</testFailureIgnore> 
          <argLine> 
           -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" 
          </argLine> 
         </configuration> 
        </plugin> 
       </plugins> 

      </build> 
     </profile> 
    </profiles> 
</project> 

enter image description here

我敢肯定,該解決方案是簡單的東西,我已經詹金斯作爲服務運行和使用一個本地管理員帳戶。我已經安裝了jenkins的chromedriver插件以及Selenium插件。測試結果正常,但他們正在使用Firefox和FF版本50似乎無法與Selenium 3.0.1上的壁虎驅動程序一起使用,所以我寧願使用Chrome,我知道它的工作正常,但對於我的生活我無法圖如何告訴詹金斯使用Chrome而不是FF。在此先感謝您的幫助!如果我遺漏了任何東西,我們表示歉意。

OS - Windows Server 2012中 Maven的 TestNG的 硒3.0.1

回答

1

我猜測,定義要使用的默認瀏覽器是Firefox和測試代碼是不是能夠找到瀏覽器的味道使用(通過命令行(或)JVM args(或)通過參數),所以它的默認值是它所知道的,即firefox

我注意到在你的IntelliJ運行配置截圖中,你已經使用JVM參數-Dbrowser=chrome指定了瀏覽器的風格,但由於某些原因,我在你的Jenkins配置頁面截圖中看不到相同的結果。

你似乎有這樣的事情clean install package -DBrowserName="$BROWSERNAME" -e

能否請您將其更改爲clean install package -Dbrowser=$BROWSERNAME -e(我不認爲你需要附上$BROWSERNAME引號和我假設BROWSERNAME指的是有效的參數在詹金斯配置頁面)

這應該基本上照顧你的問題。

+0

謝謝你解決了我的問題。它作爲無頭瀏覽器運行,我如何才能啓動瀏覽器? – OhAye

+0

請檢查是否有幫助http://stackoverflow.com/questions/9618774/jenkins-selenium-gui-tests-are-not-visible-on-windows –