2011-11-21 83 views
0

我按照http://functionaltestautomation.blogspot.com/2009/10/dataprovider-data-driven-testing-with.html?showComment=1321643221128上的說明創建了我的腳本。示例代碼完美工作。除了@test部分之外,我沒有做任何重大更改。出於某種原因,我得到錯誤java.lang.NullPointerException。我無法弄清楚可能是什麼原因造成的。Testng java.lang.NullPointerException

package script; 

import com.thoughtworks.selenium.*; 

import org.junit.AfterClass; 
import org.openqa.selenium.server.SeleniumServer; 
import org.testng.annotations.*; 

import java.io.File; 
import jxl.*; 


@SuppressWarnings("deprecation") 
public class Testcase1 extends SeleneseTestCase{ 

    @BeforeClass 
    public void setUp() throws Exception { 
     //SeleniumServer seleniumserver=new SeleniumServer(); 
     //seleniumserver.boot(); 
     //seleniumserver.start(); 
     setUp("http://devblade08-08:8080", "*firefox"); 
     selenium.open("/"); 
     selenium.windowMaximize(); 
     selenium.windowFocus(); 
    } 


    @DataProvider(name = "Data") 
    public Object[][] createData1() throws Exception{ 
     Object[][] retObjArr=getTableArray("test\\Resources\\Data\\TestCase1.xls", 
       "Scenario", "TestCase1"); 
     return(retObjArr); 
    } 

    @Test (dataProvider = "Data") 
    public void testTestcase1(String Username, String Password, String Performance) throws Exception {  



     selenium.open("/"); 
     selenium.click("link=» AudienceView Online"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.type("name=BOset::WScontent::SearchCriteria::search_criteria", "Star Trek Automation"); 
     selenium.click("css=input[type=\"submit\"]"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("//div[@id='search_results']/form/table/tbody/tr[12]/td[5]/a/span"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("css=div.seattab_off"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("id=BOparam::WSorder::getBestAvailable::reqNum::EA25EE97-EA9B-41B2-8D03-BC6B647F1255::select"); 
     selenium.select("id=BOparam::WSorder::getBestAvailable::reqNum::EA25EE97-EA9B-41B2-8D03-BC6B647F1255::select", "label=2"); 
     selenium.click("css=option[value=\"2\"]"); 
     selenium.click("name=doWork::WSorder::getBestAvailable"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("id=popupDiv_okayButton"); 
     selenium.click("name=continue"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("name=loginName"); 
     selenium.type("name=loginName", "banana"); 
     selenium.type("name=loginPassword", "banana"); 
     selenium.click("name=login"); 
     selenium.waitForPageToLoad("30000"); 






    } 

    @AfterClass 
    public void tearDown(){ 
     selenium.close(); 
     selenium.stop(); 
    } 

    public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{ 
     String[][] tabArray=null; 

      Workbook workbook = Workbook.getWorkbook(new File(xlFilePath)); 
      Sheet sheet = workbook.getSheet(sheetName); 
      int startRow,startCol, endRow, endCol,ci,cj; 
      Cell tableStart=sheet.findCell(tableName); 
      startRow=tableStart.getRow(); 
      startCol=tableStart.getColumn(); 

      Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000, false);     

      endRow=tableEnd.getRow(); 
      endCol=tableEnd.getColumn(); 
      System.out.println("startRow="+startRow+", endRow="+endRow+", " + 
        "startCol="+startCol+", endCol="+endCol); 
      tabArray=new String[endRow-startRow-1][endCol-startCol-1]; 
      ci=0; 

      for (int i=startRow+1;i<endRow;i++,ci++){ 
       cj=0; 
       for (int j=startCol+1;j<endCol;j++,cj++){ 
        tabArray[ci][cj]=sheet.getCell(j,i).getContents(); 
       } 
      } 


     return(tabArray); 
    } 


}//end of class 
+1

呃,只需使用一個調試器。 –

回答

0

包含堆棧跟蹤或更好:研究堆棧跟蹤。它會告訴你究竟問題出在哪裏(並且它比TestNG,IMO更可能出現在你的代碼中)。

2

如果不能訪問被測系統,很難看到問題出在哪裏。 我確實認爲有以下行是錯誤的或值得有關反向索引評論的:

tabArray[ci][cj]=sheet.getCell(j,i).getContents() 

如果indicies到getCell()不正確地逆轉,這可能導致試圖調用getContents()拋出NPE。

我當然認爲你應該在你的問題中使用一個調試器或包含的材料,爲什麼你不能提供堆棧跟蹤。