Running Nested TestCase in a Loop

How will we run a nested test case in a loop?

Example: Think of a scenario where we have to repeat the filling up Address, Email and Phone fields 3 times. Lets see how we can do it with the help of addons.

It can be done with the help of addons (Click Here to learn on how to create add ons).

e.g. following add on repeats entering the values for 3 times.

package main.Addon;
 
import io.testproject.java.annotations.v2.Action;
import io.testproject.java.sdk.v2.addons.WebAction;
import io.testproject.java.sdk.v2.addons.helpers.WebAddonHelper;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import org.openqa.selenium.WebElement;
 
/**
 * Created by Sisirkant on 4/11/2020.
 */
@Action(name = "Fill Up Three Fields in a loop")
public class FillUpThreeFieldsTestProject implements WebAction {
    @Override
    public ExecutionResult execute(WebAddonHelper webAddonHelper) throws FailureException {
        WebDriver driver = webAddonHelper.getDriver();
        for (int i = 0; i < 3; i++) {
            WebElement address = driver.findElementByXPath("//input[@id='address']");
            address.clear();
            address.sendKeys("My Address one" + i);
 
            WebElement eMailId = driver.findElementByXPath("//input[@id='email']");
            eMailId.clear();
            eMailId.sendKeys(i + "test@test.com");
 
            WebElement phoneNo = driver.findElementByXPath("//input[@id='phone']");
            phoneNo.clear();
            phoneNo.sendKeys("1111111111" + i);
        }
        return ExecutionResult.PASSED;
    }
}

Note that this is not an ideal way but wanted to showcase how we can use the power of add to loop certain steps with different set of values.

Once the Addon is imported, this can be used as a test step.

About This Site

The main aim of this site is to share knowledge with fellow software test specialists who are keen to grow both technically and professionally.

Categories