错误:将其设置为静态或向您的类添加no-args构造函数

时间:2016-07-07 18:59:25

标签: java selenium selenium-webdriver testng

我正在运行此类作为testNG并且获取错误要么使其成为静态,要么添加no-args构造函数。如果我没有添加arg构造函数,我会收到错误:"隐式超级构造函数BaseClass()未定义。"

public class testmaven extends BaseClass{
public testmaven(WebDriver driver) {
    super(driver);
    // TODO Auto-generated constructor stub
}


@Test
public void myMethod() throws Exception {

    logInPage.openApp("Chrome","http://url.com");

}

以下是基类:

public class BaseClass {
public WebDriver driver;
public boolean isDisplay;
public LogInPage logInPage;
public WaitForObj wait;
public DashboardPage dashboardPage;
public Actions action;
public Util util; 

public BaseClass(WebDriver driver){
    this.driver = driver;
    this.isDisplay = false;
    logInPage = new LogInPage(driver);
    wait = new WaitForObj(driver);
    dashboardPage = new DashboardPage(driver);
    util = new Util (driver);
    action = new Actions(driver);
}

以下是登录类

 public class LogInPage extends BaseClass {
BrowserFactory browserfactory = new BrowserFactory();

public LogInPage(WebDriver driver){
    super(driver);
}    

public void openApp(String browserName, String env) throws Exception{

    driver = browserfactory.getBrowser(browserName);
    Log.info("Browser:" + browserName);
    driver.manage().window().maximize();
    driver.get(env);
    Log.info("Env: " + env);
    wait.wait(1);
}

1 个答案:

答案 0 :(得分:0)

你必须向TestNG解释它应该如何实现你的测试类。

解决方案是使用@Factory

另一个解决方案是一个更常见的模式,它有一个空的构造函数,并使用@BeforeX and/or @AfterX方法初始化属性。

相关问题