gpt4 book ai didi

java - Junit 在 Eclipse 中通过,在 Jenkins 中失败

转载 作者:行者123 更新时间:2023-11-28 21:22:13 25 4
gpt4 key购买 nike

您好,我的 JUnit 测试在 eclipse 中通过了。 JUnit 在 Eclipse 中有所有绿色条,但是当我从 Jenkins 调用 xml 文件时,它说失败。我已经在 stakeoverflow 上搜索了几个小时,但我找不到问题所在。请帮助我的有效代码如下:

   @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 的控制台输出:

enter image description here

请帮忙。

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>

enter image description here

---------------- 新问题------------------------ enter image description here

@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);
}

最佳答案

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 应该在执行构建之前手动创建,或者应该在之前的构建过程中创建。

关于java - Junit 在 Eclipse 中通过,在 Jenkins 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48815144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com