2017-09-25 35 views
0

這是我的腳本代碼。我正在試圖從Excel工作表中的數據,但有filenullXlxs filenull讀取異常

public class TC003_VerifyLoginWithDifferentRecords extends testbase { 

    public static final Logger log = 
    Logger.getLogger(TC003_VerifyLoginWithDifferentRecords.class.getName()); 
    HomePage homepage; 

    @DataProvider(name = "logindata") 
    public String[][] getTestData() 
    { 
     String[][]testRecords = getData("TestData.xlsx","LoginTestData"); 
     return testRecords; 
    } 

    @BeforeClass 
    public void setUp() 
    { 
     init(); 
    } 

    @Test(dataProvider = "logindata") 
    public void TestLogin(String emailAddress, String Password) 
    { 
     log.info("================Starting VerifyLogin with Different 
     Records==================="); 
     homepage = new HomePage(driver); 
     homepage.loginApplication(emailAddress,Password); 
     log.info("================Ending VerifyLogin with Different Records==================="); 
    } 

    @AfterTest 
    public void endTest() 
    { 
     // driver.close(); 
    } 

這裏我所提供的excel表我的

public String[][] getData(String workbookname, String sheetname) 
{ 

    String path = "H:/JAVA TESTING CODES/UIAutomation/src/main/java/com/test/automation/UIAutomation/data"+workbookname; 
    excel = new ExcelReader(path); 
    String[][] data = excel.getDataFromSheet(workbookname, sheetname); 
    return data; 
} 
+0

'「H:/ JAVA測試代碼/ UIAutomation/src/main/java/com/test/automation/UIAutomation/data「+ workbookname;'假設'data'是一個文件夾,你不需要尾隨'/'嗎? –

+0

我試着跟蹤/但有一個相同的錯誤 – sp4

+0

請提供更多的細節。例如,哪條線給出了錯誤。傳遞給函數的值是什麼?這似乎是你自己可以很容易地調試的東西 - 我不認爲有什麼棘手的問題意味着[SO]問題是解決問題的最佳方式。 –

回答

0

路徑這是MT testbase類的錯誤在讀xlxs說異常也面臨同樣的問題,但隨後在我的Excel中檢查了以下3點。

1)如果您沒有使用Microsoft產品Excel,那麼請在您的Excel_reader類中的任何地方使用HSSF類。 2)你必須將所有數據轉換爲字符串格式在Excel中通過使用Excel選項,如更改爲文本到列。 3)你的紙書寫到底是哪你作爲參數傳遞在函數一樣LoginTestData你的情況相同的名字,也簿的名稱應該是具有TestData.xlsx相同的名稱作爲函數

檢查與所提供的3分以上,讓我知道如果問題仍然存在,因爲我已經做了像你一樣的代碼,但考慮到以上3點,它的工作