I have one difficult scenario for automation testing.

I want to run one test cases for 100 different URLs/Domain.

Precondition :

  • Script is generalize and running individuality properly.
  • Use of TestNG and Selenium Webdriver.
  • Different test data needed for every tesng.xml

Question :

How can I fulfill my purpose for running one scripts in single run
for all testng.xml or single test case ?

Please provide inputs so I can start working on it.

6 Answers 6


I hope this code will give you some logic understanding and configure this code according to your requirement.

Use one xml file in which you have to pass all hundred url in any tag and use them by below method

 public class test {

    public static void main(String[] args) {
         List<String> Url = getData("Urls", 100);
         // further test case coding

    public static List<String> getData(String Data, int size) {

        String[] st = null;
        File xmlfile = new File(System.getProperty("user.dir") + "\\Resource.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder dbuilder = dbFactory.newDocumentBuilder();
            Document doc = dbuilder.parse(xmlfile);

            NodeList list = doc.getElementsByTagName(Data);

            System.out.println("length of  : " + list.getLength());
            st = new String[list.getLength()];
            for (int i = 0; i < list.getLength(); i++) {

                st[i] = doc.getElementsByTagName(Data).item(i).getTextContent();
        } catch (Exception e) {

        List<String> data = new ArrayList<String>();
        return data;


here is resoucre.xml file

  • getRandomData is getData i think.. Please correct me if i am wrong.
    – Sagar007
    Jan 19, 2017 at 9:38

Can you store your 100 different website URLs into an Excel spreadsheet and run your test using data driven tests with each URL as input each time?

  • I can store anywhere. But question is What is logical way to do same ?
    – Sagar007
    Jan 17, 2017 at 12:52
  • 1
    @Sagar007 What do you mean by "logical way"?
    – dzieciou
    Jan 18, 2017 at 6:56

1) Store your urls, and test data somewhere (like xml, text file, excel or in other class)

2) At start of your test read them

3) Run test, but catch problems and Store fail / pass for each url, unless you want test to break at first error

heres a simplified pseudo example i think id write to do what i think you want to do:

list getUrlFromFile(file){

    //Get urls from file somehow

    return list


void TestMethod(){

    list Url = getUrlFromFile();

    list Passed = new list;

    for each (string url in Url) {

        try {

            //Go to url

        catch (problem){

            //log problem
            //skip and continue for next url        


    //Assert Length of Passed = Length of Url, otherwise test failed

Try TestNG Data provider,

public class SameClassDataProvider 
    @DataProvider(name = "data-provider")
    public Object[][] urldataProviderMethod() {

    return new Object[][] { { "URL1" }, { "URL2" } };

    @Test(dataProvider = "data-provider")
    public void testMethod(String url) {

    System.out.println("URL is: " + URL);

    /* based on the URL do somethings  


You can use data provider function at testNG. And save the data in local files like excel, json format.

  • 1
    Please edit your answer to explain how your suggestion solves the OP's problem.
    – Kate Paulk
    Sep 4, 2018 at 13:40
  • Sorry, I'll do it next time.
    – junghan
    Sep 10, 2018 at 7:10

I am using data provider in each class and iterating the TestNg process. I can't upfront store the URL's because they are dynamic. There is a flag set in db for which scripts needs to be run, SO, I am retrieving the data of all the URL's having the flag set along with credentials and putting them in the result set, I am sending it one after the other to property file from where the test classes take the URL and credentials. After each value is set to property file, I am running TestNg (which is stored as batch file) by using process function.

But the tests are not running for more than 3 URLs with huge test cases. Looking for a better approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.