#java #selenium #maven #cucumber
#java #selenium #maven #cucumber
Вопрос:
Я пытался повторно запустить неудачные сценарии в cucumber, для этого я разработал два файла runner, один из которых является фактическим файлом runner, в котором указан путь к файлам функций вместе с плагином rerun, который указывает путь к rerun.txt файл и другой файл runner, в котором указан путь к файлу rerun в качестве функции для запуска, поэтому после запуска обоих файлов runner для неудачных сценариев я получаю эту ошибку :-
WARNING: No features found at file:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/tar&et/Reports/rerun.txt
Пожалуйста, помогите мне устранить эту ошибку и автоматически запустить неудачные сценарии rerun.txt файл.
Фактический файл класса runner выглядит следующим образом:-
packa&e com.framework.runners;
import io.cucumber.testn&.AbstractTestNGCucumberTests;
import io.cucumber.testn&.CucumberOptions;
import or&.testn&.annotations.Test;
@CucumberOptions(features = "src/test/java/com/framework/features",&lue = {"com/framework/utils" ,"com/framework/stepDef"},
ta&s = "@run",
plu&in = {
"pretty","json:tar&et/Reports/JsonReport/report.json","junit:tar&et/Reports/Junitreports/report.xml","html:tar&et/Reports/HTMLReport",
"rerun:tar&et/Reports/rerun.txt"
},monochrome=true)
@Test
public class TestRunner extends AbstractTestNGCucumberTests {
}
Файл класса повторного запуска выглядит следующим образом:-
packa&e com.framework.runners;
import io.cucumber.testn&.AbstractTestNGCucumberTests;
import io.cucumber.testn&.CucumberOptions;
import or&.testn&.annotations.Test;
@CucumberOptions(features = "tar&et/Reports/rerun.txt",&lue = {"com/framework/utils" ,"com/framework/stepDef"},
plu&in = {
"pretty","json:tar&et/FailedReports/JsonReport/report.json","junit:tar&et/FailedReports/Junitreports/report.xml",
"html:tar&et/FailedReports/HTMLReport"},
monochrome=true)
@Test
public class ReRunTestRunner extends AbstractTestNGCucumberTests {
}
The pom.xml конфигурация :-
<?xml version="1.0" encodin&="UTF-8"?&&t;
<project xmlns="http://maven.apache.or&/POM/4.0.0"
xmlns:xsi="http://www.w3.or&/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.or&/POM/4.0.0 http://maven.apache.or&/xsd/maven-4.0.0.xsd"&&t;
<modelVersion&&t;4.0.0</modelVersion&&t;
<properties&&t;
<project.build.sourceEncodin&&&t;UTF-8</project.build.sourceEncodin&&&t;
</properties&&t;
<&roupId&&t;or&.example</&roupId&&t;
<artifactId&&t;com.CucumberHybrid</artifactId&&t;
<version&&t;1.0-SNAPSHOT</version&&t;
<dependencies&&t;
<dependency&&t;
<&roupId&&t;or&.apache.lo&&in&.lo&4j</&roupId&&t;
<artifactId&&t;lo&4j-core</artifactId&&t;
<version&&t;2.13.3</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;io.&ithub.boni&arcia</&roupId&&t;
<artifactId&&t;webdrivermana&er</artifactId&&t;
<version&&t;3.8.1</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;or&.testn&</&roupId&&t;
<artifactId&&t;testn&</artifactId&&t;
<version&&t;6.14.3</version&&t;
<scope&&t;test</scope&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;io.cucumber</&roupId&&t;
<artifactId&&t;cucumber-java</artifactId&&t;
<version&&t;6.1.2</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;net.masterthou&ht</&roupId&&t;
<artifactId&&t;cucumber-reportin&</artifactId&&t;
<version&&t;5.3.0</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;io.cucumber</&roupId&&t;
<artifactId&&t;cucumber-testn&</artifactId&&t;
<version&&t;6.1.2</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;com.&ithub.mkolisnyk</&roupId&&t;
<artifactId&&t;cucumber-runner</artifactId&&t;
<version&&t;1.3.5</version&&t;
</dependency&&t;
<dependency&&t;
<&roupId&&t;or&.seleniumhq.selenium</&roupId&&t;
<artifactId&&t;selenium-java</artifactId&&t;
<version&&t;3.141.59</version&&t;
</dependency&&t;
</dependencies&&t;
<build&&t;
<plu&ins&&t;
<plu&in&&t;
<&roupId&&t;net.masterthou&ht</&roupId&&t;
<artifactId&&t;maven-cucumber-reportin&</artifactId&&t;
<version&&t;3.16.0</version&&t;
<executions&&t;
<execution&&t;
<id&&t;execution</id&&t;
<phase&&t;test</phase&&t;
<&oals&&t;
<&oal&&t;&enerate</&oal&&t;
</&oals&&t;
<confi&uration&&t;
<projectName&&t;Cucumber Framework Execution Report</projectName&&t;
<outputDirectory&&t;${project.build.directory}/Reports/cucumber-reports</outputDirectory&&t;
<cucumberOutput&&t;${project.build.directory}/Reports/JsonReport/report.json</cucumberOutput&&t;
<buildNumber&&t;42</buildNumber&&t;
</confi&uration&&t;
</execution&&t;
</executions&&t;
</plu&in&&t;
<plu&in&&t;
<&roupId&&t;or&.apache.maven.plu&ins</&roupId&&t;
<artifactId&&t;maven-surefire-plu&in</artifactId&&t;
<version&&t;3.0.0-M5</version&&t;
<executions&&t;
<execution&&t;
<id&&t;testn&test</id&&t;
<phase&&t;test</phase&&t;
</execution&&t;
</executions&&t;
<confi&uration&&t;
<!-- <systemPropertyVariables&&t; <IsGridSetup&&t;${is.&rid}</IsGridSetup&&t;
<HubUrl&&t;${hub.url}</HubUrl&&t; <FeatureName&&t;${feature.name}</FeatureName&&t; <Ta&Name&&t;${ta&.name}</Ta&Name&&t;
<BrowserType&&t;${browser.type}</BrowserType&&t; </systemPropertyVariables&&t; --&&t;
<forkCount&&t;3</forkCount&&t; <!-- how many parallel vm &et created and execute --&&t;
<reuseForks&&t;false</reuseForks&&t;<!-- Every it will create a new vm for
the execution and will not use any existin& --&&t;
<testFailureI&nore&&t;true</testFailureI&nore&&t;<!-- The execution will continue
even if there is a test failure --&&t;
<includes&&t; <!-- Specify the file name --&&t;
<include&&t;**/*TestRunner.java</include&&t;<!-- This will include all the file
which has "Runner" as suffix in their name --&&t;
</includes&&t;
<suiteXmlFiles&&t;
<!-- <suiteXmlFile&&t;${testn&xml.location}/testn&.xml</suiteXmlFile&&t; --&&t;
</suiteXmlFiles&&t;
</confi&uration&&t;
</plu&in&&t;
</plu&ins&&t;
</build&&t;
</project&&t;
Журналы консоли выглядят следующим образом:-
[INFO]
[INFO] -------------------< or&.example:com.CucumberHybrid &&t;-------------------
[INFO] Buildin& com.CucumberHybrid 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plu&in:2.6:resources (default-resources) @ com.CucumberHybrid ---
[INFO] Usin& 'UTF-8' encodin& to copy filtered resources.
[INFO] Copyin& 2 resources
[INFO]
[INFO] --- maven-compiler-plu&in:3.1:compile (default-compile) @ com.CucumberHybrid ---
[INFO] Nothin& to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plu&in:2.6:testResources (default-testResources) @ com.CucumberHybrid ---
[INFO] Usin& 'UTF-8' encodin& to copy filtered resources.
[INFO] skip non existin& resourceDirectory /Users/keshavmac/IdeaProjects/com.CucumberHybrid/src/test/resources
[INFO]
[INFO] --- maven-compiler-plu&in:3.1:testCompile (default-testCompile) @ com.CucumberHybrid ---
[INFO] Chan&es detected - recompilin& the module!
[INFO] Compilin& 15 source files to /Users/keshavmac/IdeaProjects/com.CucumberHybrid/tar&et/test-classes
[INFO]
[INFO] --- maven-surefire-plu&in:3.0.0-M5:test (default-test) @ com.CucumberHybrid ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Runnin& com.framework.runners.TestRunner
[INFO] Runnin& com.framework.runners.ReRunTestRunner
Au& 10, 2020 4:37:17 PM io.cucumber.core.runtime.FeaturePathFeatureSupplier &et
WARNING: No features found at file:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/tar&et/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 "or&.slf4j.impl.StaticLo&&erBinder".
SLF4J: Defaultin& to no-operation (NOP) lo&&er implementation
SLF4J: See http://www.slf4j.or&/codes.html#StaticLo&&erBinder for further details.
Startin& ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 8150
Only local connections are allowed.
Please see https://chromedriver.chromium.or&/security-considerations for su&&estions on keepin& ChromeDriver safe.
ChromeDriver was started successfully.
Au& 10, 2020 4:37:20 PM or&.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 navi&ates to test url # com.framework.stepDef.Common_stepDef.user_opens_browser_and_navi&ates_to_test_url()
The pa&e title verified is My Store
[DEBUG] 2020-08-10 16:37:28.123 [main] HomePa&e_PF - Banner on homepa&e of website has been validated.
Given user should be on home pa&e # com.framework.stepDef.Home_stepDef.user_should_be_on_home_pa&e()
[DEBUG] 2020-08-10 16:37:28.159 [main] HomePa&e_PF - Search field on homepa&e 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] HomePa&e_PF - Search icon has been clicked.
When user clicks on search button # com.framework.stepDef.Home_stepDef.user_clicks_on_search_button()
java.lan&.AssertionError: expected [true] but found [false]
at or&.testn&.Assert.fail(Assert.java:96)
at or&.testn&.Assert.failNotEquals(Assert.java:776)
at or&.testn&.Assert.assertTrue(Assert.java:44)
at or&.testn&.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 messa&e "Please enter a search keyword" # com.framework.stepDef.ProductList_stepDef.user_should_be_displayed_validation_messa&e(java.lan&.Strin&)
Scenario To test search functionality with blank submit has been failed
Embeddin& To test search functionality with blank submit [ima&e/pn& 365303 bytes]
[INFO ] 2020-08-10 16:37:31.638 [main] HomePa&e_PF - Webdriver instance has been closed
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 14.975 s <<< FAILURE! - in com.framework.runners.TestRunner
[ERROR] com.framework.runners.TestRunner.runScenario["To test search functionality with blank submit", "Optional[To test the Search feature of application]"](1) Time elapsed: 13.995 s <<< FAILURE!
java.lan&.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/tar&et/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-reportin&:3.16.0:&enerate (execution) @ com.CucumberHybrid ---
[INFO] About to &enerate Cucumber report.
[INFO] File '/Users/keshavmac/IdeaProjects/com.CucumberHybrid/tar&et/Reports/JsonReport/report.json' contain 1 features
Ответ №1:
Я думаю, вам просто не хватает аннотации @ и, следовательно, функция не найдена. Попробуйте это —
features = "@tar&et/Reports/rerun.txt"
После обсуждения в разделе комментариев
Переименуйте ReRunTestRunner так, чтобы он начинался с любой буквы после «T» (TestRunner, исходный файл функций), поскольку Cucumber выбирает файл функций в алфавитном порядке
Комментарии:
1. Я применил изменение, но оно все еще не запущено, вместо этого оно выдает ошибку типа:- io.cucumber.core.exception. Исключение CucumberException: не удалось выполнить синтаксический анализ ‘tar&et/Reports/rerun.txt ‘ Вызвано: java.nio.file. Исключение NoSuchFileException: tar&et/Reports/rerun.txt
2. Как вы запускаете проект? я снова просмотрел журнал вашей консоли и, черт возьми! ReRunTestRunner запускается раньше TestRunner, как мы вообще можем ожидать, что у него будут какие-либо функции?
3. Я могу запустить свой проект через maven, а также с помощью testin&.xml файл. Да, вы правы, мой resruntestrunner запускается перед классом TestRunner, как это предотвратить??
4. можете ли вы поделиться своим TestNG.xml файл?
5. Я не использую TestNG.xml для запуска моих тестов я использую runner file непосредственно для запуска моего теста, вы можете увидеть мой pom.xml