我用黄瓜和硒在黄瓜中得到了初始化错误

问题描述 投票:1回答:4

测试跑步者 import org.junit.runner.RunWith;

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

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

}

MyApplication.feature

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          |
      | 9739817000 | mnbvcxz  |
      | 9739817001 | mnbvcxz1  |
      | 9739817002 | mnbvcxz2  |

Maven 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>

smoke.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://milacronqa.genalphacatalog.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 {


    }

以上是测试运行器,功能文件,Smoke测试类。它抛出了一个启动错误。我是Cucumber的新手并重新检查所有maven依赖,它只是正确的。但是它甚至也给出了错误

enter image description here

maven selenium-webdriver cucumber cucumber-junit cucumber-java
4个回答
0
投票

因为,您没有为功能文件指定任何数据集,所以您不需要使用Scenario Outline。当您需要使用不同的数据集执行相同的方案时,可以使用它。因此,从功能文件中删除Scenario Outline(显示在更新的功能文件下面)并重试:

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。如果您有任何进一步的疑问,请与我们联系。


0
投票

场景大纲用于将不同的输入数据集传递给场景。例如,'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     |

0
投票

你的pom文件绝对没问题。

如果您使用的是场景大纲,则在这里使用场景大纲,特征文件中应该有示例注释。无论如何,无需使用场景大纲即可实现测试场景

使用以下代码更新功能文件和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://milacronqa.genalphacatalog.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 {


}
}

保持文件夹结构,如附图enter image description here中所述

如果您想使用下面的场景大纲更新功能文件,则相同的smoke.java文件将适用于此情况。

Feature: Test Milacron 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|

请让我知道这对你有没有用


0
投票

对我有用的是从features目录中删除空的功能文件(没有任何方案的那些)。

© www.soinside.com 2019 - 2024. All rights reserved.