Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 黄瓜测试忽略-TestNG_Java_Intellij Idea_Cucumber_Jira Xray - Fatal编程技术网

Java 黄瓜测试忽略-TestNG

Java 黄瓜测试忽略-TestNG,java,intellij-idea,cucumber,jira-xray,Java,Intellij Idea,Cucumber,Jira Xray,我希望关于SO的第二个问题的脚本编写得很好。我正在尝试在Java中使用Gherkin、TestNG和Selenium自动化测试用例。使用带有Intellij的Maven项目 当我在.feature文件中启动测试用例时,我能够启动它们,但是当我使用testng.xml文件或testrunner类时,它会忽略测试用例 我已经检查了项目设置,似乎配置正确。还检查了pom.xml中是否有适当的依赖项(我希望有) 我的测试功能 我的试跑者 我的步骤定义-步骤定义中的以下代码是 从功能文件启动测试用例时工作

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

当我在.feature文件中启动测试用例时,我能够启动它们,但是当我使用testng.xml文件或testrunner类时,它会忽略测试用例

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

我的测试功能

我的试跑者

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

我的POM.xml

//下面是我的POM.xml,我通常在线学习不同的教程来获取依赖项。我对不同版本的依赖项的兼容性有问题。我能够纠正它们。不确定这是否仍然是问题所在
4.0.0
自动执行
自动执行
1.0-快照
黄瓜
黄瓜核
4.7.1
黄瓜
黄瓜爪哇
4.7.1
测试
黄瓜
小黄瓜
5.0.0
黄瓜
黄瓜汁
1.0.6
假如
org.seleniumhq.selenium
硒爪哇
3.141.59
黄瓜
黄瓜试验
4.7.1
org.testng
testng
7.0.0
测试
黄瓜
黄瓜皮容器
4.7.1
io.github.bonigarcia
webdrivermanager
3.6.2
测试
io.github.bonigarcia
webdrivermanager
3.6.2
编译
org.apache.poi
poi
4.1.0
org.apache.poi
poi ooxml
4.1.0
org.apache.maven.plugins
maven编译器插件
1.8
1.8
org.apache.maven.plugins
maven surefire插件
2.21.0
testng.xml
网络智囊团
马文黄瓜报道
3.15.0
执行
验证
生成
语言测试
目标/黄瓜报告/高级报告
target/cucumber reports/CucumberTestReport.json
1.
假的
我的预期结果应该是考试通过了。但是当通过testng.xml或runner类启动时,它总是被忽略。如果有人能帮上忙,我将非常高兴


PS:我的最终目标是使用页面对象模型,使用Cucumber和Java自动化和启动Intellij上的测试用例。这将更新Jira中X射线的测试用例。如果任何人有任何关于这些功能的有用链接,将不胜感激

glue元素应该是包名,而不是目录。因此,如果您的步骤在包
steps
中,那么胶水应该是
steps

此外,TestNG会吞噬Cucumber抛出的
SkipException
异常中的消息,因此您应该添加
摘要
插件,以了解Cucumber跳过测试的原因(很可能是由于未正确配置胶水而导致未定义的步骤)


顺便说一下:您不应该在pom中包含可传递依赖项。您可以而且应该删除
cucumber core
gherkin
cumber jvm deps
依赖项。

您可以在尝试运行testng.xml时发布输出/错误吗?添加
summary
插件或在严格模式下运行。@Sureshmani它在运行testng.xml文件时只显示Test ignored它不起作用。如果删除所有三个依赖项,则无法从testng.xml或功能文件启动测试。除去Gherkin和cucumber核心依赖项,我可以从特性启动测试,但不能从testng.xml启动。添加摘要插件不会显示任何不同的错误消息。它总是向我显示以下错误消息:Test ignored。特点:X射线JiraMake确保重新导入您的maven项目。在IDEA中运行测试时,选择套装并向下滚动。如果失败,请将
strict=true
添加到您的
@cucucumberoptions
。我也在cucumber选项中添加了strict,没有任何更改。同样的结果!Test ignored您可以打开
TestNGCucumberRunner
并在
runScenario
方法中放置一些断点,然后查看发生了什么。我这样做了,它显示了一个错误,“源代码不符合字节码”
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);

    }
//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>
@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 {

}