1

私はハイブリッド フレームワークを使用しています。Excel シートを作成するために、データ プロバイダーによって Apache-poi ライブラリを使用しています。

コードを使用して、テスト ケースが記述された Excel シートを読み書きし、そのケースに応じてステータスを設定できるように、コードが必要です。

現在、コードを実行しているときに、ログイン メソッドがスキップされました。実際、私は初心者で、Excel の読み取りと書き込みに使用しようとしています。問題を解決するために誰か助けてもらえますか?

public class HybridExecuteTest {
    private static final String BROWSER_PATH = "D:\\abc\\setup\\FFinstalled\\firefox.exe";
    private static XSSFWorkbook ExcelWBook;
    private static XSSFSheet ExcelWSheet;
    private static XSSFCell Cell;
    private static XSSFRow Row;
    WebDriver webdriver = null;

    @Test(dataProvider = "hybridData")
    public void testLogin(String testcaseName, String keyword,
            String objectName, String objectType, String value)
            throws Exception {
        // TODO Auto-generated method stub
        if (testcaseName != null && testcaseName.length() != 0) {
            // webdriver=new FirefoxDriver();
            File file = new File(BROWSER_PATH);
            FirefoxBinary fb = new FirefoxBinary(file);
            webdriver = new FirefoxDriver(fb, new FirefoxProfile());
        }
        ReadObject object = new ReadObject();
        Properties allObjects = object.getObjectRepository();
        UIOperation operation = new UIOperation(webdriver);
        // Call perform function to perform operation on UI
        operation.perform(allObjects, keyword, objectName, objectType, value);
    }

    @DataProvider(name = "hybridData")

    // This method is to set the File path and to open the Excel file, Pass Excel Path and Sheetname as Arguments to this method
        public Object[][] setExcelFile(String filePath, String fileName, String sheetName) throws Exception {
        Object object[][] = null;
        try {
            File file = new File(filePath + "\\" + fileName);
            // Open the Excel file
            FileInputStream ExcelFile = new FileInputStream(file);
            // Access the required test data sheet
            ExcelWBook = new XSSFWorkbook(ExcelFile);
            ExcelWSheet = ExcelWBook.getSheet(sheetName);
        } catch (Exception e) {throw (e);}
        return object;
    }
    // This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num
    public String getCellData(int RowNum, int ColNum) throws Exception {
        try {
            Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
            String CellData = Cell.getStringCellValue();
            return CellData;
        } catch (Exception e) {
            return "";
        }
    }
    // This method is to write in the Excel cell, Row num and Col num are the parameters
    public String setCellData(String Result, int RowNum, int ColNum,String filePath, String fileName) throws Exception {
        try {
            Row = ExcelWSheet.getRow(RowNum);
            Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
            if (Cell == null) {
                Cell = Row.createCell(ColNum);
                Cell.setCellValue(Result);
            } else {
                Cell.setCellValue(Result);
            }
            // Constant variables Test Data path and Test Data file name
            File file = new File(filePath + "\\" + fileName);
            // Open the Excel file
            FileOutputStream ExcelFile = new FileOutputStream(file);
            ExcelWBook.write(ExcelFile);
        } catch (Exception e) {
            throw (e);
        }
        return null;
    }
}

コンソール:

SKIPPED: testLogin
org.testng.TestNGException: 
Some DataProvider public java.lang.Object[][] testCases.HybridExecuteTest.setExcelFile(java.lang.String,java.lang.String,java.lang.String) throws java.lang.Exception parameters unresolved:  at 1 type class java.lang.String
 at 2 type class java.lang.String
 at 3 type class java.lang.String

注: 私は Apache poi のチュートリアルを実行しましたが、通常は書き方を理解していますが、フレームワークで行き詰まっています。これらを手伝ってください。

4

1 に答える 1

0

パラメータを dataprovider に渡そうとしましたが、これはサポートされていません。文字列 filePath、文字列 fileName、文字列 sheetName をクラス レベル変数として宣言し、メソッドからそれらにアクセスします。

String filePath="something"; String fileName="something"; String sheetName ="something";

 @DataProvider(name = "hybridData")
public Object[][] setExcelFile() throws Exception {
        Object object[][] = null;
        try {
            File file = new File(filePath + "\\" + fileName);
            // Open the Excel file
            FileInputStream ExcelFile = new FileInputStream(file);
            // Access the required test data sheet
            ExcelWBook = new XSSFWorkbook(ExcelFile);
            ExcelWSheet = ExcelWBook.getSheet(sheetName);
        } catch (Exception e) {throw (e);}
        return object;
    }

直面するもう 1 つの問題は、object[][] を返す前に何も割り当てていないことです。

于 2016-02-20T17:20:47.637 に答える