使用 testng 执行测试时出现空指针异常

发布于 2024-11-27 18:49:48 字数 2373 浏览 0 评论 0原文

// 我试图通过使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上得阳光 2024-12-04 18:49:48

您从未初始化过 selenium 对象。

You never initialized the selenium object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文