Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:18:15+00:00 2026-06-13T10:18:15+00:00

I am using TestNG for my selenium tests. There is a test called Create

  • 0

I am using TestNG for my selenium tests.
There is a test called “Create Firm” which needs to be run multiple times on my laptop.

So I have written a class called “CreateFirm” for this, and the data for various firms reside in an excel spreadsheet.

At various times, I need to create various sets of firms, which I control using a column in Excel spreadsheet , which holds my computer name.

I use the @Factory to create my “CreateFirm” classes, which has one @Test method to create a Firm.

In excel spreadsheet If i have assigned Firm1,Firm2,Firm3,Firm4 in the same order to my laptop, @Factory creates them in a random order like Firm4,Firm3,Firm1,Firm2

My question is how to get @Factory to create test instances in the order that I want ?

My @Factory method is

      @Factory
  public Object[] runCreateFirm()
  {

        //This is where I get the list of test cases assigned to my laptop
        this.test_id_list=get_test_ids_for_test_run("Create Firm (class approach).xls", "Global");      

        Object[] result = new Object[this.test_id_list.size()];


        int index=0 ;
        for (String firm_id: this.test_id_list)
        {
            //This is where I get all the test data from the Excel spreadsheet
            HashMap<String,String> test_data_row=this.get_row_from_excel("Create Firm (class approach).xls", "Global", "test_case_id", firm_id);

            System.out.println("Inside Firm Factory ,index="+index +", test case id="+ test_data_row.get("test_case_id"));

            //CreateFirm is the class which will use the data and do all the UI actions to create a Firm
            result[index]=new CreateFirm(test_data_row);
            index++;
        }
        return result;
  }

XML is

    <?xml version="1.0" encoding="UTF-8"?>
<suite name="CreateFirm Suite">
  <test name="Create Firm Test"  order-by-instances="false">
    <classes>
      <class name="regressionTests.factory.CreateFirmFactory"/>
    </classes>
  </test>
</suite>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:18:16+00:00Added an answer on June 13, 2026 at 10:18 am

    Managed to write the interceptor method for my requirement.
    To start with I introduced a new field in my class called “priority” . I couldnt use @Priority because, my test class had only one test method, in which case all my instantiations will have the same priority.
    So I introduced a new field called priority which will have the order in which which the class should be instantiated. I use that field in the interceptor method to set the order of instantiation

    public List<IMethodInstance> intercept(List<IMethodInstance> methods,ITestContext context) 
    {
    
        List<IMethodInstance> result = new ArrayList<IMethodInstance>();
        int array_index=0;
    
        for (IMethodInstance m : methods)
        {
            result.add(m);
        }
        //Now iterate through each of these test methods
        for (IMethodInstance m : methods)
        {
            try {               
                //Get the FIELD object from - Methodobj->method->class->field
                Field f = m.getMethod().getRealClass().getField("priority");
                //Get the object instance of the method object              
                array_index=f.getInt(m.getInstance());
            } 
             catch (Exception e) {
                e.printStackTrace();
            }           
            result.set(array_index-1, m);           
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using TestNG to run Selenium based tests in Java. I have a bunch
I am using Selenium Grid with TestNG to run my tests in parallel. I
I'm using Selenium WebDriver with Testng (started using an .xml file) to test a
I'm using django-selenium to test my Django 1.3 project. The problem is, tests fail
After I run a bunch of Selenium (jUnit4) tests using Maven, I'd like to
I'm writing a selenium test using the Play! Framework and some tests have common
In using TestNG for my Selenium framework, the setUp method is relatively complex. There
Newbie in testing. I generated a test case using Selenium, and then exported it
I am using selenium rc in eclipse with testNG. I need to click on
I am testing an application using Selenium IDE. There is a table with unstable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.