我已将我的项目配置为使用 Jenkins 运行构建,如果我自己执行 testng.xml,它会成功执行我的测试用例,但如果我通过 Jenkins 执行,我会收到以下错误消息
构建步骤“执行 Windows 批处理命令”将构建标记为失败 完成:失败
但是,如果测试用例输出仅使用 `(system.out.println();),则它会成功执行构建
如果测试用例与打开浏览器相关,则通过 Jenkins 会失败
这是我的测试课
public WebDriver driver;
public String baseUrl = "http://iparkit.com/";
@BeforeMethod
public void initializeWebDriver() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
driver.manage().window().maximize();
}
//Close Browser after each test case execution
@AfterMethod
public void closeBrowser()
{
driver.close();
}
@Test(enabled=true) //TC2-01 - OK
public void iparkit_valid_email_password() throws InterruptedException
{
driver.findElement(By.xpath(".//*[@id='mast']/nav/ul/li[4]/a")).click();
driver.findElement(By.xpath(".//*[@id='email']")).sendKeys("imanltd+1@hotmail.com");
driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("*******");
driver.findElement(By.xpath(".//*[@id='top']/div/main/form/main/fieldset[3]/button")).click();
String Expectedlnktext = driver.findElement(By.linkText("Sign Out")).getText();
String Actuallnktext = "Sign Out";
Assert.assertEquals(Actuallnktext,Expectedlnktext);
}
}
这是我的 testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="automationframework.Iparkittesting"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
这是最后一个控制台输出
Started by user anonymous
Building in workspace D:\K - Selenium\SeleniumWorkspace\iParkit_copy
[iParkit_copy] $ cmd /c call C:\Windows\TEMP\hudson4187523140058494240.bat
D:\K - Selenium\SeleniumWorkspace\iParkit_copy>run.bat
D:\K - Selenium\SeleniumWorkspace\iParkit_copy>java -cp bin;lib/* org.testng.TestNG testng.xml
[TestNG] Running:
D:\K - Selenium\SeleniumWorkspace\iParkit_copy\testng.xml
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
最佳答案
在批处理脚本末尾使用 exit/b 0
应该可以解决问题。
关于java - 构建步骤 'Execute Windows batch command' 将构建标记为失败已完成 : FAILURE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34476561/