Selenium Cucumber-//在这里编写代码,将上面的短语转化为具体的操作

Selenium Cucumber-//在这里编写代码,将上面的短语转化为具体的操作,selenium,selenium-webdriver,cucumber,Selenium,Selenium Webdriver,Cucumber,我尝试使用不同的数据执行相同的测试,但在尝试运行测试时出现以下错误 您可以使用以下代码段实现缺少的步骤: @When("^Enter the ADMIN and password(\\d+)$") public void enter_the_ADMIN_and_password(int arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new

我尝试使用不同的数据执行相同的测试,但在尝试运行测试时出现以下错误

您可以使用以下代码段实现缺少的步骤:

@When("^Enter the ADMIN and password(\\d+)$") 

public void enter_the_ADMIN_and_password(int arg1) throws Throwable {

// Write code here that turns the phrase above into concrete actions
throw new PendingException();

} 
下面是我的功能文件

Scenario Outline: Login 
Given Open chrome and login
When Enter the <Username> and <Password>
Then Click on Login
Examples: 
|Username           |Password   | 
|ADMIN              |password123| 

我认为您所描述的“错误”实际上是cucumber告诉您,在“输入用户名和密码”时,无法找到步骤的匹配定义,并且根据场景大纲数据自动生成了下面的示例定义:

@When("^Enter the ADMIN and password(\\d+)$") 
public void enter_the_ADMIN_and_password(int arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
} 
问题是步骤定义在参数上使用引号,但实际步骤没有引号,因此cucumber无法匹配它们。您需要更改要素文件中的步骤以包含引号:

When Enter the "<Username>" and "<Password>"
@When("^Enter the (.*) and (.*)$")                  
public void enter_the_Username_and_Password(String username,String Password) throws Throwable                           
{       
   System.out.println("This step enter the Username and Password on the login page."+username +Password);
   loginObj.Login(driver);
}   

这可能是由于黄瓜包装配置错误造成的。检查胶水选项

@RunWith(Cucumber.class)
@CucumberOptions(
          features = { "src/test/resources/features/CucumberTests.feature" }, 
          tags = { "@integration_test"},
          glue = { "br.com.cucumber.integration.stepDefinition" }, 
          format = { "pretty", "html:target/reports/cucumber/html", "json:target/cucumber.json", "usage:target/usage.jsonx", "junit:target/junit.xml" })
@ContextConfiguration(classes= AppConfiguration.class)
public class CumcumberTest extends BaseTestCase {
}

我也犯了同样的错误。对我来说,问题是我在包中为后端测试而不是前端测试创建了步骤定义。如果步骤定义类具有相同或相似的名称,则可能会出错。从Intellij中的功能文件创建步骤定义时,在选择错误的包时会发生这种情况。

我发现这个问题,并发现原因是我无意中给出了类的名称,而不是粘合代码的包: gluecode的错误参数值是我的类:gluecode=“StepDefinition”,而它应该是我的包:gluecode=“stepDefs”

我的TestRunner.java如下所示:

package testRunner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

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

public class TestRunner {

}

我也犯了同样的错误。就我而言,我忘记了文件名中的
.step.
部分

因此,我通过修改以下文件名解决了此问题:

mystepfile.ts

致:


mystepfile.step.ts

您的错误是什么?
package testRunner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

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

public class TestRunner {

}