Ошибка -> cucumber.runtime.CucumberException: не удалось создать экземпляр класса <class>- в этом классе нет пустого конструктора или конструктора с включенной страницей " - PullRequest
1 голос
/ 24 октября 2019

Я использую FirefoxDriverInstance в качестве синглтона для вызова драйвера. Кроме того, используя профиль Firefox для обхода двухфакторной аутентификации.

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;
}

}

Ниже приведен мой код входа в систему с использованием cucumber-selenium-webdriver. Я использовал тот же экземпляр драйвера.

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."); }
}
}

Невозможно понять, как обойти эту ошибку.

1 Ответ

0 голосов
/ 24 октября 2019

Попробуйте поместить код ниже в конструкторе:

   FirefoxDriverInstance.Initialize();

Пример:

public class TC01_Login {

   public TC01_Login (){
       FirefoxDriverInstance.Initialize();
    }
}

Удалить его из BeforeMethod

...