gpt4 book ai didi

java - testng.xml 没有运行来自不同包的多个类

转载 作者:行者123 更新时间:2023-12-02 01:49:58 26 4
gpt4 key购买 nike

这是我的代码片段:
包 A 中的 BrowserFactory.java

public class Browserfactory {
public static void startBrowser(){
System.setProperty("webdriver.gecko.driver", strFirefoxDriverPath);
driver = new FirefoxDriver();
driver.get(someSampleURL);
}

@BeforeTest()
public void setDriver() {
Reports.configAndPrepareReport();
}

@AfterTest
public void tearDownDriver() {
driver.quit();
Reports.writeToHTML();
}

@BeforeSuite
public void startSuite() {
BrowserFactory.startBrowser();
}

@AfterSuite
public void endSuite() {
Reports.closeTheChannelToHTMLReport();
}
}

包B中的VerifyCheckboxesPage.java

public class VerifyCheckboxesPage extends BrowserFactory{
CheckboxesPage objCheckboxesPage;

@BeforeClass
public void beforeClass() {
new MainPage(BrowserFactory.driver).goToCheckboxesPage();
objCheckboxesPage = new CheckboxesPage(BrowserFactory.driver);
}

@Test(priority = 1)
public void verifyCheckboxesPageHeader() {
if(objCheckboxesPage.txtHeader.getText().equals("Checkboxes")) {
Reports.logStatus(LogStatus.PASS);
}
else {
Reports.logStatus(LogStatus.FAIL);
}
}

@Test(priority = 2)
public void verifyCountOfCheckboxes() {
if(objCheckboxesPage.chkCheckboxes.size() == 2) {
Reports.logStatus(LogStatus.PASS);
}
else {
Reports.logStatus(LogStatus.FAIL);
}
}
}

CheckboxesPage.java 位于包 C

public class CheckboxesPage{
WebDriver driver;

@FindBy(someMethodToFindObjectsOnPage)
public WebElement txtHeader;

@FindAll({@FindBy(someMethodToFindObjects)})
public List<WebElement> chkCheckboxes;

public CheckboxesPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
}

VerifyABTestingPage.java 位于包 B

public class VerifyABTestingPage extends BrowserFactory{
ABTestingPage objABTestingPage;

@BeforeClass
public void beforeClass() {
Reports.startTest("Verify A/B Testing page");
new MainPage(BrowserFactory.driver).goToABTestingPage();
objABTestingPage = new ABTestingPage(BrowserFactory.driver);
}

@Test(priority = 1)
public void verifyABTestingPageHeader() {
if(objABTestingPage.txtHeader.getText().equals("A/B Test Control")){
Reports.logStatus(LogStatus.PASS);
}
else {
Reports.logStatus(LogStatus.FAIL);
}
}

@Test(priority = 2)
public void verifyABTestingPageBody() {
if(objABTestingPage.txtBody.getText().contains(strExpectedBody)) {
Reports.logStatus(LogStatus.PASS);
}
else {
Reports.logStatus(LogStatus.FAIL);
}
}
}

ABTestingPage.java 位于包 C

public class ABTestingPage {
WebDriver driver;

@FindBy(someMethodToLocateObject)
public WebElement txtHeader;

@FindBy(someMethodToLocateObject)
public WebElement txtBody;

public ABTestingPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
}
}

MainPage.java 位于包 C

public class MainPage {
@FindBy(someMethodToLocateObject)
public WebElement lnkABTesting;

@FindBy(someMethodToLocateObject)
public WebElement lnkCheckboxes;

WebDriver driver;

public MainPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
}

public void goToABTestingPage() {
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(lnkABTesting)).click();
}

public void goToCheckboxesPage() {
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(lnkCheckboxes)).click();
}
}

最后,这是我的 testng.xml 的样子:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.herokuapp.internet.tests.VerifyCheckboxesPage"/>
<class name="com.herokuapp.internet.tests.VerifyABTestingPage"/>
</classes>
</test>
</suite>

问题陈述:当我通过右键单击 xml 文件并单击“运行方式”> TestNGSuite 来从 testng.xml 运行测试用例时,它只运行VerifyCheckboxesPage(testng xml 中的第一个类名),而且也运行只是此类的第一个测试用例。不知道为什么。

最佳答案

尝试重新配置 testNG.xml 并注释您的测试

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Functional Smoke Jenkins suite" parallel="false" thread-count="5" verbose="8">

<test name="test name FIRST">
<parameter name="env" value="DEFAULT"/>
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="com.herokuapp.internet.tests.VerifyCheckboxesPage"/>
</classes>
</test>
<test name="test name SECOND">
<parameter name="env" value="DEFAULT"/>
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="com.herokuapp.internet.tests.VerifyABTestingPage"/>
</classes>
</test>

并请使用适当的组名称注释测试:

  @Test(priority = 1,groups = {"smoke})
public void verifyABTestingPageHeader() {
if(objABTestingPage.txtHeader.getText().equals("A/B Test Control")){
Reports.logStatus(LogStatus.PASS);
}
else {
Reports.logStatus(LogStatus.FAIL);
}
}

希望这至少在调试阶段有所帮助。让我知道您会得到什么结果。

P.s请尝试按照官方 testNg doc here 一步步准确地进行设置。

关于java - testng.xml 没有运行来自不同包的多个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53113983/

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