黄瓜测试被忽略-TestNG

时间:2019-08-28 15:40:24

标签: java intellij-idea cucumber jira-xray

我希望我关于SO的第二个问题写得很好。我正在尝试在Java中使用Gherkin,TestNG和Selenium自动化测试用例。在Intellij中使用Maven项目。

当我在.feature文件中启动测试用例时,我可以启动它们,但是当我使用testng.xml文件或Test Runner类时,它会以某种方式忽略测试用例。

我已经检查了似乎已正确配置的项目设置。还检查我的pom.xml是否具有适当的依赖项(希望如此)

  

我的测试功能

Feature: Xray Jira

  @TEST_01 @STC
  Scenario: Xray Jira Testing
    Given The user login to the application
    When the credentials are entered
    Then the homepage is viewed
  

我的测试跑步者

package Runners;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(
        features = "src/test/resources/",
        glue = {"src/test/Steps/"},
        plugin = {
                "pretty",
                "html:target/cucumber-reports/cucumber-pretty",
                "json:target/cucumber-reports/CucumberTestReport.json"
        })
public class UITest extends AbstractTestNGCucumberTests {

}
  

我的步骤定义-步骤定义中的以下代码是   从功能文件启动测试用例时可以正常工作

package Steps;

import Pages.BasePage;
import Pages.HomePage;
import Pages.LoginPage;
import Helper.ConfigFileReader;
import io.cucumber.java.en.*;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

public class MyStepdefs extends BasePage {
    private WebDriver driver = null;
    private Hooks lHooks;

    public MyStepdefs(Hooks lHooks) {
        this.driver = lHooks.driver;
    }

    @Given("The user login to the application")
    public void the_user_login_to_the_application() {
        LoginPage loginObject = new LoginPage(driver);
        resultValue = loginObject.VerifyUrl();
        Assert.assertTrue(resultValue);
    }

    @When("the credentials are entered")
    public void the_credentials_are_entered() {
        ConfigFileReader config = new ConfigFileReader();
        String userID = config.getUserID();
        String userPassword = config.getUserPassword();
        LoginPage loginObject = new LoginPage(driver);
        loginObject.enterName(userID);
        loginObject.enterPassword(userPassword);
        loginObject.clickLoginButton();
        HomePage lHome = new HomePage(driver);
        resultValue=lHome.verifyMenuIsDisplayed();
        Assert.assertTrue(resultValue);
    }

    @Then("the homepage is viewed")
    public void the_homepage_is_viewed() {

        HomePage homeObject = new HomePage(driver);
        resultValue=homeObject.verifyMenuIsDisplayed();
        Assert.assertTrue(resultValue);

    }
  

我的POM.xml

//Below is my POM.xml I usually followed different tutorials online to get the dependencies. I had issues with compatibility of different version of the dependencies. I was able to correct them. Not sure if it is still the problem

<?xml version="1.0" encoding="UTF-8"?>
<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>execute_auto</groupId>
    <artifactId>execute_auto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>4.7.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.7.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>5.0.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
        <dependency>    
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.6</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>4.7.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.0.0</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>4.7.1</version>
        </dependency>


        <!-- Web driver manager dependency -->

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <configuration>
                    <suiteXmlFiles>testng.xml</suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>3.15.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>POC-language-testing</projectName>
                            <outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
                            <cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
                            <buildNumber>1</buildNumber>
                            <parallelTesting>false</parallelTesting>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


        </plugins>


    </build>

</project>

我的预期结果应该是测试通过了。但是当通过testng.xml或Runner类启动时,它总是被忽略。如果有人可以帮助我,我将非常高兴

PS:我的最终目标是使用Page Object Model在使用Cucumber和Java的Intellij上自动化并启动测试用例。这应该更新Jira中Xray上的测试用例。如果有人对此类功能有任何有用的链接,将不胜感激。

1 个答案:

答案 0 :(得分:0)

glue元素应该是程序包名称,而不是目录。因此,如果您的步骤在包装Steps中,则胶水应该为Steps

另外,TestNG吞噬了Cucumber引发的SkipException异常中的消息,因此您应该添加summary插件以查看为什么Cucumber跳过了测试(很可能是由于未定义步骤,因为您没有正确配置胶水。

@CucumberOptions(
        features = "src/test/resources/",
        glue = {"Steps"},
        plugin = {
                "summary"
                "pretty",
                "html:target/cucumber-reports/cucumber-pretty",
                "json:target/cucumber-reports/CucumberTestReport.json"
        })
public class UITest extends AbstractTestNGCucumberTests {

}

顺便说一句:您不应在pom中包含传递依赖。您可以并且应该删除cucumber-coregherkincucumber-jvm-deps依赖性。