Java 错误->;cucumber.runtime.CucumberException:未能实例化类<;类别>;-这个类没有';t没有空的或启用页面的构造函数“;
我使用Java 错误->;cucumber.runtime.CucumberException:未能实例化类<;类别>;-这个类没有';t没有空的或启用页面的构造函数“;,java,selenium-webdriver,firefox,compiler-errors,runtime-error,Java,Selenium Webdriver,Firefox,Compiler Errors,Runtime Error,我使用FirefoxDriverInstance作为调用驱动程序的单例。另外,使用firefox配置文件绕过2因素身份验证 public class FirefoxDriverInstance { public static WebDriver Instance = null; public static void Initialize() { if (Instance == null) { System.out.println("Initializing Firef
FirefoxDriverInstance
作为调用驱动程序的单例。另外,使用firefox配置文件绕过2因素身份验证
public class FirefoxDriverInstance {
public static WebDriver Instance = null;
public static void Initialize() {
if (Instance == null) {
System.out.println("Initializing Firefox Driver!!!");
System.setProperty("webdriver.gecko.driver","./src/test/resources/driver/geckodriver2.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile.getProfile("SeleniumTester"));
Instance = new FirefoxDriver(options);
}
Instance.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Instance.manage().window().maximize();
}
public static void close() {
System.out.println("Closing Browser!!!");
Instance.close();
Instance = null;
}
public static void quit() {
System.out.println("Quitting Browser!!!");
Instance.quit();
Instance = null;
}
}
下面是我使用Web驱动程序的登录代码。我使用了相同的驱动程序实例
public class TC01_Login {
@BeforeMethod
public void openbrowser() throws IOException {
FirefoxDriverInstance.Initialize();
}
public Properties propertyFileReader() throws Exception {
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir")+"\\src\\test\\resources\\testdata\\application.properties");
obj.load(objfile);
return obj;
}
WebDriverWait wait = new WebDriverWait(FirefoxDriverInstance.Instance, 150);
@Given("^user has entered the required URL$")
public void user_has_entered_the_required_URL() throws Throwable {
Properties obj = propertyFileReader();
System.out.println("In the First Loop!!");
FirefoxDriverInstance.Instance.get(obj.getProperty("baseUrl"));
String actualTitle = FirefoxDriverInstance.Instance.getTitle();
System.out.println("Actual Title :" + actualTitle);
if (actualTitle.contains("test")){
System.out.println("INFO : Title is being displayed as expected.");
}
else {
System.out.println("ERROR : Title is NOT being displayed as expected."); }
}
}
无法理解如何绕过此错误。请尝试在构造函数中输入以下代码:
FirefoxDriverInstance.Initialize();
示例:
public class TC01_Login {
public TC01_Login (){
FirefoxDriverInstance.Initialize();
}
}
将其从方法之前删除,尝试在构造函数中放入以下代码:
FirefoxDriverInstance.Initialize();
示例:
public class TC01_Login {
public TC01_Login (){
FirefoxDriverInstance.Initialize();
}
}
将其从方法之前的中删除您没有问任何问题。您没有问任何问题。