簡體   English   中英

如何使用TestNG框架和Jenkins運行Selenium測試

[英]How to run Selenium tests using TestNG framework and Jenkins

我想使用Jenkins運行用TestNG框架編寫的Selenium測試。

在jenkins job(Freestyle project)中配置的命令:

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的創建會話活動中被打中並給出錯誤。

注意:

命令行中運行時,相同的命令運行成功

控制台輸出的錯誤日志: (jenkins)

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. Jenkins-2.19.4(作為Windows服務)
  2. Java-1.8
  3. TestNG-6.8.5
  4. 硒-3.0.1
  5. Firefox-51
  6. 壁虎-0.11.1
  7. 操作系統-Windows 7-64位

正如Mackowski所建議的Mackowski ,將Jenkins作為Mackowski webapp (而不是Windows Service )安裝在tomcat ,並解決了該問題

參考:

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

注意:當我們在將Jenkins as Windows Service部署Jenkins as Windows Service時運行測試時,不會啟動/觀察到任何瀏覽器GUI。 Jenkins inside tomcat ,啟動了瀏覽器GUI。

這不是TestNG或Selenium問題。 將Jenkins安裝為Windows服務時,有時會發生此錯誤。 在Tomcat或GlassFish之類的servlet容器中安裝Jenkins,它應該會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM