Вы можете реализовать пропущенные шаги с помощью фрагментов ниже - PullRequest
0 голосов
/ 05 июля 2018
>## This my Pom.xml file structure ##
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.cucumberExcecise</groupId>
    <artifactId>Cucumber_Practice</artifactId>
    <version>0.0.1-SNAPSHOT</version>

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

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

## Feature File:##
Feature: Login Feature
Scenario: Login as a authenticated user
   Given User is on Home Page
**Step Definition code:**
@Given("User is on Home Page$")
    public void user_is_on_homepage() {
        // Write code here that turns the phrase above into concrete actions
        System.setProperty("webdriver.chrome.driver", "E:\\Downloads\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://sample.com");
    }
**Runner Class:**
@RunWith(Cucumber.class)
@CucumberOptions(strict = true,features = "src/test/resources/featureFiles/sample.feature", glue = {
        "src/test/java/com/stepDefinitions/Step.java" })

public class TestRunner {

}

**Whenever running Runner class its showing below error:**

1 Scenarios ([33m1 undefined[0m)
1 Steps ([33m1 undefined[0m)
0m0.000s

Вы можете реализовать пропущенные шаги с помощью фрагментов ниже:

    @Given("^User is on Home Page$")
    public void user_is_on_Home_Page() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

1 Ответ

0 голосов
/ 05 июля 2018

в вашем классе Testrunner вы должны поместить некоторые вещи, или, скорее, у них есть определенные аннотации (сам класс пуст)

Вы должны указать, где находятся файлы Feature и где находятся файлы шагов (файлы .java, это происходит в «связке»)

Вы также можете указать теги (затем вы аннотируете свои функции или сценарии с помощью @something для их запуска) Есть и другие варианты, например, отчеты.

пример будет:

package steps;

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

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/"
        , monochrome = false
        , format = { "pretty", "html:target/results" }
        , glue = { "steps" }
        , strict = true
        , tags = {"@RT-interact"}
)
public class TestRunner {
}

Есть много учебных пособий, таких как http://www.automationtestinghub.com/cucumber-test-runner-class-junit/, где вы можете найти больше информации.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...