【问题标题】:Unable to Run tests using Runner in Intellij无法在 Intellij 中使用 Runner 运行测试
【发布时间】:2021-01-20 10:08:10
【问题描述】:

当尝试使用运行器运行测试时,我为功能文件创建了一个测试。运行器已成功构建并完成,但没有任何反应。

功能文件:

Feature: Login to Queries

  #Login in Chrome
Scenario: Login using Chrome
Given I open Chrome
When I browse to Queries
Then I login to Queries using "pcy1" and "123"£"

步骤定义(该类扩展基类):

public class login extends base {

@Given("^I open Chrome$")
public void iOpenChrome() throws Throwable {
    driver = initializeDriver();
    throw new PendingException();
}

@When("^I browse to Queries$")
public void iBrowseToQueries() {
    driver.get("https://atesting321.test/");
    throw new PendingException();
}

@Then("^I login to Queries using \"([^\"]*)\" and \"([^\"]*)\"£\"$")
public void iLoginToQueriesUsingAnd£(String username, String password) throws Throwable {
    driver.findElement(By.id("UserName")).sendKeys(username);
    driver.findElement(By.id("Password")).sendKeys(password);
    driver.findElement(By.id("btnLogin")).click();
    throw new PendingException();
}

跑步者

@RunWith(Cucumber.class)
@CucumberOptions(
    features= "src/test/java/features/login",
    glue= "stepDefinitions")

public class RunTest {
public static void main (String[] args)
{}

基类(用作全局变量)

public class base {

public WebDriver driver;
public Properties prop;
public ChromeOptions coptions;

public WebDriver initializeDriver() throws IOException
{
    prop= new Properties();

    String browserName= "chrome";
    System.out.println(browserName);
    String pathToDriver = "";

    if(browserName.equals("chrome"))
    {
        pathToDriver = "C:\\Repositories\\automationProject\\webDrivers\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", pathToDriver);
        coptions.addArguments("disable-infobars");
        coptions.addArguments("--start-maximized");
        driver= new ChromeDriver(coptions);
        //execute in chrome driver

    }

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    return driver;
}

当我运行 RunTest java 文件时,我得到以下结果:

进程以退出代码 0 结束

File Paths

【问题讨论】:

  • 您使用什么 JUnit 版本?请务必仔细阅读文档,请参阅此处的 JUnit 部分 cucumber.io/docs/cucumber/api
  • 另外描述一下你期望得到什么结果?

标签: java selenium testing intellij-idea cucumber


【解决方案1】:

当我开始使用 Cucumber 时,我遇到了同样的问题,它就像未配置跑步者一样。

转到运行配置并删除第一次运行代码时在那里创建的内容。之后,代码将通过您的 RunTest,制作胶水并运行功能文件。

【讨论】:

    【解决方案2】:

    你的 runner 类不应包含 main 方法:

    @RunWith(Cucumber.class)
    @CucumberOptions(
        features= "src/test/java/features/login",
        glue= "stepDefinitions")
    
    public class RunTest {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-06-06
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多