在Selenium JAVA中使用TESTNG-POM框架中的Actions类

时间:2015-12-16 07:56:12

标签: java selenium testng

我在实施Actions类的过程中陷入了代码之间我在双击复选框记录时获取 NullpointerException 以下是我的Selenium Code

package Script;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class DriverInstance {
    public WebDriver driver;

  @BeforeTest
  public void beforeTest() {
      driver = new FirefoxDriver();
      driver.get("https://ppmss360.ford.qa.ams.hpmsdynamics.com");
      driver.manage().window().maximize();
  }

  @AfterTest
  public void afterTest() {
  //driver.quit();
  }

}

下面是TestNGScript类:

package Script;

import org.testng.annotations.Test;

import POM.Acc_landingPage_Pom;
import POM.Dashboard_POM;
import POM.LoginCRM;

public class OpenAccount extends DriverInstance {

  @Test
  public void f() throws InterruptedException {


        Acc_landingPage_Pom obj1 = new Acc_landingPage_Pom(driver);
        obj1.rec_open();


  }
}

以下是POM课程:

    package POM;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class Acc_landingPage_Pom {
    public WebDriver driver;

    @FindBy(xpath="(//input[@class='ms-crm-RowCheckBox'])[1])")
    private WebElement acc_rec;

    public Acc_landingPage_Pom(WebDriver driver2) {
        PageFactory.initElements(driver2, this);

    }
        public void rec_open()
        { 



            Actions action = new Actions(driver);
            action.moveToElement(acc_rec).doubleClick().perform();
        }
}

在rec_open()方法中的Actions Line上获取 NullPointerException

下面是NPE stackTrace

java.lang.NullPointerException
    at org.openqa.selenium.interactions.Actions.<init>(Actions.java:44)
    at POM.Acc_landingPage_Pom.rec_open(Acc_landingPage_Pom.java:24)
    at Script.OpenAccount.f(OpenAccount.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

任何人都可以查看此内容

1 个答案:

答案 0 :(得分:0)

Acc_landingPage_Pom.drivernull,这就是为什么在尝试构建Actions个实例时,您获得了NullPointerException

我没有看到您在driver初始化Acc_landingPage_Pom的任何地方。

也许您的意思是Acc_landingPage_Pom扩展DriverInstance而不定义自己的driver成员,或者您打算将driver = driver2置于Acc_landingPage_Pom的构造函数中

您无法使用Actions null初始化/构建WebDriver