Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99408

Reusability of tests in TestNG

$
0
0

I would like to run some automated tests for testing a web application in which process workflows are handled.

For the interfacing with the application itself I've written already a Page Object Model which makes use of Selenium WebDriver in order to interact with the several components of the application.

And now I'm about to write a number of tests which should allow me to run a number of automated tests for that particular application. And as a test framework I would like to use TestNG.

But because of the fact that the application under test is a workflow application, I discovered that I always need to work me through a certain part of the process flow first in order to do a test afterwards.

Example testcase 1: Add an activity to certain task in a dossier

  1. Login to application
  2. Open dossier x
  3. Open task y within dossier x
  4. Add activity z to task y within dossier x

Example testcase 2: Add a planning for a certain activity on a task in a dossier

  1. Login to application
  2. Open dossier x
  3. Open task y within dossier x
  4. Add activity z to task y within dossier x
  5. Add the planning for activity z

So as you can see from the examples above, I always need to work myself through a certain amount of similar steps before I can do the actual test.

As a starting point for myself I started writing TestNG classes. One for testcase 1 and a second one for testcase 2. Then, within each test class I have implemented a number of test methods which correspond to the test steps.

See example code below for testcase 1:

public class Test_Add_Activity_To_Task_In_Dossier extends BaseTestWeb {

private Dossier d;
private Task t;

@Test
public void login() {
    System.out.println("Test step: login");
}

@Test(dependsOnMethods = "login")
public void open_dossier() {
    System.out.println("Test step: open dossier");
}

@Test(dependsOnMethods = "open_dossier")
public void open_task() {
    System.out.println("Test step: open task");
}

@Test(dependsOnMethods = "open_task")
public void add_activity() {
    System.out.println("Test step: add activity");
}

}

And here the example code for testcase 2:

public class Test_Add_Planning_For_Activity_To_Task_In_Dossier extends BaseTestWeb {

private Dossier d;
private Task t;

@Test
public void login() {
    System.out.println("Test step: login");
}

@Test(dependsOnMethods = "login")
public void open_dossier() {
    System.out.println("Test step: open dossier");
}

@Test(dependsOnMethods = "open_dossier")
public void open_task() {
    System.out.println("Test step: open task");
}

@Test(dependsOnMethods = "open_task")
public void add_activity() {
    System.out.println("Test step: add activity");
}

@Test(dependsOnMethods = "add_activity")
public void add_planning() {
    System.out.println("Test step: add planning");
}

}

So as you can notice already this kind of structuring the tests is not maintainable as the amount of testcases to be written grows because I'm now always repeating the same steps first before I arrive to the actual test to be done...

Therefore I would like to ask the community here upon how it would be possible to make everything more reusable and avoid the writing of repeated steps over and over in every single testcase

All ideas are more than welcome!!


Viewing all articles
Browse latest Browse all 99408

Trending Articles