Ashish Jagtap
Ashish Jagtap

Reputation: 2819

Run multiple selenium java test cases as suite with Testng

Hi all I have written multiple test cases in selenium to perform following task using WebDriver

  1. Login to my portal
  2. Add Group
  3. Add Location

following is my selenium code to perform this task on my portal

Base Selenium Class

public class BaseSeleniumTest extends SeleneseTestBase {
    protected static WebDriver driver;
    @BeforeSuite
    public static void firefoxSetUp() throws MalformedURLException {
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
    }

    @AfterSuite
    public static void closeFirefox(){
       driver.quit();
    }
}//End BaseSeleniumTest Class.

Login Test Case

public class LogInTest extends BaseSeleniumTest {
    LogInPage page;
    public static final String BASE_URL = "http://www.mywebsite.com";

    @BeforeMethod
    public void beforeMethod() {
        page = PageFactory.initElements(driver, LogInPage.class);
        page.openPage(BASE_URL);
    }

    @Test(dataProvider="loginData",groups="loginGroup")
    public void logIn(String email,String password) {
        page.logInAs(email, password);
    }

    @DataProvider(name = "loginData")
    public Object[][] getData() {
        return new Object[][] { { "username", "password" } };
    }
}//End of LogInTest Class.

Add Group Test Case

public class AddGroupTest extends BaseSeleniumTest {
    AddGroupPage addGroupPage;
      @BeforeMethod
      public void openAddGroupPage() {
          addGroupPage = PageFactory.initElements(driver, AddGroupPage.class);
          addGroupPage.openPage();
      }

    @Test(dataProvider = "getCSVData",dataProviderClass=AddGroupsDataProvider.class,dependsOnGroups={"loginGroup"},groups="addGroup")
    public void AddGroup(String groupName,String displayName,String description) {
            addGroupPage.addGroup(groupName, displayName, description);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
}//End of AddGroupTest Class.

Add Location test Case

public class AddLocationTest extends BaseSeleniumTest {
    AddLocationPage addLocationPage;
    @BeforeMethod
      public void openAddLocationPage() {
          addLocationPage = PageFactory.initElements(driver, AddLocationPage.class);
          addLocationPage.openPage();
     }

    @Test(dataProvider = "getCSVData", dataProviderClass = AddLocationDataProvider.class, dependsOnGroups = { "loginGroup" }, groups = "addLocation")
    public void addLocation(String locationName, String displayName,
            String description, String groups) {
        addLocationPage.addLocation(locationName, displayName, description,
                groups.split(","));
    }
}  

when I run this script independently they run perfectly now I want to run this scripts as suite but I don't know where to start from. As my Add Location Test case dependent on Add Group and Add Group test case is dependent on Login test case.

following are my questions

  1. what I have do ? to run this test cases as suite.(later I have to run this suite through jar file)
  2. How I can specify dependencies among them ?

Thanks in advance...

Upvotes: 0

Views: 7138

Answers (1)

SiKing
SiKing

Reputation: 10329

Your question leads to an opinion-based answer, which is generally off-topic for SO. Consider looking through Software Quality Assurance & Testing Stack Exchange.

I'm going to attempt to give you at least some answer. You should:

  1. Consider the choice of your test framework. Something like TestNG allows you to specify dependencies.
  2. Consider the architecture of your tests. Some of your "tests" will probably be better as individual methods, which you can then call from a test. Consider using PageObject model.

Upvotes: 1

Related Questions