无法调用使用selenium Java对TestNG测试用例执行鼠标操作的方法

无法调用使用selenium Java对TestNG测试用例执行鼠标操作的方法,java,selenium,selenium-webdriver,browser-automation,Java,Selenium,Selenium Webdriver,Browser Automation,执行鼠标操作的代码: public class test3 extends utility { public WebDriver driver; @BeforeTest public void invokeBrowser() throws IOException { driver = base(); driver.get(resource.getProperty("url"

执行鼠标操作的代码:

    public class test3 extends utility {
        public WebDriver driver;
        @BeforeTest
        public void invokeBrowser() throws IOException {
            driver = base();
            driver.get(resource.getProperty("url"));
    
        }
    
        @Test
        public class thirdPage {
            public void main() {
    
                actionTest test3 = new actionTest();
                test3.executeTest();
            }
        }
    
    }
上面的代码在执行块test3.executeTest()时导致“NullPointerException”,声明driver=null


重构代码库可能有助于解决此问题。创建一个基本测试类。添加与web驱动程序初始化和其他主要内容相关的代码。然后为测试创建另一个类。从基本测试类继承它。然后,您可以在所有测试类中使用初始化的驱动程序。

什么返回
base()
方法?请加上它的代码。除此之外,检查是否在
实用程序
类中没有另一个
WebDriver-driver
声明。顺便说一句,类应该用大写字母命名,Test3、utility、ActionTest等。@pgurbr:base()方法在utility类下,将初始化WebDriver
WebDriver-driver=new ChromeDriver()。澄清点是,是否将调用具有鼠标操作活动的executeTest()方法来@TestCase thirdPage类。(或)是否有其他方法调用executeTest()到@Test case类。谢谢
base()
方法必须返回
Webdriver
对象(作为Webdriver类型)或为声明的
Webdriver
对象(作为void)设置值。@pburgr:谢谢,我从您的建议中得到了问题!(很抱歉在我之前的回复中提到了错误的名称)感谢您的评论,我找到了修复程序,它正在工作!太好了@苏库马西瓦
    public class test3 extends utility {
        public WebDriver driver;
        @BeforeTest
        public void invokeBrowser() throws IOException {
            driver = base();
            driver.get(resource.getProperty("url"));
    
        }
    
        @Test
        public class thirdPage {
            public void main() {
    
                actionTest test3 = new actionTest();
                test3.executeTest();
            }
        }
    
    }
public class actionTest {   
    
    public void executeTest() {
    Actions execute = new Actions();    
    execute.moveToElement(driver.findElement(By.id("header-search-input"))).click().keyDown(Keys.SHIFT).sendKeys("Cricket").build().perform();
    driver.findElement(By.id("header-desktop-search-button")).click();
    }
    
    

}