Reputation: 698
Here are my code snippets:
BrowserFactory.java in package A
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();
}
}
VerifyCheckboxesPage.java in package B
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 in package 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 in package 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 in package 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 in package 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();
}
}
Finally, here is how my testng.xml looks like:
<?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>
Problem statement: When I run my test cases from testng.xml by right clicking on the xml file and clicking on Run As > TestNGSuite, it runs just VerifyCheckboxesPage (the 1st class name in testng xml) and that too only the 1st test case of this class. Not sure why.
Upvotes: 0
Views: 1489
Reputation: 7339
Try out to re-configure testNG.xml and annotate your tests
<?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>
And please annotate Tests with appropriate group names:
@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);
}
}
Hope this helps at least in debugging phase. Let me know what results You will get.
P.s please try to follow with Your setup accurately step-by-step from official testNg doc here.
Upvotes: 3