samedi 9 février 2019

how i can running testng code with (Dataprovider) from Exsel file

a already write code to get response from API i used Exsel as dataprovider file to send the request but when i run the code A Test ignored message appears.

public class ReadExel {

public  String[][] getCellData(String path, String sheetName) throws InvalidFormatException, IOException {
    FileInputStream stream = new FileInputStream(path);
    XSSFWorkbook workbook = (XSSFWorkbook) XSSFWorkbookFactory.create(stream);
    XSSFSheet s = workbook.getSheet(sheetName);
    int rowcount = s.getLastRowNum();
    int cellcount = s.getRow(0).getLastCellNum();
    String data[][] = new String[rowcount][cellcount];
    for (int i = 1; i <= rowcount; i++) {
        XSSFRow r = s.getRow(i);
        for (int j = 0 ;j < cellcount ;j++)
        {
            XSSFCell Cell = r.getCell(j);
        }
    }
   return data;
}

}

public class GetCrNo {

@DataProvider (name = "db1")
public Object[][] getExcelData() throws Exception {

    ReadExel read = new ReadExel();
    return read.getCellData("C:/QA files/WebServices projects source/Wathiq/TestData/TestData.xlsx","Data");
}

@Test(dataProvider = "db1")

public void Validate_Response(String CRNO) {
    try {
        RequestSpecBuilder builder;
        //setting the request headers
        builder = new RequestSpecBuilder();
        builder.setBaseUri("http://localhost:8080").setContentType("application/json");
        RequestSpecification requestSpec = builder.build();
        Response response = given().spec(requestSpec).when().get("/wathiq-services/api/v1/wathiq/cr-data/"+CRNO);
        System.out.println();

        if (response.getBody().asString().contains("test"))
        {
            System.out.println("Test Pass");
        }
        else
        {
            System.out.println("Test Fail");
        }

        response.then().log().all();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Aucun commentaire:

Enregistrer un commentaire