2011-08-01 53 views
0

执行测试//我试图通过用TestNG空指针异常,同时使用TestNG

      package com.xyz.ngp.selenium; 

      import org.testng.annotations.*; 
      import javax.swing.*; 
      import com.thoughtworks.selenium.SeleneseTestNgHelper; 

      public class Grouping extends SeleneseTestNgHelper { 

       @BeforeGroups (groups = {"smoke"}) 
       public void oneTimeSetUp() {   
        try {   
         String st="we are in BeforeGroups"; 
         JOptionPane.showMessageDialog(null,st); 
         // scroll down to the bottom to see justprintsomething. 
         justprintsomething(); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        }  
       } 

       @Test(groups = {"smoke"}) 
       public void test1() throws Exception { 
        String st="you wanted to execute smoke group"; 
        JOptionPane.showMessageDialog(null,st); 
       } 

       @Test(groups = {"functional"}) 
       public void test2() throws Exception { 
        String st="you wanted to execute : either (functional) or this test: (test2)"; 
        JOptionPane.showMessageDialog(null,st); 
       } 

       @Test(groups = {"test3"}) 
       public void test3() throws Exception { 
        String st="you wanted to execute : this test: (test3)"; 
        JOptionPane.showMessageDialog(null,st); 
       } 

       //@BeforeMethod (groups = "smoke") //do i need this beforegroups here? 
       public void justprintsomething() throws Exception {   
        try {   
         // it gets printed 
         String st="inside justprintsomething going to selenium.open"; 
         JOptionPane.showMessageDialog(null,st); 
         // if i comment out the below line code works fine 
         selenium.open("http://www.google.com/"); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        }  
       } 

      } 

将它们分组执行测试用例//我得到空指针异常错误只是selenium.open之前。

+0

你需要展示一些真实的(可编译的)代码来获得任何有用的答案。 –

回答

0

您从未初始化硒对象。

+0

他实际上从不声明一个硒变量。 –

+0

谢谢你们,我解决了这个问题。如果null = selenium,则创建一个实例。 –