测试跑步者
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依赖,它只是正确的。但是它也给出了错误
答案 0 :(得分: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。如果您有任何疑问,请与我们联系。
答案 1 :(得分: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 {
}
}
如果您想使用如下所示的场景大纲更新功能文件 在这种情况下,相同的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|
让我知道它是否适合你
答案 2 :(得分: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 |
答案 3 :(得分:0)
对我有用的是从功能目录中删除空的功能文件(没有任何方案的文件)。