使用 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 之前收到空指针异常错误。
// i am trying to execute test cases by grouping them using 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();
}
}
}
// i am getting null pointer exception error just before selenium.open.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您从未初始化过 selenium 对象。
You never initialized the selenium object.