Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to run same test multiple times in Selenium using TestNG?

In the previous tutorial, we discussed some of the important Git commands used to perform operations on our code repository. Hope you enjoyed reading the article. Well, today we are going to discuss the technique to run same test Multiple Times in our Selenium project with the help of TestNG. This is one of the TestNG interview questions recently asked my friends, so I thought to write a detailed article over this. It might help some of the needy one.

Before we begin, I have some interesting reading suggestions for you.

  • TestNG Tutorials
  • How to use IReporter to create custom TestNG report?
  • Retry failed tests with TestNG using IRetryAnalyser
  • Cross browser testing using TestNG
  • Group tests in Selenium using TestNG
  • How to create dependencies in Selenium with TestNG
  • Run Selenium Tests in Parallel using TestNG

These reading suggestions will improve your knowledge bank.

Why do we run same test multiple times?

It is very important to understand the scenario of running same test Multiple times. If we have the logical answer to this question then we are good to design our test plan with the right automation feasibility.

With data driven testing, we run same tests multiple times with different test data, but here we are just invoking the same test multiple times and reason could be anything; like-

  • Checking the dynamic changes in UI
  • Validating dynamic table
  • Load testing
  • Performance testing
  • Stability testing of the test framework itself
  • Test execution time calculation

These are the quick reasons to run same test multiple times. If you have some more reasons, then do share with us through the comment section which is at the bottom of this blog post.

How to run same test multiple times using TestNG?

First, create a TestNG class file and add all the required annotations. Identify that @Test annotation which you want to run multiple times. Once you identified the @Test annotation then design the test format as below.

@Test(invocationCount = numberOfCount)

Here we use keyword named as invocationCount with some numeric value. It invokes the @Test multiple times and the invocation count is equal to the integer value assigned to the invocationCount keyword.

Let’s have a look at the sample program below:

Sample Program

package Test;

import org.testng.annotations.Test;

public class MultiTimeRunner {
	
  @Test(invocationCount=5)
  public void testRunner() {
	  System.out.println("Sample Test");
  }
}

In the above sample program, I just created a TestNG class file and added @Test annotation with invocationCount value equals 5. So the testRunner() method written inside the @Test annotation will be executed five times.

Here is the sample test.xml file.

The following screenshot is the console output which shows testRunner() method invoked for five times.

This was all about running same test multiple times using TestNG. You can share your views and queries by using our comment section below and Do not forget to join our Facebook group.

The post How to run same test multiple times in Selenium using TestNG? appeared first on Inviul.



This post first appeared on Inviul, please read the originial post: here

Share the post

How to run same test multiple times in Selenium using TestNG?

×

Subscribe to Inviul

Get updates delivered right to your inbox!

Thank you for your subscription

×