1
votes

could you please suggest what could be the issue with my code , After using dataprovider my test method Test2 and Test3 both are looks like unreachable,can you provide me the solution that how i could fix this issue without putting all the code into single Test method

  1. while using data provider i'm only able to reach Test1 code means after executing my code i am getting below output (see below output)

OUTPUT

Before Test case

Print Test1

where my expected output should be (see below out put)

OUTPUT

Before Test case

Print Test1

Print Test2

Print Test2

public class Test extends DriverConfig {
    
    @DataProvider
    public Iterator<String> getTestData() throws Exception {
        driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
        ArrayList<String> getclientProduct = sftpCon.clientProduct("Client Type");
        System.out.println("getclientProduct----------" + getclientProduct);
        System.out.println("Before Test case");
        return getclientProduct.iterator();
    
    }
    
    @Test(priority = 1, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class,dataProvider = "getTestData")
    public void A1(String clientName,String clientAddress) throws Exception {

        wait = new WebDriverWait(driver, 10);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        System.out.println("Print Test1");
    }
    @Test(priority = 2, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class)
    public void A2() throws Exception {
        wait = new WebDriverWait(driver, 80);
        System.out.println("Print Test2");
        
    }

    @Test(priority = 3, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class)
    public void A3() throws Exception {
        wait = new WebDriverWait(driver, 10);
        System.out.println("Print Test3");
        
    }

}
2
You can use BeforeClass annotation to execute a code before all test methods. driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); shall not be inside DataProvider. DataProvider is automatically called from test methods when the name is used within the Test.Janesh Kodikara
It's not working , i have multiple test data to be testing where my code flow should be multiple times as per my test data but I don't know where is the issue i can able to get only the result of 1st test data not 2nd and 3rd .... etcSoumya Ranjan Das

2 Answers

0
votes

Name of of the data provider was not defined in the code. Name of the data provider should match with the name used within @Test

@DataProvider (name = "getTestData")

Following should work with the expected order of execution.

public class Test extends DriverConfig{


@BeforeClass
public void beforeClass(){
    driver = new ChromeDriver();
    System.out.println("Before Test case");
}

@DataProvider (name = "getTestData")
public Iterator<String> getTestData() throws Exception {
   
    ArrayList<String> getclientProduct = sftpCon.clientProduct("Client Type");
    System.out.println("getclientProduct----------" + getclientProduct);
   
    return getclientProduct.iterator();

}

@Test(priority = 1, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class,dataProvider = "getTestData")
public void A1(String clientName,String clientAddress) throws Exception {

    System.out.println("Print Test1");
}
@Test(priority = 2, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class)
public void A2() throws Exception {
 
    System.out.println("Print Test2");

}

@Test(priority = 3, retryAnalyzer = RetryFailedTestCases.RetryTestCases.class)
public void A3() throws Exception {
    System.out.println("Print Test3");

}

}

0
votes

You can use @Factory annotation for these type of scenarios. Below is the code snippet

public class Test{
        
    String data;
    
    @DataProvider(name="dataProvider")
    public static Iterator<String> getTestData() throws Exception {
        ArrayList<String> data = new ArrayList<String>();
        data.add("Test Data");
        return data.iterator();
    
    }
    
    @Factory(dataProvider="dataProvider")
    public Test(String data) {
        this.data = data;
    }
    
    @Test(priority = 1)
    public void A1() {
        System.out.println("Print Test 1: " + data);
    }
    @Test(priority = 2)
    public void A2() {
        System.out.println("Print Test 2: " + data);
    }

    @Test(priority = 3)
    public void A3()  {
        System.out.println("Print Test 3: " + data);
    }
        
}

OUTPUT:

Print Test 1: Test Data
Print Test 2: Test Data
Print Test 3: Test Data

===============================================
Single Test
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================