gpt4 book ai didi

java - 在 TestNG.xml 中使用组时忽略 @AfterMethod 调用

转载 作者:搜寻专家 更新时间:2023-10-31 19:29:10 25 4
gpt4 key购买 nike

我有一个包含以下代码的测试:

public class ViewLineList 
{

Browser browser = new Browser();
WebDriver driver;

public void viewLineList(String driverName)
{
driver = browser.getDriver(driverName);

//Navigate to System Facing
driver.manage().window().maximize();
driver.navigate().to("URL GOES HERE");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

//Verify Line List is present
WebElement lineList = driver.findElement(By.xpath("/html/body/div/div/div/div/form/div/div[2]/div/div[2]/div"));
Assert.assertNotNull(lineList, "The Line List is empty");
Assert.assertEquals(true, lineList.isDisplayed(), "The line list is not displayed");

//Verify Columns are present

WebElement poEligibleColumn = driver.findElement(By.linkText("PO Eligible"));
WebElement patientColumn = driver.findElement(By.linkText("Patient/SSN"));
WebElement wardColumn = driver.findElement(By.linkText("Ward/Room"));
WebElement drugColumn = driver.findElement(By.linkText("Drug"));
WebElement dosageColumn = driver.findElement(By.linkText("Dosage"));
WebElement startDateColumn = driver.findElement(By.linkText("Start Date"));
WebElement nextDoseColumn = driver.findElement(By.linkText("Next Dose"));
WebElement lastReviewDateColumn = driver.findElement(By.linkText("Last Review Date"));
WebElement reviewerColumn = driver.findElement(By.linkText("Reviewer"));
WebElement toolsColumn = driver.findElement(By.linkText("Tools"));

Assert.assertEquals(true, poEligibleColumn.isDisplayed(), "The PO Eligible column is not present");
Assert.assertEquals(true, patientColumn.isDisplayed(), "The Patient column is not present");
Assert.assertEquals(true, wardColumn.isDisplayed(), "The Ward column is not present");
Assert.assertEquals(true, drugColumn.isDisplayed(), "The Drug column is not present");
Assert.assertEquals(true, dosageColumn.isDisplayed(), "The Dosage column is not present");
Assert.assertEquals(true, startDateColumn.isDisplayed(), "The Start Date column is not present");
Assert.assertEquals(true, nextDoseColumn.isDisplayed(), "The Next Dose column is not present");
Assert.assertEquals(true, lastReviewDateColumn.isDisplayed(), "The Last Review Date column is not present");
Assert.assertEquals(true, reviewerColumn.isDisplayed(), "The Reviewer column is not present");
Assert.assertEquals(true, toolsColumn.isDisplayed(), "The Tools column is not present");
}

测试 - 运行这些

@Test(groups = {"functionalTests.FF"})
public void test_ViewLineList_FF()
{
viewLineList("firefox");
}

@Test(groups = {"functionalTests.IE"})
public void test_ViewLineList_IE()
{
viewLineList("ie");
}
@AfterMethod
public void tearDown()
{
driver.quit();
}

当我从上面的类运行测试时,@AfterMethod 工作正常。当我从我的 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" preserve-order="true">
<groups>
<run>
<include name="functionalTests.FF"/>
<exclude name="functionalTests.IE"/>
<exclude name="functionalTests.iOS"/>
</run>
</groups>
<classes>
<class name="ui_Tests.ViewLineList"/>
<!-- <class name="ui_Tests.ViewLineListResolutions"/>
<class name="ui_Tests.InteractWithLineList"/>
<class name="ui_Tests.POEligibleTests"/>
<class name="ui_Tests.DisableColumns"/>
<class name="ui_Tests.ExpandCollapseBars"/>
<class name="ui_Tests.BarGraphs"/> -->
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

如果我从 XML 文件运行测试,则 @AfterMethod 将被忽略。我同样尝试过 @AfterTest@AfterClass,当测试失败时,它们似乎都被忽略了。

最佳答案

您的 @AfterMethod 未运行,因为它不在您正在运行的组中。您已指定该组或告诉它始终运行。

@AfterMethod(groups = {"functionalTests.FF"})

@AfterMethod(alwaysRun = true)

您很可能想使用 alwaysRun = true

关于java - 在 TestNG.xml 中使用组时忽略 @AfterMethod 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14124055/

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