我得到初始化错误 cucumber 与maven和 selenium

ugmeyewa  于 2023-01-08  发布在  Maven
关注(0)|答案(4)|浏览(167)

测试运行程序

导入组织.junit.runner.运行方式;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features="features",glue={"stepDefinition"})
public class TestRunner {

}

我的应用程序功能

Feature: Test test smoke scenario

  Scenario Outline: Test  login with valid credentials
    Given open fireFox and start application
    When I enter valid "username" and valid "password"
    Then User should be able to login successfully

Examples: 
      | username   | password          |
      | 9739817000 | mnbvcxz  |
      | 9739817001 | mnbvcxz1  |
      | 9739817002 | mnbvcxz2  |

美芬POM

<groupId>demo</groupId>
  <artifactId>prac</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>prac</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency> 
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>
  

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.4</version>
</dependency>
</dependencies>
</project>

烟雾.java

public class Smoke {
    WebDriver driver;
    @Given("^open fireFox and start application$")
    public void open_fireFox_and_start_application() throws Throwable {
        driver=new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://testweb.com");
        
    }

    @When("^I click on Login$")
    public void I_click_on_Login() throws Throwable {
        driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();
        

    }

    @When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
    public void enter_valid_and_valid(String un, String pwd) throws Throwable {
        driver.findElement(By.id("Username")).sendKeys(un);
        driver.findElement(By.id("Password")).sendKeys(pwd);
        
    }

    @Then("^Click on Login$")
    public void Click_on_Login() throws Throwable {
        driver.findElement(By.id("loginUser")).click();
        
    }
    @Then("^User should be able to login successfully$")
    public void User_should_be_able_to_login_successfully() throws Throwable {
        
       
    }

以上这些是测试运行程序,功能文件,烟雾测试类。它抛出一个初始化错误。我是新的 cucumber 和重新检查所有的maven依赖,它的正确性只有。但甚至它给错误
enter image description here

6kkfgxo0

6kkfgxo01#

由于尚未为功能文件指定任何数据集,因此不需要使用方案大纲。当需要使用不同的数据集执行相同的方案时,可以使用它。因此,请从功能文件中删除方案大纲(显示在更新后的功能文件下方),然后重试:

Feature: Test Milacron smoke scenario

Scenario: Test  login with valid credentials
Given open fireFox and start application
When I enter valid "username" and valid "password"
Then User should be able to login successfully

请参考link以获取更多关于编写特性文件的细节。如果您有任何进一步的疑问,请告诉我。

d7v8vwbk

d7v8vwbk2#

“方案大纲”用于将不同的输入数据集传递到您的方案。例如,“ABC”和“PWD”分别是您的用户名和密码,然后按如下所示更新您的功能文件,

Feature: Test Milacron smoke scenario
Scenario Outline: Test  login with valid credentials
Given open fireFox and start application
When I enter valid "username" and valid "password"
Then User should be able to login successfully

Examples:
 | username      | password |
 | ABC           |  PWD     |
p4rjhz4m

p4rjhz4m3#

对我有效的方法是从features目录中删除空的特性文件(那些没有任何场景的文件)。

nx7onnlm

nx7onnlm4#

你的pom档案绝对没问题。
这里你使用的是Scenario Outline,如果你使用Scenario Outline,那么在功能文件中应该有Examples注解。无论如何,你的测试场景不需要使用场景大纲就可以实现
使用以下代码更新功能文件和java文件:
Myapplication.feature:功能:测试测试烟雾场景

Scenario: Test  login with valid credentials
     Given open fireFox and start application
     When I click on Login
     When I enter valid "username" and valid "password"
     Then I click on Loginbutton
     Then User should be able to login successfully

Smoke.java:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Smoke {
   WebDriver driver;
@Given("^open fireFox and start application$")
public void open_fireFox_and_start_application() throws Throwable {
    driver=new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("https://testweb.com");

}

 @When("^I click on Login$")
    public void I_click_on_Login() throws Throwable {
        driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();
    }

@When("^I enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
public void i_enter_valid_and_valid(String arg1, String arg2) throws   Throwable {
    driver.findElement(By.id("Username")).sendKeys(arg1);
    driver.findElement(By.id("Password")).sendKeys(arg2);
}

@Then("^I click on Loginbutton$")
public void Click_on_Login() throws Throwable {
    driver.findElement(By.id("loginUser")).click();

}
@Then("^User should be able to login successfully$")
public void User_should_be_able_to_login_successfully() throws Throwable {

}
}

保持随附图片

中所述的文件夹结构
如果你想使用场景大纲更新功能文件,如下所示,相同的smoke.java文件将在这种情况下工作。

Feature: Test test smoke scenario

 Scenario Outline: Test  login with valid credentials
  Given open fireFox and start application
  When I click on Login
  When I enter valid "<username>" and valid "<password>"
  Then I click on Loginbutton
  Then User should be able to login successfully

Examples:
  |username|password|
  |test|test|

如果对你有用就告诉我

相关问题