如何从我的 class 启动构造函数?

How can i start the constructor from my class?

我遇到了这个问题,这让我发疯,我有这个 class

    package Test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Firefox {

    String keyFirefox = "webdriver.gecko.driver";
    String valueFirefox = "...path/geckodriver.exe";

    public Firefox(){
        System.setProperty(keyFirefox, valueFirefox);
    }

    WebDriver Firefox = new FirefoxDriver();
}

在我的主 class 中,我实例化了前一个 class 并且可以毫无问题地访问属性

package Test;


public class EntryPoint {

    public static void main(String[] args) {


        Firefox firefoxBrowser = new Firefox();
        firefoxBrowser.Firefox.get("https://www.amazon.com.mx/");


    }

}

但是编译的时候return我报错了:

线程异常 "main" java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统 属性 设置;有关详细信息,请参阅 https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

谢谢!

如果要在设置属性后创建驱动程序,请尝试

public class Firefox {

    static final String FIREFOX_DRIVER = "webdriver.gecko.driver";
    static final String FIREFOX_DRIVER_PATH = "...path/geckodriver.exe";

    WebDriver driver;

    public Firefox(){
        System.setProperty(FIREFOX_DRIVER, FIREFOX_DRIVER_PATH);
        driver = new FirefoxDriver();
    }


}