What is the best approach of the follwoing scenario.

I have to run a number of which take in data. The first set of values are pretty standard but then one is and can be any length in number. I’m retriving this data from two excel sheets As so:

  String[][] vplmns = readVPLMN.getArrayData("Test_Data.xlsx","VPLMNS");
  Object[][] testObjArray = ExcelUtils.getTableArray("Test_Data.xlsx","Sheet2");

I then run my test using the following:

@Test(priority=2)
public void createCampaignNew() throws Exception{

    String[][] cars = readVPLMN.getArrayData("Test_Data.xlsx","Cars");
    Object[][] ObjArray = ExcelUtils.getTableArray("Test_Data.xlsx","Personal_Deails");
    System.out.println("Running name test");

    for (int i = 351; i<ObjArray.length; i++){


        Create_Person.setName((String) testObjArray[i][0]);
        Create_Person.setAge(Integer.parseInt((String) testObjArray[i][1]));
        Create_Person.setAddress((String) testObjArray[i][2]);
        Create_Person.setNumberOfCars(Integer.parseInt((String) testObjArray[i][3]));
        Create_Person.setType((String) testObjArray[i][4]);
        Create_Person.setVplmns(cars[i]);
        Create_Person.createCampaginNew();



    }

The retrival of data and everything runs fine but my issue is the Test is ran as one continous scenario so if a test fails it breaks. So I am trying to find a way to run the test independently. I have tried using factory (http://testng.org/doc/documentation-main.html#factories) but I’m getting a little confused when trying to retrun the list of objects and how to intialise the webbrowser. Due to the volume of tests I need to run the tests in one window. An exapmple in which I’ve correctly used TESTNG factory can be seen below:

 public class FactoryTestSimple {

 String i;
 String j;

    @Factory(dataProvider = "userModeProvider")
    public FactoryTestSimple(String i,String j) {
        this.i = i;
        this.j = j;
    }

public String getI() {
    return i;
}

public void setI(String i) {
    this.i = i;
}

public String getJ() {
    return j;
}

public void setJ(String j) {
    this.j = j;
}


@BeforeClass(alwaysRun = false)
public void init() throws Exception {
    System.out.println("Before Running the class userMode is ");
}



@Test(groups = "testFactory", description = "test method1")
public void testMethod1() throws Exception {
    FactoryTestSimple s =new FactoryTestSimple("Input one","Input2");
    System.out.println("------");
    System.out.println(s.getI());
    System.out.println("------");
    System.out.println(s.getJ());

}



@DataProvider
private static String [][] userModeProvider() {


    String[][] obj = new String[3][2];

    for (int i=0;i<=3;i++) {               
        for (int j=0;j<=2;j++){

    }

}
    return obj;
}
}

Can anyone help me combine the two everthing I try ends up with a null values or fails.

My full tests case can be seen below:

@BeforeClass(alwaysRun = true)
public void setup() throws MalformedURLException{
    FirefoxBinary binary = new FirefoxBinary(new File("C:\Program Files (x86)\Mozilla Firefox\firefox.exe"));
    FirefoxProfile profile = new FirefoxProfile();
    this.driver = new FirefoxDriver(binary, profile);

    //this.driver = new FirefoxDriver();
    wait = new WebDriverWait(driver, 10);
    Create_Person = PageFactory.initElements(driver, Create_Person.class );
}

@AfterClass(alwaysRun = true)
public void teardown(){
    this.driver.quit();
}

@Test(priority=1,retryAnalyzer=Retry.class)
public void testSignUpMainPage(){
    Create_Person.loadPage();

}

@Test(priority=2)
public void createCampaignNew() throws Exception{

    String[][] cars = readVPLMN.getArrayData("Test_Data.xlsx","Cars");
    Object[][] ObjArray = ExcelUtils.getTableArray("Test_Data.xlsx","Personal_Deails");
    System.out.println("Running name test");

    for (int i = 351; i<ObjArray.length; i++){


        Create_Person.setName((String) testObjArray[i][0]);
        Create_Person.setAge(Integer.parseInt((String) testObjArray[i][1]));
        Create_Person.setAddress((String) testObjArray[i][2]);
        Create_Person.setNumberOfCars(Integer.parseInt((String) testObjArray[i][3]));
        Create_Person.setType((String) testObjArray[i][4]);
        Create_Person.setVplmns(cars[i]);
        Create_Person.createCampaginNew();



    }



Source link https://sqa.stackexchange.com/questions/34833/dynamic-tests-using-testng--

LEAVE A REPLY

Please enter your comment!
Please enter your name here