开发者

Running same tests on multiple URLs in testNG

i have created few test cases are i need to test on multiple pages of website. i want to execute the test cases on all the pages by providing url of pages in excel sheet and then running the test cases one by one on the URL.

i have put the test suite name , test class name and methods name in te开发者_StackOverflowstng.xml so that order of execution is maintanined. Now how to write a program to run these tests recursively on all webpages.

Thanks Vishal


Providing URLs in excel sheet is not a good idea, but it is possible to implement.

Take a look at @DataProvider annotation in TestNG. Here is an example from JUnit 4 vs TestNG article:

@Test(dataProvider = "Data-Provider-Function")
public void parameterIntTest(Class clzz, String[] number) {
   System.out.println("Parameterized Number is : " + number[0]);
   System.out.println("Parameterized Number is : " + number[1]);
}

//This function will provide the patameter data
@DataProvider(name = "Data-Provider-Function")
public Object[][] parameterIntTestProvider() {
    return new Object[][]{
               {Vector.class, new String[] {"java.util.AbstractList", "java.util.AbstractCollection"}},
               {String.class, new String[] {"1", "2"}},
               {Integer.class, new String[] {"1", "2"}}
              };
}

Your Data Provider implementation will have to load the data from the excel sheet and return it as an Object[][]. Obviously an easier way it is to have the URLs hard coded in the Data Provider implementation. Or you can have the test URLs listed in the testng.xml as explained in the article mentioned. But that is your choice depending on how much flexibility you have in implementing the solution.

This answers the TestNG part. You probably need to ask or search "how to read an excel sheet in java". Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜