在Cucumber重新运行失败的场景时出现错误。

huangapple go评论75阅读模式
英文:

Getting error while rerun of failed scenarios in cucumber

问题

I was trying to rerun the failed scenarios in cucumber, for this I had designed two runner files, one is the actual runner file which has path of feature files along with rerun plugin which specifies path of rerun.txt file and the other runner file which has path of rerun file as feature to be run, So after running both the runner files for the failed scenarios I am getting this error: -

WARNING: No features found at file:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/Reports/rerun.txt

Please help me to resolve this error and automatically run the failed scenarios of rerun.txt file.

The actual runner class file is as below: -

package com.framework.runners;

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

@CucumberOptions(features = "src/test/java/com/framework/features",glue = {"com/framework/utils" ,"com/framework/stepDef"},
        tags = "@run",
        plugin = {
                "pretty","json:target/Reports/JsonReport/report.json","junit:target/Reports/Junitreports/report.xml",
                "html:target/Reports/HTMLReport",
                "rerun:target/Reports/rerun.txt"
        },monochrome=true)

@Test
public class TestRunner extends AbstractTestNGCucumberTests {
}

The rerunner class file is as below: -

package com.framework.runners;

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

@CucumberOptions(features = "target/Reports/rerun.txt",glue = {"com/framework/utils" ,"com/framework/stepDef"},
        plugin = {
                "pretty","json:target/FailedReports/JsonReport/report.json","junit:target/FailedReports/Junitreports/report.xml",
                "html:target/FailedReports/HTMLReport"},
        monochrome=true)

@Test
public class ReRunTestRunner extends AbstractTestNGCucumberTests {
}

The pom.xml configuration is: -

<?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>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <groupId>org.example</groupId>
    <artifactId>com.CucumberHybrid</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- Dependencies here -->
    </dependencies>
    <build>
        <!-- Build configuration here -->
    </build>
</project>

The console logs are as below: -

[Console logs here]

英文:

I was trying to rerun the failed scenarios in cucumber, for this I had designed two runner files, one is the actual runner file which has path of feature files along with rerun plugin which specifies path of rerun.txt file and the other runner file which has path of rerun file as feature to be run, So after running both the runner files for the failed scenarios I am getting this error :-

WARNING: No features found at file:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/Reports/rerun.txt

Please help me to resolve this error and automatically run the failed scenarios of rerun.txt file.

The actual runner class file is as below:-

package com.framework.runners;

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

@CucumberOptions(features = &quot;src/test/java/com/framework/features&quot;,glue = {&quot;com/framework/utils&quot; ,&quot;com/framework/stepDef&quot;},
        tags = &quot;@run&quot;,
        plugin = {
                &quot;pretty&quot;,&quot;json:target/Reports/JsonReport/report.json&quot;,&quot;junit:target/Reports/Junitreports/report.xml&quot;,&quot;html:target/Reports/HTMLReport&quot;,
                &quot;rerun:target/Reports/rerun.txt&quot;
        },monochrome=true)

@Test
public class TestRunner extends AbstractTestNGCucumberTests {
}

The rerunner class file is as below:-

package com.framework.runners;

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

@CucumberOptions(features = &quot;target/Reports/rerun.txt&quot;,glue = {&quot;com/framework/utils&quot; ,&quot;com/framework/stepDef&quot;},
        plugin = {
                &quot;pretty&quot;,&quot;json:target/FailedReports/JsonReport/report.json&quot;,&quot;junit:target/FailedReports/Junitreports/report.xml&quot;,
                &quot;html:target/FailedReports/HTMLReport&quot;},
        monochrome=true)

@Test
public class ReRunTestRunner extends AbstractTestNGCucumberTests {
}

The pom.xml configuration is :-

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;/properties&gt;

    &lt;groupId&gt;org.example&lt;/groupId&gt;
    &lt;artifactId&gt;com.CucumberHybrid&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
            &lt;version&gt;2.13.3&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;io.github.bonigarcia&lt;/groupId&gt;
            &lt;artifactId&gt;webdrivermanager&lt;/artifactId&gt;
            &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.testng&lt;/groupId&gt;
            &lt;artifactId&gt;testng&lt;/artifactId&gt;
            &lt;version&gt;6.14.3&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
            &lt;version&gt;6.1.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;net.masterthought&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-reporting&lt;/artifactId&gt;
            &lt;version&gt;5.3.0&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-testng&lt;/artifactId&gt;
            &lt;version&gt;6.1.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.github.mkolisnyk&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-runner&lt;/artifactId&gt;
            &lt;version&gt;1.3.5&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
            &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
            &lt;version&gt;3.141.59&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;net.masterthought&lt;/groupId&gt;
                &lt;artifactId&gt;maven-cucumber-reporting&lt;/artifactId&gt;
                &lt;version&gt;3.16.0&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;execution&lt;/id&gt;
                        &lt;phase&gt;test&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;generate&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;projectName&gt;Cucumber Framework Execution Report&lt;/projectName&gt;
                            &lt;outputDirectory&gt;${project.build.directory}/Reports/cucumber-reports&lt;/outputDirectory&gt;
                            &lt;cucumberOutput&gt;${project.build.directory}/Reports/JsonReport/report.json&lt;/cucumberOutput&gt;
                            &lt;buildNumber&gt;42&lt;/buildNumber&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.0.0-M5&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;testngtest&lt;/id&gt;
                        &lt;phase&gt;test&lt;/phase&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
                &lt;configuration&gt;
                    &lt;!-- &lt;systemPropertyVariables&gt; &lt;IsGridSetup&gt;${is.grid}&lt;/IsGridSetup&gt;
                        &lt;HubUrl&gt;${hub.url}&lt;/HubUrl&gt; &lt;FeatureName&gt;${feature.name}&lt;/FeatureName&gt; &lt;TagName&gt;${tag.name}&lt;/TagName&gt;
                        &lt;BrowserType&gt;${browser.type}&lt;/BrowserType&gt; &lt;/systemPropertyVariables&gt; --&gt;
                    &lt;forkCount&gt;3&lt;/forkCount&gt; &lt;!-- how many parallel vm get created and execute --&gt;
                    &lt;reuseForks&gt;false&lt;/reuseForks&gt;&lt;!-- Every it will create a new vm for
						the execution and will not use any existing --&gt;
                    &lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt;&lt;!-- The execution will continue
						even if there is a test failure --&gt;
                    &lt;includes&gt; &lt;!-- Specify the file name --&gt;
                        &lt;include&gt;**/*TestRunner.java&lt;/include&gt;&lt;!-- This will include all the file
							which has &quot;Runner&quot; as suffix in their name --&gt;
                    &lt;/includes&gt;
                    &lt;suiteXmlFiles&gt;
                        &lt;!-- &lt;suiteXmlFile&gt;${testngxml.location}/testng.xml&lt;/suiteXmlFile&gt; --&gt;
                    &lt;/suiteXmlFiles&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
&lt;/project&gt;

The console logs are as below:-

[INFO] 
[INFO] -------------------&lt; org.example:com.CucumberHybrid &gt;-------------------
[INFO] Building com.CucumberHybrid 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ com.CucumberHybrid ---
[INFO] Using &#39;UTF-8&#39; encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ com.CucumberHybrid ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ com.CucumberHybrid ---
[INFO] Using &#39;UTF-8&#39; encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/keshavmac/IdeaProjects/com.CucumberHybrid/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ com.CucumberHybrid ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 15 source files to /Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ com.CucumberHybrid ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.framework.runners.TestRunner
[INFO] Running com.framework.runners.ReRunTestRunner
Aug 10, 2020 4:37:17 PM io.cucumber.core.runtime.FeaturePathFeatureSupplier get
WARNING: No features found at file:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/Reports/rerun.txt
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.851 s - in com.framework.runners.ReRunTestRunner
@run
Scenario: To test search functionality with blank submit                           # src/test/java/com/framework/features/Home.feature:7
[INFO ] 2020-08-10 16:37:18.331 [main] BaseSetup - New Webdriver instance invoked
SLF4J: Failed to load class &quot;org.slf4j.impl.StaticLoggerBinder&quot;.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 8150
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Aug 10, 2020 4:37:20 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[INFO ] 2020-08-10 16:37:20.357 [main] BaseSetup - Chrome browser instance launched successfully
  When user opens browser and navigates to test url                                # com.framework.stepDef.Common_stepDef.user_opens_browser_and_navigates_to_test_url()
The page title verified is My Store
[DEBUG] 2020-08-10 16:37:28.123 [main] HomePage_PF - Banner on homepage of website has been validated.
  Given user should be on home page                                                # com.framework.stepDef.Home_stepDef.user_should_be_on_home_page()
[DEBUG] 2020-08-10 16:37:28.159 [main] HomePage_PF - Search field on homepage has been validated.
  And search textfield should be visible                                           # com.framework.stepDef.Home_stepDef.search_textfield_should_be_visible()
[DEBUG] 2020-08-10 16:37:30.526 [main] HomePage_PF - Search icon has been clicked.
  When user clicks on search button                                                # com.framework.stepDef.Home_stepDef.user_clicks_on_search_button()
      java.lang.AssertionError: expected [true] but found [false]
	at org.testng.Assert.fail(Assert.java:96)
	at org.testng.Assert.failNotEquals(Assert.java:776)
	at org.testng.Assert.assertTrue(Assert.java:44)
	at org.testng.Assert.assertTrue(Assert.java:54)
	at com.framework.stepDef.Home_stepDef.user_clicks_on_search_button(Home_stepDef.java:32)
	at ���.user clicks on search button(file:///Users/keshavmac/IdeaProjects/com.CucumberHybrid/src/test/java/com/framework/features/Home.feature:10)
  Then user should be displayed validation message &quot;Please enter a search keyword&quot; # com.framework.stepDef.ProductList_stepDef.user_should_be_displayed_validation_message(java.lang.String)
    Scenario To test search functionality with blank submit has been failed
    Embedding To test search functionality with blank submit [image/png 365303 bytes]
[INFO ] 2020-08-10 16:37:31.638 [main] HomePage_PF - Webdriver instance has been closed
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 14.975 s &lt;&lt;&lt; FAILURE! - in com.framework.runners.TestRunner
[ERROR] com.framework.runners.TestRunner.runScenario[&quot;To test search functionality with blank submit&quot;, &quot;Optional[To test the Search feature of application]&quot;](1)  Time elapsed: 13.995 s  &lt;&lt;&lt; FAILURE!
java.lang.AssertionError: expected [true] but found [false]
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   TestRunner.runScenario expected [true] but found [false]
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] 
[ERROR] There are test failures.
Please refer to /Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[INFO] 
[INFO] --- maven-cucumber-reporting:3.16.0:generate (execution) @ com.CucumberHybrid ---
[INFO] About to generate Cucumber report.
[INFO] File &#39;/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/Reports/JsonReport/report.json&#39; contain 1 features

答案1

得分: 1

I think you are just missing annotation @ and hence no feature is found. Try this -

features = "@target/Reports/rerun.txt"


After discussion in comment section

Rename ReRunTestRunner to start with any letter after "T" (TestRunner, original feature file), as Cucumber picks up feature file in alphabetical order

英文:

I think you are just missing annotation @ and hence no feature is found. Try this -

features = &quot;@target/Reports/rerun.txt&quot;


After discussion in comment section

Rename ReRunTestRunner to start with any letter after "T" (TestRunner, original feature file), as Cucumber picks up feature file in alphabetical order

huangapple
  • 本文由 发表于 2020年8月11日 01:14:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63344895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定