Я пытаюсь запустить тест на огурец, написанный на Java.
Кажется, что все работает нормально, за исключением того, что после того, как я реализовал файл функций, я начинаю получать эту ошибку: cucumber.runtime.CucumberException: Не удалось создать экземпляр класса stepDefinitions.
package runners;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/FeatureFile",
glue = {"stepDefinitions"}
)
public class TestRunner {
}
Структура проекта выглядит следующим образом:
Класс StepDefinitons выглядит следующим образом. Сначала я запускаю файл функций, после чего у меня появляются методы, которые мне нужно реализовать в классе stepDefinitons.
package stepDefinitions;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
public class Steps {
private static WebDriver driver;
WebDriverWait wait=new WebDriverWait(driver, 20);
@Given("^I naviagte to login page$")
public void i_naviagte_to_login_page() {
System.setProperty("webdriver.chrome.driver", "E:\\TestingJAR\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.facebook.com");
}
@When("^I enter username as operqa(\\d+)$")
public void i_enter_username_as_operqa(String usr) {
WebElement username = driver.findElement(By.name("username"));
username.sendKeys(usr);
username.sendKeys(Keys.TAB);
}
@When("^I enter password as (\\d+)$")
public void i_enter_password_as(String pass) {
WebElement tipoValidacion;
tipoValidacion = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"tipoValidacionDiv\"]/div/div/div/span[3]")));
tipoValidacion.click();
driver.findElement(By.xpath("//*[@id=\"tipoValidacionDiv\"]/div/div/div/span[1]")).click();
WebElement password;
password = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("password")));
password.sendKeys(pass);
}
@When("^I press Ingresar button$")
public void i_press_Ingresar_button() {
driver.findElement(By.xpath("//BUTTON[@type='submit']")).click();
}
@Then("^I should be able to login successfully$")
public void i_should_be_able_to_login_successfully() {
WebElement loginSuccess = driver.findElement(By.xpath("//H1[@class=''][text()='Home']"));
Assert.assertEquals(loginSuccess.getText(),"Home");
}
}