我正在尝试使用Jenkins运行TestNG测试。它给我配置失败并跳过。我在这里和其他网站上也读过类似的问题,但是它们没有帮助。 我已经阅读了这个enter link description here并尝试了alwaysRun = true,但即使这样也无法解决我的问题。
我收到这样的错误:
总测试运行:4,失败:0,跳过:2 配置失败:1,跳过:1
我的测试如下:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Search {
WebDriver driver;
@BeforeTest
@Parameters("browser")
public void crossBrowsers(String browser) throws InterruptedException {
if (browser.equalsIgnoreCase("Firefox")) {
driver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("Chrome")) {
System.setProperty("webdriver.chrome.driver", "C:\\mypath\\chromedriver.exe");
driver = new ChromeDriver();
}
driver.navigate().to("myaddress");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@Test
public void methodA() throws InterruptedException {
}
@Test
public void methodB() throws InterruptedException {
}
@AfterTest
public void quitBrowsers() {
driver.quit();
}
发布TestNG结果的堆栈跟踪:
<?xml version="1.0" encoding="UTF-8"?>
<testng-results skipped="3" failed="0" total="6" passed="3">
<reporter-output>
</reporter-output>
<suite name="Suite" duration-ms="28498" started-at="2017-12-07T09:51:27Z" finished-at="2017-12-07T09:51:55Z">
<groups>
</groups>
<test name="FirefoxTest" duration-ms="11724" started-at="2017-12-07T09:51:27Z" finished-at="2017-12-07T09:51:38Z">
<class name="scripts.CloseEachError">
<test-method status="FAIL" signature="crossBrowsers(java.lang.String)[pri:0, instance:scripts.CloseEachError@1ff8b8f]" name="crossBrowsers" is-config="true" duration-ms="0" started-at="2017-12-07T10:51:27Z" finished-at="2017-12-07T10:51:27Z">
<params>
<param index="0">
<value>
<![CDATA[Firefox]]>
</value>
</param>
</params>
<exception class="org.openqa.selenium.WebDriverException">
<message>
<![CDATA[Process unexpectedly closed with status: 0
Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:12:07.291Z'
System info: host: 'BC_LT35', ip: '192.168.26.71', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x47e934 - <no info>
1: 0x47f0a3 - <no info>
2: 0x442649 - <no info>
3: 0x449cc3 - <no info>
4: 0x42a890 - <no info>
5: 0x406f5e - <no info>
6: 0x40cfc9 - <no info>
7: 0x6bef19 - <no info>
8: 0x420756 - <no info>
9: 0x6b96e0 - <no info>
10: 0x7ffdf4d01fe4 - BaseThreadInitThunk]]>
</message>
<full-stacktrace>
<![CDATA[org.openqa.selenium.WebDriverException: Process unexpectedly closed with status: 0
Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:12:07.291Z'
System info: host: 'BC_LT35', ip: '192.168.26.71', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x47e934 - <no info>
1: 0x47f0a3 - <no info>
2: 0x442649 - <no info>
3: 0x449cc3 - <no info>
4: 0x42a890 - <no info>
5: 0x406f5e - <no info>
6: 0x40cfc9 - <no info>
7: 0x6bef19 - <no info>
8: 0x420756 - <no info>
9: 0x6b96e0 - <no info>
10: 0x7ffdf4d01fe4 - BaseThreadInitThunk
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
at scripts.CloseEachError.crossBrowsers(CloseEachError.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:616)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.TestNG.privateMain(TestNG.java:1355)
at org.testng.TestNG.main(TestNG.java:1324)
]]>
</full-stacktrace>
</exception> <!-- org.openqa.selenium.WebDriverException -->
<reporter-output>
</reporter-output>
</test-method> <!-- crossBrowsers -->
<test-method status="SKIP" signature="clkDropDownBtn()[pri:0, instance:scripts.CloseEachError@1ff8b8f]" name="clkDropDownBtn" duration-ms="0" started-at="2017-12-07T10:51:38Z" finished-at="2017-12-07T10:51:38Z">
<reporter-output>
</reporter-output>
</test-method> <!-- clkDropDownBtn -->
<test-method status="SKIP" signature="closeEachErr()[pri:0, instance:scripts.CloseEachError@1ff8b8f]" name="closeEachErr" duration-ms="0" started-at="2017-12-07T10:51:38Z" finished-at="2017-12-07T10:51:38Z">
<reporter-output>
</reporter-output>
</test-method> <!-- closeEachErr -->
<test-method status="SKIP" signature="VerifyErrList()[pri:0, instance:scripts.CloseEachError@1ff8b8f]" name="VerifyErrList" duration-ms="0" started-at="2017-12-07T10:51:38Z" finished-at="2017-12-07T10:51:38Z">
<reporter-output>
</reporter-output>
</test-method> <!-- VerifyErrList -->
<test-method status="SKIP" signature="quitBrowsers()[pri:0, instance:scripts.CloseEachError@1ff8b8f]" name="quitBrowsers" is-config="true" duration-ms="0" started-at="2017-12-07T10:51:38Z" finished-at="2017-12-07T10:51:38Z">
<reporter-output>
</reporter-output>
</test-method> <!-- quitBrowsers -->
</class> <!-- scripts.CloseEachError -->
</test> <!-- FirefoxTest -->
<test name="ChromeTest" duration-ms="16743" started-at="2017-12-07T09:51:38Z" finished-at="2017-12-07T09:51:55Z">
<class name="scripts.CloseEachError">
<test-method status="PASS" signature="crossBrowsers(java.lang.String)[pri:0, instance:scripts.CloseEachError@5474c6c]" name="crossBrowsers" is-config="true" duration-ms="3587" started-at="2017-12-07T10:51:38Z" finished-at="2017-12-07T10:51:42Z">
<params>
<param index="0">
<value>
<![CDATA[Chrome]]>
</value>
</param>
</params>
<reporter-output>
</reporter-output>
</test-method> <!-- crossBrowsers -->
<test-method status="PASS" signature="VerifyErrList()[pri:0, instance:scripts.CloseEachError@5474c6c]" name="VerifyErrList" duration-ms="41" started-at="2017-12-07T10:51:42Z" finished-at="2017-12-07T10:51:42Z">
<reporter-output>
</reporter-output>
</test-method> <!-- VerifyErrList -->
<test-method status="PASS" signature="clkDropDownBtn()[pri:0, instance:scripts.CloseEachError@5474c6c]" name="clkDropDownBtn" duration-ms="12242" started-at="2017-12-07T10:51:42Z" finished-at="2017-12-07T10:51:54Z">
<reporter-output>
</reporter-output>
</test-method> <!-- clkDropDownBtn -->
<test-method status="PASS" signature="closeEachErr()[pri:0, instance:scripts.CloseEachError@5474c6c]" name="closeEachErr" duration-ms="295" started-at="2017-12-07T10:51:54Z" finished-at="2017-12-07T10:51:54Z">
<reporter-output>
</reporter-output>
</test-method> <!-- closeEachErr -->
<test-method status="PASS" signature="quitBrowsers()[pri:0, instance:scripts.CloseEachError@5474c6c]" name="quitBrowsers" is-config="true" duration-ms="577" started-at="2017-12-07T10:51:54Z" finished-at="2017-12-07T10:51:55Z">
<reporter-output>
</reporter-output>
</test-method> <!-- quitBrowsers -->
</class> <!-- scripts.CloseEachError -->
</test> <!-- ChromeTest -->
</suite> <!-- Suite -->
</testng-results>
XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="FirefoxTest">
<parameter name="browser" value="Firefox"></parameter>
<classes>
<class name="scripts.testJenkins"/>
</classes>
</test> <!-- SearchTest -->
<test name="ChromeTest">
<parameter name="browser" value="Chrome"></parameter>
<classes>
<class name="scripts.testJenkins"/>
</classes>
</test>
</suite> <!-- Suite -->
答案 0 :(得分:0)
我卸载了我的jenkins并再次安装了战争,然后运行良好。