我的JUnit测试通过了eclipse。 JUnit在eclipse中有所有绿色条,但是当我从Jenkins调用xml文件时它说失败了。我在赌注流量上花了好几个小时,我找不到问题。请帮助我的代码如下:
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // this allows you to execute test in order
public class AdpPortal_1_Homepage {
private WebDriver driver;
private String homeUrl;
private String homeTitle = "ADP Associate Portal";
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\eclipse\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
homeUrl = "https://myadp.adpcorp.com/wps/myportal/main/myADP_new";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
//Full test
@Test
public void fullTest() throws Exception {
step01_VerifyHomePage();
}
// Go to Home page and verify title
public void step01_VerifyHomePage() throws Exception {
driver.get(homeUrl);
// homeTitle = "ADP Associate Portal"
driver.getTitle().contains(homeTitle);
Thread.sleep(3000);
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
这也是Jenkins的控制台输出:
请帮忙。
ant文件摘要:
<target name="AdpPortal_1_Homepage">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="AdpPortal_1_Homepage" todir="${junit.output.dir}"/>
<classpath refid="ADP_Automation_(JUnit)_(Jenkins).classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
--------------新问题--------------------------
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\eclipse\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
homeUrl = "https://myadp.adpcorp.com/wps/myportal/main/myADP_new";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(homeUrl);
}
//Full test
@Test
public void fullTest() throws Exception {
step02_HoverMyWorkSpace();
}
public void step02_HoverMyWorkSpace() throws Exception {
WebDriverWait wait = new WebDriverWait(driver,20000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("DivMyWorkList"))));
if ( driver.findElement(By.id("DivMyWorkList")).isDisplayed()){
System.out.println("DivMyWorkList Visiable");
}else{
System.out.println("DivMyWorkList NOT Visiable");
}
// Assert.assertEquals(true, workspace.isDisplayed());
// Thread.sleep(3000);
}
答案 0 :(得分:1)
Ant构建中的jUnit步骤会为每个已执行的测试类创建包含测试结果的XML文件。
如果你的步骤是这样的
<target name="unit-test" depends="test-build" >
<junit printsummary="yes" haltonfailure="no" haltonerror="no" failureproperty="test.failed">
<classpath refid="test.classpath"/>
<formatter type="xml" />
<batchtest fork="no" todir="build/test-results">
<fileset dir="${test-src}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
<fail message="Test failure detected, check test results." if="test.failed" />
</target>
然后,这些文件将在项目目录下的build/test-results
目录中生成。唯一的问题是目录build/test-results
应该在执行构建之前手动创建,或者应该在构建之前的步骤中创建。