2011-11-21 80 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。

我当然认为你应该在你的问题中使用一个调试器或包含的材料,为什么你不能提供堆栈跟踪。