2016-12-15 130 views
1

我想運行使用Jenkins在TestNG框架中編寫的Selenium測試。如何使用TestNG框架和Jenkins運行Selenium測試

的命令詹金斯作業(自由泳項目)的配置:

java -cp J:\taf\testng\*;J:\taf\workspace\TestNGExamples\bin;J:\automation\* org.testng.TestNG J:\taf\workspace\TestNGExamples\testng1.xml 

注:-cp argument,給testng jar, test classes, and selenium jar

當我運行的作業(Build Now選項)的目錄路徑,它越來越在創建Selenium會話活動時發生並給出錯誤。

注:

同樣的命令從命令行跑的時候跑成功。從控制檯輸出

錯誤日誌:(詹金斯)

Started by user Naveen 
Building in workspace C:\Program Files (x86)\Jenkins\workspace\TestNG Example 
[TestNG Example] $ cmd /c call C:\Windows\TEMP\hudson2261889395366550414.bat 

C:\Program Files (x86)\Jenkins\workspace\TestNG Example>java -cp J:\taf\testng\*;J:\taf\workspace\TestNGExamples\bin;J:\automation\* org.testng.TestNG J:\taf\workspace\TestNGExamples\testng1.xml 
[TestNG] Running: 
    J:\taf\workspace\TestNGExamples\testng1.xml 

1481801204206 geckodriver INFO Listening on 127.0.0.1:1387 
Dec 15, 2016 4:56:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end 
1481801204827 mozprofile::profile INFO Using profile path C:\Windows\TEMP\rust_mozprofile.KDz9DWYpWQAM 
1481801204829 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe 
1481801204831 geckodriver::marionette INFO Connecting to Marionette on localhost:7795 
1481801206090 Marionette INFO Listening on port 7795 

###!!! [Parent][MessageChannel] Error: (msgtype=0x2E007D,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv 

JavaScript error: resource://app/modules/ContentCrashHandlers.jsm, line 75: TypeError: browser.permanentKey is not a non-null object 

###!!! [Parent][MessageChannel] Error: (msgtype=0x2E007D,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv 

Dec 15, 2016 4:56:47 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
INFO: Detected dialect: W3C 

###!!! [Parent][MessageChannel] Error: (msgtype=0x2E007D,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv 

以下是測試類:

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.Test; 

    public class SeleniumTests { 

     @Test 
     public void test1(){ 
      WebDriver driver = new FirefoxDriver(); 
      driver.get("http://www.google.co.in"); 
      driver.quit(); 
     } 

    } 

以下是testng1.xml

<?xml version="1.0" encoding="UTF-8"?> 

<suite name="Default suite"> 
    <test verbose="2" name="Default test"> 
    <classes> 
     <class name="SeleniumTests"/> 
    </classes> 
    </test> <!-- Default test --> 
</suite> <!-- Default suite --> 

環境細節:

  1. 詹金斯 - 2.19.4(作爲Windows服務)
  2. 爪哇 - 1.8
  3. TestNG的 - 6.8.5
  4. 硒 - 3.0.1
  5. 火狐 - 51
  6. geckodriver - 0.11。 1
  7. 鋨 - 的Windows 7 - 64位
+0

你使用哪個操作系統? Linux呢?視窗? – mackowski

+0

Windows操作系統 - 7 - 64位 –

+0

對於ChromDriver,沒有觀察到任何問題。但對於IEDriver,得到'org.openqa.selenium.NoSuchWindowException:無法獲取瀏覽器(警告:服務器沒有提供任何堆棧跟蹤信息)' –

回答

2

這不是TestNG或Selenium問題。當Jenkins被安裝爲Windows Service時,有時會出現此錯誤。安裝Jenkins內部像Tomcat或GlassFish的servlet容器,它應該有所幫助。

2

如所建議的通過Mackowski,安裝Jenkinstomcat中作爲webapp(而不是Windows Service)並且它解決了問題

參考:

  1. https://wiki.jenkins-ci.org/display/JENKINS/Tomcat

注:當我們部署Jenkins as Windows Service當運行測試,沒有瀏覽器的GUI啓動/觀察。 Jenkins inside tomcat,瀏覽器GUI啓動。

相關問題