我想使用Jenkins运行在TestNG框架中编写的Selenium测试。
在jenkins作业(Freestyle项目)中配置的命令:
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 -->
环境详情:
答案 0 :(得分:2)
根据Mackowski
的建议,在Jenkins
tomcat
中安装了webapp
作为Windows Service
(而不是Jenkins as Windows Service
)并且解决了问题强>
参考:
注意:当我们在部署Jenkins inside tomcat
时运行测试时,不会启动/观察浏览器GUI。 **/usr/lib/nagios/plugins/check_ssh -H 127.0.0.1 -p 22**
*SSH OK - OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6 (protocol 2.0) | time=0.004430s;;;0.000000;10.000000*
,启动浏览器GUI。
答案 1 :(得分:2)
这不是TestNG或Selenium问题。当Jenkins被称为Windows服务时,有时会发生此错误。在像Tomcat或GlassFish这样的servlet容器中安装Jenkins,它应该有所帮助。