这是我的代码段:
包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);
}
}
}
包C中的CheckboxesPage.java
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);
}
}
B中的VerifyABTestingPage.java
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);
}
}
}
C中的ABTestingPage.java
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);
}
}
C中的MainPage.java
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中的第一个类名),仅此类的第一个测试用例。不知道为什么。
答案 0 :(得分:2)
尝试重新配置testNG.xml并注释测试
AlertDialog
请用适当的组名注释测试:
setState
希望这至少在调试阶段有所帮助。让我知道您将得到什么结果。
建议,请尝试从官方testNg doc here逐步逐步进行设置。