├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── serenity.properties ├── settings.gradle └── src ├── main ├── java │ └── net │ │ ├── serenitybdd │ │ └── jbehave │ │ │ ├── ClassFinder.java │ │ │ ├── GivenStoryMonitor.java │ │ │ ├── RootPackage.java │ │ │ ├── SerenityCandidateSteps.java │ │ │ ├── SerenityJBehave.java │ │ │ ├── SerenityJBehaveSystemProperties.java │ │ │ ├── SerenityJBehaveTestRunner.java │ │ │ ├── SerenityReporter.java │ │ │ ├── SerenityStepCandidate.java │ │ │ ├── SerenityStepContext.java │ │ │ ├── SerenityStepFactory.java │ │ │ ├── SerenityStepInitializationError.java │ │ │ ├── SerenityStories.java │ │ │ ├── SerenityStory.java │ │ │ ├── StoryPathFinder.java │ │ │ ├── annotations │ │ │ └── Metafilter.java │ │ │ ├── converters │ │ │ ├── DateTimeConverter.java │ │ │ ├── TimeConverter.java │ │ │ └── YearMonthConverter.java │ │ │ ├── embedders │ │ │ ├── ExtendedEmbedder.java │ │ │ └── monitors │ │ │ │ ├── CompositeEmbedderMonitor.java │ │ │ │ └── ReportingEmbedderMonitor.java │ │ │ ├── reflection │ │ │ └── Extract.java │ │ │ ├── runners │ │ │ └── SerenityReportingRunner.java │ │ │ └── service │ │ │ └── JBehaveTagProviderStrategy.java │ │ └── thucydides │ │ └── jbehave │ │ ├── ThucydidesJUnitStories.java │ │ ├── ThucydidesJUnitStory.java │ │ └── annotations │ │ └── Metafilter.java └── resources │ └── META-INF │ └── services │ └── net.thucydides.core.statistics.service.TagProviderStrategy ├── smoketests ├── README.md ├── pom.xml ├── serenity.properties └── src │ └── test │ ├── java │ └── smoketests │ │ ├── RunASingleScenario.java │ │ ├── TagDemo.java │ │ ├── WhenDeclaringManualScenarios.java │ │ ├── WhenSkippingScenarios.java │ │ ├── WhenUsingGivenStoriesWithWebTests.java │ │ ├── WhenUsingLifecycleStepsWithWebTests.java │ │ ├── WhenUsingSimpleLifecycleSteps.java │ │ ├── WhenUsingStepLibraries.java │ │ ├── WhenUsingTables.java │ │ └── stepdefinitions │ │ ├── LifecycleStepDefinitions.java │ │ ├── SkippingScenariosStepDefinitions.java │ │ └── UsingStepLibrariesStepDefinitions.java │ └── resources │ ├── preconditions │ ├── aPreconditionCalculator.story │ └── aPreconditionDuckDuckGo.story │ └── stories │ ├── jbehave_lifecycle_phases │ ├── when_using_after_stories_steps.story │ ├── when_using_lifecycle_steps_with_web_tests.story │ ├── when_using_more_given_stories.story │ └── when_using_simple_lifecycle_steps.story │ ├── overview.md │ ├── skipped_pending_and_manual_scenarios │ ├── when_declaring_manual_scenarios.story │ └── when_skipping_scenarios.story │ ├── understanding_serenity_steps │ ├── overview.md │ └── when_using_step_libraries.story │ └── using_tables │ └── when_using_tables.story └── test ├── java ├── com │ └── ClassWithOnePackage.java └── net │ └── serenitybdd │ └── jbehave │ ├── ABehaviorContainingSlowTests.java │ ├── ABehaviorWithAFailingAssumption.java │ ├── ABehaviorWithATaggedPendingAndSkippedScenarios.java │ ├── ABehaviorWithAnError.java │ ├── ABehaviorWithCustomMetaTags.java │ ├── ABehaviorWithSeleniumPageObjects.java │ ├── ABehaviorWithSpringBeans.java │ ├── ABehaviorWithTags.java │ ├── AFailingBehavior.java │ ├── AFailingBehaviorWithSelenium.java │ ├── AFailingDataDrivenBehavior.java │ ├── APassingBehavior.java │ ├── APassingBehaviorWithABeforeClause.java │ ├── APassingBehaviorWithSeveralScenarios.java │ ├── APassingBehaviorWithState.java │ ├── APassingWebTestSample.java │ ├── APassingWebTestSampleWithASpecifiedBrowser.java │ ├── APassingWebTestSampleWithNestedSteps.java │ ├── APassingWebTestSampleWithThucydidesPropertiesDefined.java │ ├── APendingDataDrivenBehavior.java │ ├── ASampleBehaviorForUatOnly.java │ ├── ASampleBehaviorWithSharedVariables.java │ ├── ASetOfBehaviorsContainingFailures.java │ ├── ASetOfBehaviorsContainingWebTestFailures.java │ ├── ASetOfSampleBehaviorsContainingSlowTests.java │ ├── ASetOfSeleniumTests.java │ ├── ASlowBehavior.java │ ├── AStoryInTheStoriesDirectory.java │ ├── AStorySample.java │ ├── AStorySampleSpecifyingTheDriver.java │ ├── AbstractJBehaveStory.java │ ├── AllBehaviors.java │ ├── AnotherPassingBehavior.java │ ├── BehaviorWithEmbeddedTables.java │ ├── BehaviorsForUatAndTestEnvironments.java │ ├── DataDrivenBehavior.java │ ├── DataDrivenBehaviorWithSelenium.java │ ├── FixtureMethods.java │ ├── TestOutcomeFinder.java │ ├── WhenConfiguringJBehaveStorySteps.java │ ├── WhenDeterminingTheRootPathOfAPackage.java │ ├── WhenFindingStoriesOnTheClasspath.java │ ├── WhenHandlingJodaStepParameters.java │ ├── WhenLoadingClassesFromAPackage.java │ ├── WhenRunningASelectionOfJBehaveStories.java │ ├── WhenRunningDataDrivenJBehaveStories.java │ ├── WhenRunningJBehaveFixtures.java │ ├── WhenRunningJBehaveStories.java │ ├── WhenRunningJBehaveStoriesManualTags.java │ ├── WhenRunningJBehaveStoriesWithError.java │ ├── WhenRunningJBehaveStoriesWithFailure.java │ ├── WhenRunningJBehaveStoriesWithIgnored.java │ ├── WhenRunningJBehaveStoriesWithPending.java │ ├── WhenRunningJBehaveStoriesWithScreenshots.java │ ├── WhenRunningJBehaveStoriesWithSkipped.java │ ├── WhenRunningJBehaveStoriesWithSuccess.java │ ├── WhenRunningJBehaveStoriesWithTags.java │ ├── WhenRunningJBehaveStoriesWithTitle.java │ ├── WhenRunningWebJBehaveStories.java │ ├── WhenRunningWebJBehaveStoriesUsingAdvancedBrowserManagement.java │ ├── WhenRunningWebJBehaveStoriesUsingDataDriven.java │ ├── WhenRunningWebJBehaveStoriesUsingPageObjects.java │ ├── WithAnAnnotatedMetafilter.java │ ├── YetAnotherPassingBehavior.java │ ├── converters │ └── WhenConvertingJodaDateTimes.java │ ├── pages │ └── StaticSitePage.java │ ├── samples │ └── levels │ │ ├── first │ │ └── SerenityStorySampleForFistLevel.java │ │ └── second │ │ └── SerenityStorySampleForSecondLevel.java │ ├── smoketests │ ├── LifecycleStepDefinitions.java │ ├── SkippingScenariosStepDefinitions.java │ ├── UsingStepLibrariesStepDefinitions.java │ ├── WhenSkippingScenarios.java │ ├── WhenUsingGivenStoriesWithWebTests.java │ ├── WhenUsingSimpleLifecycleSteps.java │ └── WhenUsingStepLibraries.java │ └── steps │ ├── CheckValuesStep.java │ ├── CompositeSteps.java │ ├── EnterNamesStep.java │ ├── NestedSpringEnabledSteps.java │ ├── NestedSteps.java │ ├── ParameterizedSteps.java │ ├── SomeDataDrivenSteps.java │ ├── SomeNestedSeleniumSteps.java │ ├── SomeNonWebDataDrivenSteps.java │ ├── SomeNormalSteps.java │ ├── SomeSeleniumSteps.java │ ├── SomeSerenitySteps.java │ ├── SomeStepsWithState.java │ ├── SpringEnabledSteps.java │ ├── StepsWithSharedVariables.java │ ├── StorySteps.java │ ├── StoryStepsUsingACustomTag.java │ ├── StoryStepsWithPageObjects.java │ ├── StoryStepsWithSerenitySteps.java │ ├── WidgetService.java │ └── dateconversions │ ├── DateTimeConversionSteps.java │ ├── LocalTimeConversionSteps.java │ └── MonthYearConversionSteps.java └── resources ├── data └── names-data.csv ├── log4j.properties ├── spring └── config.xml ├── static-site ├── index-with-jquery.html ├── index.html └── jquery.min.js ├── stories ├── BehaviorWithEmbeddedTables.story ├── LookupADefinitionSuite.story ├── RunningASimpleJBehaveBehavior.story ├── aBehaviorThrowingAnException.story ├── aBehaviorWithADescription.story ├── aBehaviorWithAFailingAssumption.story ├── aBehaviorWithAPendingStep.story ├── aBehaviorWithATaggedPendingAndSkippedScenarios.story ├── aBehaviorWithATitle.story ├── aBehaviorWithAnError.story ├── aBehaviorWithAnIssue.story ├── aBehaviorWithAnUndefinedStep.story ├── aBehaviorWithCompositeSteps.story ├── aBehaviorWithCustomMetaTags.story ├── aBehaviorWithCustomMetaTagsAtSeveralLevels.story ├── aBehaviorWithCustomMetaTagsInSeveralScenarios.story ├── aBehaviorWithDatesAndTimes.story ├── aBehaviorWithFeatures.story ├── aBehaviorWithGivenStories.story ├── aBehaviorWithIssues.story ├── aBehaviorWithManualAndNotManualScenario.story ├── aBehaviorWithManualScenario.story ├── aBehaviorWithManualStory.story ├── aBehaviorWithMultipleFeatures.story ├── aBehaviorWithMultipleIssues.story ├── aBehaviorWithNoTitle.story ├── aBehaviorWithOneGivenStoriesBeforeAScenario.story ├── aBehaviorWithOneStoryAndMultipleIssues.story ├── aBehaviorWithSeleniumPageObjects.story ├── aBehaviorWithSeleniumUsingADifferentBrowser.story ├── aBehaviorWithSharedVariables.story ├── aBehaviorWithSkippedManualScenario.story ├── aBehaviorWithSpringBeans.story ├── aBehaviorWithTags.story ├── aComplexFailingBehavior.story ├── aDataDrivenBehavior.story ├── aFailingBehavior.story ├── aFailingBehaviorWithSelenium.story ├── aFailingDataDrivenBehavior.story ├── aPassingBehavior.story ├── aPassingBehaviorWithABeforeClause.story ├── aPassingBehaviorWithALongName.story ├── aPassingBehaviorWithSelenium.story ├── aPassingBehaviorWithSeleniumAndFirefox.story ├── aPassingBehaviorWithSeleniumAndSeveralScenarios.story ├── aPassingBehaviorWithSeveralScenarios.story ├── aPassingBehaviorWithState.story ├── aPassingBehaviorWithSteps.story ├── aPassingWebTestSampleWithNestedSteps.story ├── aPendingBehavior.story ├── aPendingDataDrivenBehavior.story ├── aPendingImplementedBehavior.story ├── aSampleBehaviorForUatOnly.story ├── aSecondPassingBehaviorWithState.story ├── aSkippedBehavior.story ├── aSlowBehavior.story ├── aTaggedPendingBehaviorWithSeveralScenarios.story ├── aTaggedWIPBehaviorWithSeveralScenarios.story ├── aWIPBehavior.story ├── acceptance_criteria │ └── HandlingJodaStepParameters.story ├── anotherPassingBehaviorWithSeleniumAndSeveralScenarios.story ├── anotherSlowBehavior.story ├── another_passing_behavior.story ├── behavior_dev_tagged.story ├── behavior_test_tagged.story ├── behavior_uat_tagged.story ├── dataDrivenBehavior.story ├── dataDrivenBehaviorWithSelenium.story ├── failingAndPassingBehaviorsWithSelenium.story ├── precondition │ ├── aPreconditionDuckDuckGo.story │ ├── aPreconditionToFile.story │ ├── aPreconditionToLookUpADefinition.story │ ├── aPreconditionToScenario1.story │ └── aPreconditionToScenario2.story ├── samples │ ├── GivenSomeOtherPrecondition.story │ ├── GivenSomePrecondition.story │ ├── SomeBehavior.story │ ├── SomeMoreBehavior.story │ └── SomeOtherBehavior.story ├── smoketests │ ├── when_skipping_scenarios.story │ ├── when_using_given_stories_with_web_tests.story │ ├── when_using_lifecycle_steps.story │ ├── when_using_simple_lifecycle_steps.story │ └── when_using_step_libraries.story └── subset │ ├── andAnotherPassingBehavior.story │ ├── anotherPassingBehavior.story │ └── yetAnotherPassingBehavior.story └── thucydides.properties /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .gradle 3 | .idea 4 | lib 5 | target 6 | *.iml 7 | *.log 8 | /serenity-jbehave.ipr 9 | /serenity-jbehave.iws 10 | /bin 11 | .project 12 | .settings 13 | .classpath -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | before_install: 3 | - chmod +x gradlew 4 | - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 5 | - sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' 6 | - wget -N http://chromedriver.storage.googleapis.com/2.11/chromedriver_linux64.zip 7 | - unzip chromedriver_linux64.zip 8 | - chmod +x chromedriver 9 | - sudo mv -f chromedriver /usr/local/share/chromedriver 10 | - sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver 11 | - sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver 12 | - sudo apt-get update 13 | - sudo apt-get install unzip 14 | - sudo apt-get install firefox 15 | - sudo apt-get install google-chrome-stable 16 | - "export DISPLAY=:99.0" 17 | - "sh -e /etc/init.d/xvfb start" 18 | 19 | script: gradle test integrationTests browserTests 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NOTE:JBehave is no longer currently supported in Serenity BDD - we advise migrating to Cucumber instead 2 | 3 | ## Serenity JBehave Integration 4 | 5 | Serenity (previously known as 'Thucydides') is a library designed to make writing automated acceptance tests easier, 6 | and more fun. 7 | 8 | ## What does it do? 9 | 10 | This module lets you write your BDD acceptance tests using JBehave, and generate fabulous living documentation reports 11 | based on the outcomes of these tests. 12 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | serenityCoreVersion = 2.0.58 2 | 3 | groovyVersion = 2.4.13 4 | junitVersion = 4.12 5 | reflectionsVersion = 0.9.11 6 | mockitoCoreVersion = 2.25.0 7 | jbehaveCoreVersion = 4.5 8 | 9 | gradleVersion = 5.2.1 10 | 11 | logbackVersion = 1.2.3 12 | jbehaveJUnitRunner = 2.3.0 13 | assertjVersion = 3.9.0 14 | paranamerVersion = 2.8 15 | commonsLoggingVersion = 1.2 16 | springVersion = 5.0.5.RELEASE 17 | springBootVersion = 2.0.1.RELEASE 18 | guavaVersion = 25.0-jre 19 | seleniumVersion = 3.141.59 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serenity-bdd/serenity-jbehave/2f88898eee446ad5017b8118790f4e0d7ae17244/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /serenity.properties: -------------------------------------------------------------------------------- 1 | story.timeout.in.secs=300 2 | #metafilter=-skip 3 | #webdriver.driver=htmlunit -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'serenity-jbehave' -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/GivenStoryMonitor.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class GivenStoryMonitor { 4 | 5 | private boolean inGivenStory = false; 6 | 7 | public void enteringGivenStory() { 8 | inGivenStory = true; 9 | } 10 | 11 | public boolean isInGivenStory() { 12 | return inGivenStory; 13 | } 14 | 15 | public void exitingGivenStory() { 16 | inGivenStory = false; 17 | } 18 | 19 | public void clear() { 20 | inGivenStory = false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/RootPackage.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import java.util.Arrays; 4 | 5 | public class RootPackage { 6 | 7 | public static String forPackage(Package testPackage) { 8 | String[] elements = testPackage.getName().split("\\."); 9 | if (elements.length == 1) { return elements[0]; } 10 | 11 | elements = Arrays.copyOfRange(elements, 0, elements.length - 1); 12 | 13 | return concatElements(elements); 14 | } 15 | 16 | private static String concatElements(final String[] subpaths) { 17 | final StringBuilder builder = new StringBuilder(); 18 | for (String path : subpaths) { 19 | builder.append(path).append("."); 20 | } 21 | return (builder.toString().isEmpty()) ? "" : builder.substring(0, builder.length() - 1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityCandidateSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import org.jbehave.core.annotations.ScenarioType; 4 | import org.jbehave.core.configuration.Configuration; 5 | import org.jbehave.core.steps.BeforeOrAfterStep; 6 | import org.jbehave.core.steps.CandidateSteps; 7 | import org.jbehave.core.steps.StepCandidate; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | public class SerenityCandidateSteps implements CandidateSteps { 13 | private final CandidateSteps candidateSteps; 14 | 15 | SerenityCandidateSteps(CandidateSteps candidateSteps) { 16 | this.candidateSteps = candidateSteps; 17 | } 18 | 19 | @Override 20 | public List listCandidates() { 21 | 22 | return candidateSteps.listCandidates().parallelStream() 23 | .map(SerenityStepCandidate::new) 24 | .collect(Collectors.toList()); 25 | } 26 | 27 | @Override 28 | public List listBeforeOrAfterStories() { 29 | return candidateSteps.listBeforeOrAfterStories(); 30 | } 31 | 32 | @Override 33 | public List listBeforeOrAfterStory(boolean givenStory) { 34 | return candidateSteps.listBeforeOrAfterStory(givenStory); 35 | } 36 | 37 | @Override 38 | public List listBeforeOrAfterScenario(ScenarioType type) { 39 | return candidateSteps.listBeforeOrAfterScenario(type); 40 | } 41 | 42 | @Override 43 | public Configuration configuration() { 44 | return candidateSteps.configuration(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityJBehave.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.serenitybdd.jbehave.converters.*; 4 | import org.jbehave.core.Embeddable; 5 | import org.jbehave.core.configuration.Configuration; 6 | import org.jbehave.core.configuration.ParanamerConfiguration; 7 | import org.jbehave.core.failures.FailureStrategy; 8 | import org.jbehave.core.failures.UUIDExceptionWrapper; 9 | import org.jbehave.core.io.CodeLocations; 10 | import org.jbehave.core.io.LoadFromClasspath; 11 | import org.jbehave.core.model.TableTransformers; 12 | import org.jbehave.core.reporters.FilePrintStreamFactory; 13 | import org.jbehave.core.reporters.Format; 14 | import org.jbehave.core.reporters.StoryReporterBuilder; 15 | import org.jbehave.core.steps.ParameterConverters; 16 | import org.junit.internal.AssumptionViolatedException; 17 | 18 | import java.nio.charset.StandardCharsets; 19 | import java.util.List; 20 | import java.util.Properties; 21 | 22 | /** 23 | * A convenience class designed to make it easier to set up JBehave tests with ThucydidesWebdriverIntegration. 24 | */ 25 | public class SerenityJBehave { 26 | 27 | // private static final CrossReference xref = new CrossReference(); 28 | 29 | /** 30 | * Returns a default JBehave configuration object suitable for ThucydidesWebdriverIntegration tests. 31 | */ 32 | public static Configuration defaultConfiguration(net.thucydides.core.webdriver.DriverConfiguration systemConfiguration, 33 | List formats, 34 | Embeddable embeddable) { 35 | 36 | Class embeddableClass = embeddable.getClass(); 37 | 38 | Properties viewResources = new Properties(); 39 | viewResources.put("decorateNonHtml", "true"); 40 | 41 | TableTransformers tableTransformers = new TableTransformers(); 42 | LoadFromClasspath utf8StoryLoader = new LoadFromClasspath(StandardCharsets.UTF_8); 43 | return new ParanamerConfiguration() 44 | .useTableTransformers(tableTransformers) 45 | .useParameterConverters( 46 | new ParameterConverters(utf8StoryLoader, tableTransformers).addConverters( 47 | new ParameterConverters.DateConverter(), 48 | new DateTimeConverter(), 49 | new YearMonthConverter(), 50 | new TimeConverter(), 51 | new ParameterConverters.EnumConverter(), 52 | new ParameterConverters.EnumListConverter())) 53 | .useStoryReporterBuilder( 54 | new StoryReporterBuilder() 55 | .withDefaultFormats() 56 | .withFormats(formats.toArray(new Format[0])) 57 | // .withCrossReference(xref) 58 | .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)) 59 | .withViewResources(viewResources) 60 | .withPathResolver(new FilePrintStreamFactory.ResolveToPackagedName()) 61 | .withFailureTrace(true).withFailureTraceCompression(true) 62 | .withReporters(new SerenityReporter(systemConfiguration))) 63 | .useStoryLoader(utf8StoryLoader) 64 | .useFailureStrategy(new IgnoreAssumptionViolations()); 65 | } 66 | 67 | private static class IgnoreAssumptionViolations implements FailureStrategy { 68 | @Override 69 | public void handleFailure(Throwable throwable) throws Throwable { 70 | if (throwable instanceof AssumptionViolatedException) { 71 | return; 72 | } 73 | if (throwable instanceof UUIDExceptionWrapper) { 74 | this.handleFailure(throwable.getCause()); 75 | } 76 | throw throwable; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityJBehaveSystemProperties.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | /** 4 | * Specifies system property values for the JBehave configuration. 5 | */ 6 | public enum SerenityJBehaveSystemProperties { 7 | 8 | /** 9 | * Set the JBehave ignoreFailuresInStories options. 10 | */ 11 | IGNORE_FAILURES_IN_STORIES, 12 | 13 | /** 14 | * @deprecated use story.timeout instead 15 | * How long before the JBehave stories time out (defaults to 300 seconds, or 5 minutes). 16 | * Note that this applies to ALL of the JBehave stories as a whole (i.e. the total test 17 | * time for all of the tests), not the individual tests. 18 | */ 19 | STORY_TIMEOUT_IN_SECS, 20 | 21 | /** 22 | * This appears to have replaced the story.timeout.in.secs property in the JBehave API. 23 | */ 24 | STORY_TIMEOUT, 25 | 26 | /** 27 | * JBehave meta filters expressions, separated by commas. 28 | * These use the meta annotations in the JBehave stories to decide what stories to 29 | * execute. See http://jbehave.org/reference/stable/meta-filtering.html for details 30 | * on how the metafilter syntax works. 31 | */ 32 | METAFILTER, 33 | 34 | /** 35 | * A regular expression that indicates which stories are included in the test run, based on the story name. 36 | * Can be used to speed up tests, but must be used in conjunction with the metafilter tag. 37 | */ 38 | STORY_FILTER, 39 | 40 | /** 41 | * If you don't restart a browser between scenarios, do you clear the session cookies? (defaults to true) 42 | */ 43 | RESET_COOKIES_EACH_SCENARIO, 44 | 45 | /** 46 | * Reset step libraries in JBehave step definitions for each scenario. 47 | * If this property is set to true (the default), any @Step-annotated member variables in JBehave step definitions 48 | * will be reinitialized before each scenario. 49 | */ 50 | RESET_STEPS_EACH_SCENARIO, 51 | 52 | 53 | /** 54 | * Define a directory for the .story files, inside src/test/resources. By default, this is 'stories' 55 | */ 56 | STORY_DIRECTORY, 57 | 58 | /** 59 | * If the JBehave stories are in a JAR file, we need to provide a semi-colon separated list of packages for 60 | * the test runner to look in, e.g. "/my/package;/my/other/package" 61 | * If the stories are in the root package or in the "stories" folder, this is not required. 62 | */ 63 | JBEHAVE_STORY_PACKAGES, 64 | 65 | /** 66 | * Controls the ignoreFailuresInView flag in JBehave (see http://jbehave.org/reference/stable/running-stories.html). 67 | */ 68 | IGNORE_FAILURES_IN_VIEW, 69 | 70 | /** 71 | * The number of threads to run stories in. 72 | */ 73 | JBEHAVE_THREADS; 74 | 75 | public String getName() {return toString().toLowerCase().replaceAll("_",".");} 76 | 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityJBehaveTestRunner.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import org.junit.runner.Runner; 4 | import org.junit.runners.Suite; 5 | import org.junit.runners.model.InitializationError; 6 | 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | public class SerenityJBehaveTestRunner extends Suite { 11 | 12 | private final Class testClass; 13 | 14 | public SerenityJBehaveTestRunner(Class klass) throws InitializationError { 15 | super(klass, Collections.emptyList()); 16 | this.testClass = klass; 17 | } 18 | 19 | @Override 20 | protected List getChildren() { 21 | return super.getChildren(); //To change body of overridden methods use File | Settings | File Templates. 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityStepCandidate.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.serenitybdd.jbehave.reflection.Extract; 4 | import org.jbehave.core.configuration.Keywords; 5 | import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser; 6 | import org.jbehave.core.steps.InjectableStepsFactory; 7 | import org.jbehave.core.steps.ParameterControls; 8 | import org.jbehave.core.steps.ParameterConverters; 9 | import org.jbehave.core.steps.Step; 10 | import org.jbehave.core.steps.StepCandidate; 11 | import org.jbehave.core.steps.StepType; 12 | import org.jbehave.core.steps.context.StepsContext; 13 | 14 | import java.lang.reflect.Method; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | public class SerenityStepCandidate extends StepCandidate { 19 | 20 | private final StepCandidate stepCandidate; 21 | 22 | public SerenityStepCandidate(StepCandidate stepCandidate) { 23 | 24 | super(stepCandidate.getPatternAsString(), 25 | stepCandidate.getPriority(), 26 | stepCandidate.getStepType(), 27 | stepCandidate.getMethod(), 28 | (Class) Extract.field("stepsType").from(stepCandidate), 29 | (InjectableStepsFactory) Extract.field("stepsFactory").from(stepCandidate), 30 | new StepsContext(), 31 | (Keywords) Extract.field("keywords").from(stepCandidate), 32 | new RegexPrefixCapturingPatternParser(), 33 | new ParameterConverters(), 34 | new ParameterControls()); 35 | this.composedOf(stepCandidate.composedSteps()); 36 | this.stepCandidate = stepCandidate; 37 | } 38 | 39 | @Override 40 | public Method getMethod() { 41 | return stepCandidate.getMethod(); 42 | } 43 | 44 | @Override 45 | public Integer getPriority() { 46 | return stepCandidate.getPriority(); 47 | } 48 | 49 | @Override 50 | public String getPatternAsString() { 51 | return stepCandidate.getPatternAsString(); 52 | } 53 | 54 | @Override 55 | public StepType getStepType() { 56 | return stepCandidate.getStepType(); 57 | } 58 | 59 | @Override 60 | public String getStartingWord() { 61 | return stepCandidate.getStartingWord(); 62 | } 63 | 64 | @Override 65 | public boolean isComposite() { 66 | return stepCandidate.isComposite(); 67 | } 68 | 69 | @Override 70 | public String[] composedSteps() { 71 | return stepCandidate.composedSteps(); 72 | } 73 | 74 | @Override 75 | public boolean ignore(String stepAsString) { 76 | return stepCandidate.ignore(stepAsString); 77 | } 78 | 79 | @Override 80 | public boolean isPending() { 81 | return stepCandidate.isPending(); 82 | } 83 | 84 | @Override 85 | public boolean matches(String stepAsString) { 86 | return stepCandidate.matches(stepAsString); 87 | } 88 | 89 | @Override 90 | public boolean matches(String step, String previousNonAndStep) { 91 | return stepCandidate.matches(step, previousNonAndStep); 92 | } 93 | 94 | @Override 95 | public Step createMatchedStep(String stepAsString, Map namedParameters, List composedSteps) { 96 | return stepCandidate.createMatchedStep(stepAsString, namedParameters, composedSteps); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return stepCandidate.toString(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityStepContext.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.pages.Pages; 4 | import net.thucydides.core.webdriver.ThucydidesWebDriverSupport; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.lang.reflect.Constructor; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Keeps track of instantiated JBehave step libraries used in ThucydidesWebdriverIntegration tests. 14 | */ 15 | public class SerenityStepContext { 16 | 17 | private static final Logger LOGGER = LoggerFactory.getLogger(SerenityStepContext.class); 18 | 19 | private Map, Object> stepInstances = new HashMap<>(); 20 | 21 | public SerenityStepContext() { 22 | } 23 | 24 | public Object newInstanceOf(final Class type) { 25 | if (stepInstances.containsKey(type)) { 26 | return stepInstances.get(type); 27 | } else { 28 | Object newInstance = null; 29 | try { 30 | ThucydidesWebDriverSupport.getPages(); 31 | if (hasConstructorWithPagesParameter(type)) { 32 | newInstance = createNewPageEnabledStepCandidate(type); 33 | } else { 34 | newInstance = type.newInstance(); 35 | } 36 | } catch (Exception e) { 37 | throw new SerenityStepInitializationError(e); 38 | } 39 | stepInstances.put(type, newInstance); 40 | return newInstance; 41 | } 42 | } 43 | 44 | private boolean hasConstructorWithPagesParameter(Class type) { 45 | Class[] constructorArgs = new Class[1]; 46 | constructorArgs[0] = Pages.class; 47 | try { 48 | type.getConstructor(constructorArgs); 49 | } catch (NoSuchMethodException e) { 50 | return false; 51 | } 52 | return true; 53 | } 54 | 55 | private T createNewPageEnabledStepCandidate(final Class type) { 56 | T newInstance = null; 57 | try { 58 | Pages pageFactory = ThucydidesWebDriverSupport.getPages(); 59 | Class[] constructorArgs = new Class[1]; 60 | constructorArgs[0] = Pages.class; 61 | Constructor constructor = type.getConstructor(constructorArgs); 62 | newInstance = constructor.newInstance(pageFactory); 63 | } catch (Exception e) { 64 | LOGGER.info("Failed to instantiate page of type {} ({})", type, e.getMessage()); 65 | } 66 | return newInstance; 67 | } 68 | 69 | public void reset() { 70 | stepInstances.clear(); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityStepInitializationError.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class SerenityStepInitializationError extends RuntimeException { 4 | public SerenityStepInitializationError(Exception cause) { 5 | super(cause); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/SerenityStory.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | import net.thucydides.core.util.Inflector; 5 | import net.thucydides.core.webdriver.DriverConfiguration; 6 | import org.codehaus.plexus.util.StringUtils; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import static org.apache.commons.lang3.StringUtils.join; 12 | 13 | /** 14 | * Run an individual JBehave story in JUnit, where the name of the story is derived from the name of the test. 15 | * For example, a class called MyStory.java would run a JBehave story called "my_story.story" or MyStory.story. 16 | */ 17 | public class SerenityStory extends SerenityStories { 18 | public SerenityStory() { 19 | findStoriesCalled(storynamesDerivedFromClassName()); 20 | } 21 | 22 | public SerenityStory(EnvironmentVariables environmentVariables) { 23 | super(environmentVariables); 24 | findStoriesCalled(storynamesDerivedFromClassName()); 25 | } 26 | 27 | protected SerenityStory(DriverConfiguration configuration) { 28 | super(configuration); 29 | findStoriesCalled(storynamesDerivedFromClassName()); 30 | } 31 | 32 | @Override 33 | public void run() { 34 | super.run(); 35 | } 36 | 37 | protected String storynamesDerivedFromClassName() { 38 | 39 | List storyNames = getStoryNameCandidatesFrom(startingWithUpperCase(simpleClassName()), 40 | startingWithLowerCase(simpleClassName()), 41 | underscoredTestName()); 42 | return join(storyNames,";"); 43 | } 44 | 45 | private List getStoryNameCandidatesFrom(String... storyNameCandidates) { 46 | List storyNames = new ArrayList<>(); 47 | for(String storyName : storyNameCandidates) { 48 | if (storyNames.isEmpty()) { 49 | addIfPresent(storyNames, "/" + storyName + ".story"); 50 | addIfPresent(storyNames, "stories/" + storyName + ".story"); 51 | } 52 | } 53 | if (storyNames.isEmpty()) { 54 | for(String storyName : storyNameCandidates) { 55 | storyNames.add("**/" + storyName + ".story"); 56 | } 57 | } 58 | return storyNames; 59 | } 60 | 61 | private String startingWithUpperCase(String storyName) { 62 | return StringUtils.capitalise(storyName); 63 | } 64 | 65 | private String startingWithLowerCase(String storyName) { 66 | return StringUtils.lowercaseFirstLetter(storyName); 67 | } 68 | 69 | private void addIfPresent(List storyNames, String storyNameCandidate) { 70 | if (Thread.currentThread().getContextClassLoader().getResource(storyNameCandidate) != null) { 71 | storyNames.add(storyNameCandidate); 72 | } 73 | } 74 | 75 | private String simpleClassName() { 76 | return this.getClass().getSimpleName(); 77 | } 78 | 79 | private String underscoredTestName() { 80 | return Inflector.getInstance().of(simpleClassName()).withUnderscores().toString(); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/annotations/Metafilter.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface Metafilter { 11 | String value(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/converters/DateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.converters; 2 | 3 | import com.google.common.base.CharMatcher; 4 | import com.google.common.base.Splitter; 5 | import org.jbehave.core.steps.ParameterConverters; 6 | import org.joda.time.DateTime; 7 | import org.joda.time.format.DateTimeFormat; 8 | import org.joda.time.format.DateTimeFormatter; 9 | 10 | import java.lang.reflect.Type; 11 | import java.util.List; 12 | 13 | public class DateTimeConverter extends ParameterConverters.AbstractParameterConverter { 14 | 15 | public static final DateTimeFormatter CONVENTIONAL_FORMAT = DateTimeFormat.forPattern("ddMMyyyy"); 16 | public static final DateTimeFormatter ISO_FORMAT = DateTimeFormat.forPattern("yyyyMMdd"); 17 | 18 | private DateTimeFormatter dateFormat; 19 | 20 | public DateTimeConverter() { 21 | this(null); 22 | } 23 | 24 | public DateTimeConverter(DateTimeFormatter dateFormat) { 25 | this.dateFormat = dateFormat; 26 | } 27 | 28 | private DateTimeFormatter getBestFormatterFor(String value) { 29 | if (dateFormat == null) { 30 | if (startsWithYear(value)) { 31 | return ISO_FORMAT; 32 | } else { 33 | return CONVENTIONAL_FORMAT; 34 | } 35 | } 36 | return dateFormat; 37 | } 38 | 39 | private boolean startsWithYear(String value) { 40 | return getDateElementsFrom(value).get(0).length() == 4; 41 | } 42 | 43 | private List getDateElementsFrom(String value) { 44 | return Splitter.on(CharMatcher.anyOf("-/")).splitToList(value); 45 | } 46 | 47 | @Override 48 | public DateTime convertValue(String value, Type type) { 49 | DateTimeFormatter formatter = getBestFormatterFor(value); 50 | return DateTime.parse(normalized(value), formatter); 51 | } 52 | 53 | private String normalized(String value) { 54 | return value.replaceAll("/", "").replaceAll("-", ""); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/converters/TimeConverter.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.converters; 2 | 3 | import org.jbehave.core.steps.ParameterConverters; 4 | import org.joda.time.LocalTime; 5 | 6 | import java.lang.reflect.Type; 7 | 8 | public class TimeConverter extends ParameterConverters.AbstractParameterConverter { 9 | 10 | @Override 11 | public LocalTime convertValue(String value, Type type) { 12 | return LocalTime.parse(value); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/converters/YearMonthConverter.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.converters; 2 | 3 | import org.jbehave.core.steps.ParameterConverters; 4 | import org.joda.time.YearMonth; 5 | import org.joda.time.format.DateTimeFormat; 6 | import org.joda.time.format.DateTimeFormatter; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | public class YearMonthConverter extends ParameterConverters.AbstractParameterConverter { 11 | public static final DateTimeFormatter MONTH_YEAR_FORMAT_WITH_DASH = DateTimeFormat.forPattern("MM-yyyy"); 12 | public static final DateTimeFormatter MONTH_YEAR_FORMAT_WITH_SLASH = DateTimeFormat.forPattern("MM/yyyy"); 13 | public static final DateTimeFormatter YEAR_MONTH_FORMAT_WITH_DASH = DateTimeFormat.forPattern("yyyy-MM"); 14 | public static final DateTimeFormatter YEAR_MONTH_FORMAT_WITH_SLASH = DateTimeFormat.forPattern("yyyy/MM"); 15 | 16 | 17 | @Override 18 | public YearMonth convertValue(String value, Type type) { 19 | DateTimeFormatter formatter = hasDash(value) ? getFormatterWithDash(value) : getFormatterWithSlash(value); 20 | return YearMonth.parse(value, formatter); 21 | } 22 | 23 | private DateTimeFormatter getFormatterWithSlash(String value) { 24 | return value.trim().charAt(2) == '/' ? MONTH_YEAR_FORMAT_WITH_SLASH : YEAR_MONTH_FORMAT_WITH_SLASH; 25 | } 26 | 27 | private DateTimeFormatter getFormatterWithDash(String value) { 28 | return value.trim().charAt(2) == '-' ? MONTH_YEAR_FORMAT_WITH_DASH : YEAR_MONTH_FORMAT_WITH_DASH; 29 | } 30 | 31 | private boolean hasDash(String value) { 32 | return value.indexOf('-') > -1; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/reflection/Extract.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.reflection; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | public class Extract { 6 | 7 | private final String fieldName; 8 | 9 | private Extract(String fieldName) { 10 | this.fieldName = fieldName; 11 | } 12 | 13 | public static Extract field(String fieldName) { 14 | return new Extract(fieldName); 15 | } 16 | 17 | public Object from(Object object) { 18 | try { 19 | Field field = object.getClass().getDeclaredField(fieldName); 20 | field.setAccessible(true); 21 | return field.get(object); 22 | } catch (IllegalAccessException e) { 23 | e.printStackTrace(); 24 | } catch (NoSuchFieldException e) { 25 | e.printStackTrace(); 26 | } 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/serenitybdd/jbehave/service/JBehaveTagProviderStrategy.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.service; 2 | 3 | 4 | import com.google.common.collect.ImmutableSet; 5 | import net.thucydides.core.ThucydidesSystemProperty; 6 | import net.thucydides.core.guice.Injectors; 7 | import net.thucydides.core.requirements.FileSystemRequirementsTagProvider; 8 | import net.thucydides.core.statistics.service.ContextTagProvider; 9 | import net.thucydides.core.statistics.service.InjectedTagProvider; 10 | import net.thucydides.core.statistics.service.TagProvider; 11 | import net.thucydides.core.statistics.service.TagProviderStrategy; 12 | import net.thucydides.core.util.EnvironmentVariables; 13 | 14 | import static net.thucydides.core.steps.TestSourceType.TEST_SOURCE_JBEHAVE; 15 | 16 | public class JBehaveTagProviderStrategy implements TagProviderStrategy { 17 | 18 | private final EnvironmentVariables environmentVariables; 19 | 20 | public JBehaveTagProviderStrategy(EnvironmentVariables environmentVariables) { 21 | this.environmentVariables = environmentVariables; 22 | } 23 | 24 | public JBehaveTagProviderStrategy() { 25 | this(Injectors.getInjector().getInstance(EnvironmentVariables.class)); 26 | } 27 | 28 | @Override 29 | public boolean canHandleTestSource(String testType) { 30 | return TEST_SOURCE_JBEHAVE.getValue().equalsIgnoreCase(testType); 31 | } 32 | 33 | @Override 34 | public Iterable getTagProviders() { 35 | String rootDirectory = ThucydidesSystemProperty.THUCYDIDES_REQUIREMENTS_DIR.from(environmentVariables,"stories"); 36 | return ImmutableSet.of( 37 | new FileSystemRequirementsTagProvider(environmentVariables,rootDirectory), 38 | new InjectedTagProvider(environmentVariables), 39 | new ContextTagProvider(environmentVariables) 40 | ); 41 | } 42 | 43 | @Override 44 | public boolean hasHighPriority() { 45 | return false; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/thucydides/jbehave/ThucydidesJUnitStories.java: -------------------------------------------------------------------------------- 1 | package net.thucydides.jbehave; 2 | 3 | import net.serenitybdd.jbehave.SerenityStories; 4 | import net.serenitybdd.jbehave.runners.SerenityReportingRunner; 5 | import net.thucydides.core.util.EnvironmentVariables; 6 | import net.thucydides.core.webdriver.DriverConfiguration; 7 | import org.junit.runner.RunWith; 8 | 9 | /** 10 | * @deprecated Use SerenityStories instead 11 | * 12 | * A JUnit-runnable test case designed to run a set of ThucydidesWebdriverIntegration-enabled JBehave stories in a given package. 13 | * By default, it will look for *.story files on the classpath, and steps in or underneath the current package. 14 | * You can redefine these constraints as follows: 15 | */ 16 | @Deprecated 17 | @RunWith(SerenityReportingRunner.class) 18 | public class ThucydidesJUnitStories extends SerenityStories { 19 | 20 | public ThucydidesJUnitStories() { 21 | super(); 22 | } 23 | 24 | protected ThucydidesJUnitStories(EnvironmentVariables environmentVariables) { 25 | super(environmentVariables); 26 | } 27 | 28 | protected ThucydidesJUnitStories(DriverConfiguration configuration) { 29 | super(configuration); 30 | } 31 | 32 | public ThucydidesConfigurationBuilder runThucydides() { 33 | return super.runSerenity(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/thucydides/jbehave/ThucydidesJUnitStory.java: -------------------------------------------------------------------------------- 1 | package net.thucydides.jbehave; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | import net.thucydides.core.util.EnvironmentVariables; 5 | import net.thucydides.core.webdriver.DriverConfiguration; 6 | 7 | /** 8 | * @deprecated Use SerenityStory instead 9 | *

10 | * Run an individual JBehave story in JUnit, where the name of the story is derived from the name of the test. 11 | * For example, a class called MyStory.jav 12 | * a would run a JBehave story called "my_story.story" or MyStory.story. 13 | */ 14 | @Deprecated 15 | public class ThucydidesJUnitStory extends SerenityStory { 16 | public ThucydidesJUnitStory() { 17 | super(); 18 | } 19 | 20 | public ThucydidesJUnitStory(EnvironmentVariables environmentVariables) { 21 | super(environmentVariables); 22 | } 23 | 24 | protected ThucydidesJUnitStory(DriverConfiguration configuration) { 25 | super(configuration); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/thucydides/jbehave/annotations/Metafilter.java: -------------------------------------------------------------------------------- 1 | package net.thucydides.jbehave.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** @deprecated 9 | * Use Metafilter annotation in serenitybdd package instead 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.TYPE) 13 | @Deprecated 14 | public @interface Metafilter { 15 | String value(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.thucydides.core.statistics.service.TagProviderStrategy: -------------------------------------------------------------------------------- 1 | net.serenitybdd.jbehave.service.JBehaveTagProviderStrategy 2 | -------------------------------------------------------------------------------- /src/smoketests/README.md: -------------------------------------------------------------------------------- 1 | ## Serenity JBehave Smoke tests 2 | 3 | This sub-project contains a range of self-documenting tests that illustrate Serenity-JBehave features. 4 | 5 | Running the tests as follows should always pass: 6 | ``` 7 | $ mvn clean verify 8 | ``` 9 | or 10 | ``` 11 | $ gradle clean test aggregate 12 | ``` 13 | 14 | Running in the failure mode will intentionally fail with self-documenting errors. 15 | ``` 16 | $ mvn clean verify -PincludingFailures 17 | ``` 18 | or 19 | ``` 20 | gradle clean test aggregate -DincludingFailures 21 | ``` 22 | -------------------------------------------------------------------------------- /src/smoketests/serenity.properties: -------------------------------------------------------------------------------- 1 | #webdriver.driver=phantomjs 2 | webdriver.driver=firefox 3 | serenity.browser.height = 1000 4 | serenity.browser.width = 1600 5 | serenity.requirement.types = epic, feature -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/RunASingleScenario.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStories; 4 | import net.serenitybdd.jbehave.annotations.Metafilter; 5 | 6 | @Metafilter("+current") 7 | public class RunASingleScenario extends SerenityStories { } 8 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/TagDemo.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class TagDemo extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenDeclaringManualScenarios.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenDeclaringManualScenarios extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenSkippingScenarios.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenSkippingScenarios extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenUsingGivenStoriesWithWebTests.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingGivenStoriesWithWebTests extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenUsingLifecycleStepsWithWebTests.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingLifecycleStepsWithWebTests extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenUsingSimpleLifecycleSteps.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingSimpleLifecycleSteps extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenUsingStepLibraries.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | import net.thucydides.core.util.EnvironmentVariables; 5 | 6 | public class WhenUsingStepLibraries extends SerenityStory {} 7 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/WhenUsingTables.java: -------------------------------------------------------------------------------- 1 | package smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingTables extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/stepdefinitions/LifecycleStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package smoketests.stepdefinitions; 2 | 3 | import net.serenitybdd.core.pages.PageObject; 4 | import net.serenitybdd.core.pages.WebElementFacade; 5 | import net.thucydides.core.annotations.DefaultUrl; 6 | import net.thucydides.core.annotations.Step; 7 | import net.thucydides.core.annotations.Steps; 8 | import org.jbehave.core.annotations.*; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | public class LifecycleStepDefinitions { 13 | 14 | static class Calculations { 15 | 16 | int total = 0; 17 | 18 | @Step 19 | public void add(int amount) { 20 | total += amount; 21 | } 22 | 23 | @Step 24 | public void substract(int amount) { 25 | total -= amount; 26 | } 27 | 28 | public int getTotal() { return total; } 29 | 30 | } 31 | 32 | static class SelfishCalculations { 33 | 34 | int total = 0; 35 | 36 | @Step 37 | public void add(int amount) { 38 | total += amount; 39 | } 40 | 41 | @Step 42 | public void substract(int amount) { 43 | total -= amount; 44 | } 45 | 46 | public int getTotal() { return total; } 47 | 48 | } 49 | 50 | @Steps(shared = true) 51 | Calculations calculations; 52 | 53 | @Steps 54 | SelfishCalculations selfishCalculations; 55 | 56 | @Given("I have a calculator") 57 | public void givenIHaveACalculator() { 58 | assertThat(calculations).isNotNull(); 59 | } 60 | 61 | @Given("I have a scientific calculator") 62 | public void givenIHaveAScientificCalculator() { 63 | calculations = new Calculations(); 64 | } 65 | 66 | @AfterScenario 67 | public void afterScenario() { 68 | System.out.println("After scenario: " + calculations + "=>" + calculations.total); 69 | } 70 | 71 | @AfterStory 72 | public void afterStory() { 73 | System.out.println("After story: " + calculations + "=>" + calculations.total); 74 | } 75 | 76 | @AfterStories 77 | public void afterStories() { 78 | System.out.println("After stories: " + calculations + "=>" + calculations.total); 79 | } 80 | 81 | @Given("I add $amount") 82 | @Alias("I add ") 83 | public void givenIAdd(int amount) { 84 | calculations.add(amount); 85 | } 86 | 87 | @When("I add $amount") 88 | @Alias("I add ") 89 | public void whenIAdd(@Named("amount") int amount) { 90 | calculations.add(amount); 91 | } 92 | 93 | @When("I substract $amount") 94 | public void whenISubstract(int amount) { 95 | calculations.substract(amount); 96 | } 97 | 98 | @Then("the total should be $total") 99 | @Alias("the total should be ") 100 | public void thenTheTotalShouldBe(@Named("total") int total) { 101 | assertThat(calculations.total).isEqualTo(total); 102 | } 103 | 104 | @Then("the total should not be zero") 105 | public void thenTheTotalShouldNotBeZero() { 106 | assertThat(calculations.total).isNotZero(); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/stepdefinitions/SkippingScenariosStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package smoketests.stepdefinitions; 2 | 3 | import net.serenitybdd.core.SkipNested; 4 | import net.serenitybdd.core.pages.PageObject; 5 | import net.serenitybdd.core.pages.WebElementFacade; 6 | import net.thucydides.core.annotations.DefaultUrl; 7 | import net.thucydides.core.annotations.Step; 8 | import net.thucydides.core.annotations.Steps; 9 | import org.jbehave.core.annotations.Given; 10 | import org.jbehave.core.annotations.Then; 11 | import org.jbehave.core.annotations.When; 12 | import org.openqa.selenium.support.FindAll; 13 | import org.openqa.selenium.support.FindBy; 14 | 15 | import java.util.List; 16 | import java.util.concurrent.TimeUnit; 17 | import java.util.stream.Collectors; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.hamcrest.Matchers.greaterThan; 21 | 22 | public class SkippingScenariosStepDefinitions { 23 | 24 | @DefaultUrl("https://duckduckgo.com") 25 | public static class DuckDuckGoSearchPage extends PageObject { 26 | 27 | @FindBy(id="search_form_input_homepage") 28 | WebElementFacade searchField; 29 | 30 | @FindBy(id="search_button_homepage") 31 | WebElementFacade searchButton; 32 | 33 | @FindBy(className = "result__title") 34 | List results; 35 | 36 | @Step 37 | public void enterSearchTerm(String searchTerm) { 38 | searchField.type(searchTerm); 39 | searchButton.click(); 40 | } 41 | 42 | public List getResults() { 43 | return results.stream().map(element -> element.getText()).collect(Collectors.toList()); 44 | } 45 | } 46 | 47 | public static class TestSteps { 48 | 49 | @Step(callNestedMethods = false) 50 | public void print(String value) { 51 | System.out.println("INSIDE STEP WITH VALUE " + value); 52 | } 53 | } 54 | 55 | public static class CuriousSurfer implements SkipNested { 56 | 57 | DuckDuckGoSearchPage searchPage; 58 | 59 | @Step 60 | public void opensTheSearchApp() { 61 | searchPage.open(); 62 | } 63 | 64 | @Step 65 | public void searchesFor(String searchTerm) { 66 | System.out.println("searchesFor " + searchTerm); 67 | searchPage.enterSearchTerm(searchTerm); 68 | } 69 | 70 | @Step 71 | public void shouldSeeTitle(String title) { 72 | System.out.println("shouldSeeTitle " + title); 73 | assertThat(searchPage.getTitle()).contains(title); 74 | } 75 | 76 | @Step 77 | public void shouldSeeAListOfResults() { 78 | assertThat(searchPage.getResults().size()).isGreaterThan(0); 79 | } 80 | } 81 | 82 | @Steps 83 | CuriousSurfer connor; 84 | 85 | @Steps 86 | TestSteps steps; 87 | 88 | @When("print '$value'") 89 | public void print(String value) { 90 | System.out.println("WHEN STEP FOR " + value); 91 | steps.print(value); 92 | } 93 | 94 | @Given("I want to search for something") 95 | public void givenIWantToSearchForFruit() { 96 | System.out.println("Opens search page"); 97 | connor.opensTheSearchApp(); 98 | } 99 | 100 | @When("I lookup $searchTerm") 101 | public void whenILookup(String searchTerm) { 102 | connor.searchesFor(searchTerm); 103 | } 104 | 105 | @Then("I should see \"$title\" in the page title") 106 | public void thenIShouldSeeTitle(String title) { 107 | connor.shouldSeeTitle(title); 108 | } 109 | 110 | @Then("I should see search results") 111 | public void thenIShouldSeeSearchResults() { 112 | connor.shouldSeeAListOfResults(); 113 | } 114 | 115 | @Then("subsequent steps should be ignored") 116 | public void ignoreSubsequentSteps() {} 117 | 118 | @Then("steps should be ignored") 119 | public void ignoreSteps() {} 120 | 121 | 122 | @Given("I want to indicate that a scenario should be performed manually") 123 | public void manual() {} 124 | 125 | @Given("I also want it appearing in the skipped scenarios") 126 | public void appear_as_skipped() {} 127 | 128 | @When("I tag it as ${tags}") 129 | public void tag_as(String tags) {} 130 | 131 | @Then("it should be reported as ${state}") 132 | public void reported_as(String states) {} 133 | } 134 | -------------------------------------------------------------------------------- /src/smoketests/src/test/java/smoketests/stepdefinitions/UsingStepLibrariesStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package smoketests.stepdefinitions; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | import net.thucydides.core.annotations.Steps; 5 | import org.jbehave.core.annotations.*; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.*; 9 | 10 | public class UsingStepLibrariesStepDefinitions { 11 | 12 | 13 | public static class SomeStepLibrary { 14 | 15 | public int stepRunCount = 0; 16 | 17 | @Step 18 | public void doSomething() { 19 | stepRunCount++; 20 | } 21 | 22 | @Step 23 | public void doSomethingElse() { 24 | stepRunCount++; 25 | } 26 | 27 | @Step 28 | public void doSomeOtherThing() { 29 | stepRunCount++; 30 | } 31 | } 32 | 33 | @Steps 34 | private SomeStepLibrary someStepLibrary; 35 | 36 | @Given("I want to use a step library") 37 | public void givenIWantToUseAStepLibrary() { 38 | } 39 | 40 | @When("I use a step library field annotated with @Steps") 41 | public void whenIAddAStepLibraryFieldAnnotatedWithSteps() { 42 | } 43 | 44 | @Then("Serenity should instantiate the field") 45 | public void thenSerenityShouldInstantiateTheField() { 46 | assertThat(someStepLibrary, notNullValue()); 47 | } 48 | 49 | ////// 50 | 51 | @Steps 52 | private SomeStepLibrary someOtherStepLibrary; 53 | 54 | @Given("I want to use several step library fields of the same type") 55 | public void givenIWantToUseSeveralStepLibraryFieldsOfTheSameType() { 56 | } 57 | 58 | @When("I use a step library fields to each of them") 59 | public void whenIAddAStepLibraryFieldsToEachOfThem() { 60 | } 61 | 62 | @Then("Serenity should instantiate a different library for each field") 63 | public void thenSerenityShouldInstantiateADifferentLibraryForEachField() { 64 | assertThat(someOtherStepLibrary, is(not(sameInstance(someStepLibrary)))); 65 | } 66 | 67 | ///// 68 | @Steps 69 | private SomeStepLibrary myStepLibrary; 70 | 71 | @Given("I have a Serenity step library") 72 | public void givenIHaveASerenityStepLibrary() { 73 | } 74 | 75 | @When("I do something with the library") 76 | public void whenIDoSomethingWithTheLibrary() { 77 | myStepLibrary.doSomething(); 78 | } 79 | 80 | @Then("the state of the library should be updated") 81 | public void thenTheStateOfTheLibraryShouldBeUpdated() { 82 | assertThat(myStepLibrary.stepRunCount, is(2)); 83 | } 84 | 85 | //// 86 | 87 | 88 | @When("I start a new scenario") 89 | public void whenIStartANewScenario() { 90 | } 91 | 92 | @Then("the step library should be reinitialised") 93 | public void thenTheStepLibraryShouldBeReinitialised() { 94 | assertThat(myStepLibrary.stepRunCount, is(0)); 95 | } 96 | 97 | @Steps(shared = true) 98 | private SomeStepLibrary aSharedStepLibrary; 99 | 100 | @Steps(shared = true) 101 | private SomeStepLibrary anotherSharedStepLibrary; 102 | 103 | @Given("I have two Serenity step libraries") 104 | public void givenIHaveTwoSerenityStepLibraries() { 105 | } 106 | 107 | @When("they are annotated with @Steps(shared=true)") 108 | public void whenTheyAreAnnotatedWithStepssharedtrue() { 109 | } 110 | 111 | @Then("both should refer to the same instance") 112 | public void thenBothShouldReferToTheSameInstance() { 113 | assertThat(aSharedStepLibrary, is(sameInstance(anotherSharedStepLibrary))); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/preconditions/aPreconditionCalculator.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that creates a calculator 2 | 3 | Given I have a scientific calculator 4 | And I add 1 -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/preconditions/aPreconditionDuckDuckGo.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that opens the DuckDuckGo home page 2 | 3 | Given I want to search for something -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/jbehave_lifecycle_phases/when_using_after_stories_steps.story: -------------------------------------------------------------------------------- 1 | Lifecycle phases can be used to run steps before and after a scenario 2 | 3 | Lifecycle: 4 | Before: 5 | Given I have a calculator 6 | And I add 1 7 | After: 8 | Then the total should not be zero 9 | 10 | Scenario: A scenario with before and after phases 11 | @tag expected-outcome:success 12 | When I add 2 13 | Then the total should be 3 14 | 15 | Scenario: Another scenario with before and after phases 16 | Meta: 17 | @tag expected-outcome:success 18 | When I add 3 19 | Then the total should be 4 20 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/jbehave_lifecycle_phases/when_using_lifecycle_steps_with_web_tests.story: -------------------------------------------------------------------------------- 1 | Lifecycle phases also work with web tests 2 | 3 | Meta: 4 | @driver chrome 5 | 6 | Lifecycle: 7 | Before: Open the search page 8 | Given I want to search for something 9 | 10 | After: Check that some results are displayed 11 | Then I should see search results 12 | 13 | Scenario: Look for pears 14 | When I lookup pear 15 | Then I should see "DuckDuckGo" in the page title 16 | 17 | Scenario: Look for apples 18 | When I lookup apple 19 | Then I should see "DuckDuckGo" in the page title 20 | 21 | 22 | Scenario: Look for oranges 23 | When I lookup oranges 24 | Then I should see "DuckDuckGo" in the page title 25 | 26 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/jbehave_lifecycle_phases/when_using_more_given_stories.story: -------------------------------------------------------------------------------- 1 | A scenario that uses lifecycle phases 2 | 3 | GivenStories: preconditions/aPreconditionCalculator.story 4 | 5 | Scenario: You can use GivenStories in several places to run a whole story before starting a set of scenarios 6 | Meta: 7 | @current 8 | 9 | When I add 2 10 | Then the total should be 3 11 | 12 | Scenario: The GivenStories story is only ever run once before the story, but shared instances are conserved between scenarios in a story 13 | Meta: 14 | @current 15 | 16 | When I add 5 17 | Then the total should be 8 18 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/jbehave_lifecycle_phases/when_using_simple_lifecycle_steps.story: -------------------------------------------------------------------------------- 1 | Lifecycle phases can be used to run steps before and after a scenario 2 | 3 | Lifecycle: 4 | Before: 5 | Given I have a calculator 6 | And I add 1 7 | After: 8 | Then the total should not be zero 9 | 10 | Scenario: A scenario with before and after phases 11 | Meta: 12 | @tag expected-outcome:success 13 | When I add 2 14 | Then the total should be 3 15 | 16 | Scenario: Another scenario with before and after phases 17 | Meta: 18 | @tag expected-outcome:success 19 | When I add 3 20 | Then the total should be 4 21 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/overview.md: -------------------------------------------------------------------------------- 1 | ## An awesome overview.md app 2 | 3 | Really, really awesome. -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/skipped_pending_and_manual_scenarios/when_declaring_manual_scenarios.story: -------------------------------------------------------------------------------- 1 | Marking scenarios as 'manual' using metadata 2 | 3 | Scenario: A manual scenario 4 | Meta: 5 | @tag expected-outcome:pending 6 | @manual 7 | Given I want to indicate that a scenario should be performed manually 8 | When I tag it as @manual 9 | Then it should be reported as manual pending 10 | 11 | Scenario: A skipped manual scenario 12 | Meta: 13 | @tag expected-outcome:skip 14 | @manual 15 | @skip 16 | Given I want to indicate that a scenario should be performed manually 17 | And I also want it appearing in the skipped scenarios 18 | When I tag it as @manual and @skipped 19 | Then it should be reported as manual skipped 20 | 21 | 22 | Scenario: A manual scenario scenario with undefined steps 23 | Meta: 24 | @tag expected-outcome:pending 25 | @manual 26 | Given I want to indicate that a scenario should be performed manually 27 | When I tag it as @manual 28 | And the steps are undefined 29 | Then it should be reported as manual pending 30 | 31 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/skipped_pending_and_manual_scenarios/when_skipping_scenarios.story: -------------------------------------------------------------------------------- 1 | Marking scenarios as pending, skipped or ignored 2 | 3 | Scenario: scenario 1 4 | Meta: 5 | @skip 6 | When print '1' 7 | 8 | Scenario: scenario 2 9 | When print '2' -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/understanding_serenity_steps/overview.md: -------------------------------------------------------------------------------- 1 | ## Serenity steps 2 | 3 | Steps are important. -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/understanding_serenity_steps/when_using_step_libraries.story: -------------------------------------------------------------------------------- 1 | Scenario: Serenity automatically instantiates step library fields in step definition classes 2 | Meta: 3 | @tag expected-outcome:success 4 | Given I want to use a step library 5 | When I use a step library field annotated with @Steps 6 | Then Serenity should instantiate the field 7 | 8 | Scenario: Serenity instantiates different step libraries for each field by default 9 | Meta: 10 | @tag expected-outcome:success 11 | Given I want to use several step library fields of the same type 12 | When I use a step library fields to each of them 13 | Then Serenity should instantiate a different library for each field 14 | 15 | Scenario: Serenity creates new step library instances for each new scenario 16 | Meta: 17 | @tag expected-outcome:success 18 | Given I have a Serenity step library 19 | When I start a new scenario 20 | Then the step library should be reinitialised 21 | 22 | Scenario: You can share step library instances using @Steps(shared=true) 23 | Meta: 24 | @tag expected-outcome:success 25 | Given I have two Serenity step libraries 26 | When they are annotated with @Steps(shared=true) 27 | Then both should refer to the same instance 28 | -------------------------------------------------------------------------------- /src/smoketests/src/test/resources/stories/using_tables/when_using_tables.story: -------------------------------------------------------------------------------- 1 | Scenario: Serenity displays scenario outlines as tables 2 | Meta: 3 | @tag expected-outcome:success 4 | Given I have a calculator 5 | When I add 6 | Then the total should be 7 | Examples: 8 | | amount | total | 9 | | 1 | 1 | 10 | | 2 | 3 | 11 | | 3 | 6 | -------------------------------------------------------------------------------- /src/test/java/com/ClassWithOnePackage.java: -------------------------------------------------------------------------------- 1 | package com; 2 | 3 | public class ClassWithOnePackage { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorContainingSlowTests.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.webdriver.DriverConfiguration; 4 | 5 | public class ABehaviorContainingSlowTests extends SerenityStories { 6 | public ABehaviorContainingSlowTests(DriverConfiguration configuration) { 7 | super(configuration); 8 | findStoriesCalled("**/aSlowBehavior.story"); 9 | } 10 | 11 | public ABehaviorContainingSlowTests() { 12 | findStoriesCalled("**/aSlowBehavior.story"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithAFailingAssumption.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ABehaviorWithAFailingAssumption extends SerenityStory { 6 | public ABehaviorWithAFailingAssumption() { 7 | } 8 | 9 | public ABehaviorWithAFailingAssumption(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithATaggedPendingAndSkippedScenarios.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ABehaviorWithATaggedPendingAndSkippedScenarios extends SerenityStory { 6 | public ABehaviorWithATaggedPendingAndSkippedScenarios() { 7 | } 8 | 9 | public ABehaviorWithATaggedPendingAndSkippedScenarios(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithAnError.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ABehaviorWithAnError extends SerenityStory { 6 | 7 | public ABehaviorWithAnError() { 8 | } 9 | 10 | public ABehaviorWithAnError(EnvironmentVariables environmentVariables) { 11 | super(environmentVariables); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithCustomMetaTags.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ABehaviorWithCustomMetaTags extends SerenityStory { 6 | public ABehaviorWithCustomMetaTags() { 7 | } 8 | 9 | public ABehaviorWithCustomMetaTags(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithSeleniumPageObjects.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class ABehaviorWithSeleniumPageObjects extends SerenityStory { 4 | public ABehaviorWithSeleniumPageObjects() { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithSpringBeans.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class ABehaviorWithSpringBeans extends SerenityStory { 4 | public ABehaviorWithSpringBeans() { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ABehaviorWithTags.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ABehaviorWithTags extends SerenityStory { 6 | public ABehaviorWithTags() { 7 | } 8 | 9 | public ABehaviorWithTags(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AFailingBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class AFailingBehavior extends SerenityStory { 6 | 7 | public AFailingBehavior() {} 8 | 9 | public AFailingBehavior(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AFailingBehaviorWithSelenium.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class AFailingBehaviorWithSelenium extends SerenityStory { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AFailingDataDrivenBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class AFailingDataDrivenBehavior extends SerenityStory { 6 | 7 | public AFailingDataDrivenBehavior() { 8 | } 9 | 10 | public AFailingDataDrivenBehavior(EnvironmentVariables environmentVariables) { 11 | super(environmentVariables); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class APassingBehavior extends SerenityStory { 6 | public APassingBehavior() { 7 | } 8 | 9 | public APassingBehavior(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingBehaviorWithABeforeClause.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class APassingBehaviorWithABeforeClause extends SerenityStory { 6 | public APassingBehaviorWithABeforeClause() { 7 | } 8 | 9 | public APassingBehaviorWithABeforeClause(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingBehaviorWithSeveralScenarios.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class APassingBehaviorWithSeveralScenarios extends SerenityStory { 6 | public APassingBehaviorWithSeveralScenarios() { 7 | } 8 | 9 | public APassingBehaviorWithSeveralScenarios(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingBehaviorWithState.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class APassingBehaviorWithState extends SerenityStory { 4 | public APassingBehaviorWithState() { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingWebTestSample.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class APassingWebTestSample extends SerenityStories { 4 | 5 | public APassingWebTestSample() { 6 | runSerenity().withDriver("htmlunit") 7 | .withProperty("restart.browser.each.scenario").setTo(true); 8 | findStoriesCalled("aPassingBehaviorWithSelenium.story"); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingWebTestSampleWithASpecifiedBrowser.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.ThucydidesSystemProperty; 4 | 5 | public class APassingWebTestSampleWithASpecifiedBrowser extends SerenityStories { 6 | 7 | public APassingWebTestSampleWithASpecifiedBrowser() { 8 | findStoriesCalled("aPassingBehaviorWithSeleniumAndFirefox.story"); 9 | runSerenity().withDriver("phantomjs"); 10 | runSerenity().withProperty(ThucydidesSystemProperty.THUCYDIDES_USE_UNIQUE_BROWSER).setTo(true); 11 | } 12 | 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingWebTestSampleWithNestedSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class APassingWebTestSampleWithNestedSteps extends SerenityStories { 4 | 5 | public APassingWebTestSampleWithNestedSteps() { 6 | runSerenity().withDriver("firefox"); 7 | findStoriesCalled("APassingWebTestSampleWithNestedSteps.story"); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APassingWebTestSampleWithThucydidesPropertiesDefined.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.ThucydidesSystemProperty; 4 | import net.thucydides.core.webdriver.DriverConfiguration; 5 | 6 | import static org.jbehave.core.reporters.Format.HTML; 7 | import static org.jbehave.core.reporters.Format.TXT; 8 | import static org.jbehave.core.reporters.Format.XML; 9 | 10 | public class APassingWebTestSampleWithThucydidesPropertiesDefined extends SerenityStories { 11 | 12 | 13 | public APassingWebTestSampleWithThucydidesPropertiesDefined(DriverConfiguration systemConfiguration) { 14 | setSystemConfiguration(systemConfiguration); 15 | findStoriesCalled("aBehaviorWithSeleniumUsingADifferentBrowser.story"); 16 | useFormats(TXT, XML, HTML); 17 | runSerenity().withProperty(ThucydidesSystemProperty.DRIVER).setTo("htmlunit"); 18 | runSerenity().withProperty(ThucydidesSystemProperty.WEBDRIVER_BASE_URL).setTo("some-base-url"); 19 | runSerenity().withProperty(ThucydidesSystemProperty.THUCYDIDES_TIMEOUT).setTo(5); 20 | runSerenity().withProperty(ThucydidesSystemProperty.THUCYDIDES_USE_UNIQUE_BROWSER).setTo(true); 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/APendingDataDrivenBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class APendingDataDrivenBehavior extends SerenityStory { 6 | 7 | public APendingDataDrivenBehavior() { 8 | } 9 | 10 | public APendingDataDrivenBehavior(EnvironmentVariables environmentVariables) { 11 | super(environmentVariables); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASampleBehaviorForUatOnly.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.webdriver.DriverConfiguration; 4 | 5 | public class ASampleBehaviorForUatOnly extends SerenityStory { 6 | public ASampleBehaviorForUatOnly(DriverConfiguration configuration) { 7 | super(configuration); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASampleBehaviorWithSharedVariables.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.webdriver.DriverConfiguration; 4 | 5 | public class ASampleBehaviorWithSharedVariables extends SerenityStory { 6 | public ASampleBehaviorWithSharedVariables(DriverConfiguration configuration) { 7 | super(configuration); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASetOfBehaviorsContainingFailures.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class ASetOfBehaviorsContainingFailures extends SerenityStories { 4 | public ASetOfBehaviorsContainingFailures() { 5 | findStoriesCalled("**/a*Behavior.story"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASetOfBehaviorsContainingWebTestFailures.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class ASetOfBehaviorsContainingWebTestFailures extends SerenityStories { 4 | public ASetOfBehaviorsContainingWebTestFailures() { 5 | findStoriesCalled("**/*WithSelenium.story"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASetOfSampleBehaviorsContainingSlowTests.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.webdriver.DriverConfiguration; 4 | 5 | public class ASetOfSampleBehaviorsContainingSlowTests extends SerenityStories { 6 | public ASetOfSampleBehaviorsContainingSlowTests(DriverConfiguration configuration) { 7 | super(configuration); 8 | findStoriesCalled("**/a*SlowBehavior.story"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASetOfSeleniumTests.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class ASetOfSeleniumTests extends SerenityStories { 4 | public ASetOfSeleniumTests() { 5 | runSerenity().inASingleSession(); 6 | findStoriesCalled("**/*PassingBehaviorWithSeleniumAndSeveralScenarios.story"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/ASlowBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class ASlowBehavior extends SerenityStory { 6 | 7 | public ASlowBehavior() { 8 | } 9 | 10 | public ASlowBehavior(EnvironmentVariables environmentVariables) { 11 | super(environmentVariables); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AStoryInTheStoriesDirectory.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | 5 | public class AStoryInTheStoriesDirectory extends SerenityStory { 6 | public AStoryInTheStoriesDirectory() { 7 | } 8 | 9 | public AStoryInTheStoriesDirectory(EnvironmentVariables environmentVariables) { 10 | super(environmentVariables); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AStorySample.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | import net.thucydides.core.webdriver.DriverConfiguration; 5 | 6 | public class AStorySample extends SerenityStories { 7 | public AStorySample(String storyName, DriverConfiguration configuration, EnvironmentVariables environmentVariables) { 8 | this.setEnvironmentVariables(environmentVariables); 9 | setSystemConfiguration(configuration); 10 | findStoriesCalled(storyName); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AStorySampleSpecifyingTheDriver.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class AStorySampleSpecifyingTheDriver extends SerenityStories { 4 | public AStorySampleSpecifyingTheDriver(String storyName) { 5 | findStoriesCalled(storyName); 6 | } 7 | 8 | 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AbstractJBehaveStory.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.serenitybdd.jbehave.runners.SerenityReportingRunner; 4 | import net.thucydides.core.configuration.WebDriverConfiguration; 5 | import net.thucydides.core.model.TestOutcome; 6 | import net.thucydides.core.reports.TestOutcomeLoader; 7 | import net.thucydides.core.util.MockEnvironmentVariables; 8 | import net.thucydides.core.webdriver.DriverConfiguration; 9 | import org.junit.Before; 10 | import org.junit.Rule; 11 | import org.junit.rules.TemporaryFolder; 12 | import org.junit.runner.notification.Failure; 13 | import org.junit.runner.notification.RunNotifier; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class AbstractJBehaveStory { 21 | 22 | protected MockEnvironmentVariables environmentVariables; 23 | protected DriverConfiguration systemConfiguration; 24 | 25 | @Rule 26 | public TemporaryFolder temporaryFolder = new TemporaryFolder(); 27 | 28 | protected File outputDirectory; 29 | 30 | protected List raisedErrors = new ArrayList<>(); 31 | 32 | @Before 33 | public void prepareReporter() throws IOException { 34 | 35 | environmentVariables = new MockEnvironmentVariables(); 36 | 37 | outputDirectory = temporaryFolder.newFolder("output"); 38 | environmentVariables.setProperty("thucydides.outputDirectory", outputDirectory.getAbsolutePath()); 39 | environmentVariables.setProperty("webdriver.driver", "phantomjs"); 40 | systemConfiguration = new WebDriverConfiguration(environmentVariables); 41 | raisedErrors.clear(); 42 | } 43 | 44 | final class AlertingNotifier extends RunNotifier { 45 | 46 | private Throwable exceptionThrown; 47 | 48 | @Override 49 | public void fireTestFailure(Failure failure) { 50 | exceptionThrown = failure.getException(); 51 | super.fireTestFailure(failure); 52 | } 53 | 54 | public Throwable getExceptionThrown() { 55 | return exceptionThrown; 56 | } 57 | } 58 | 59 | protected void run(SerenityStories stories) { 60 | SerenityReportingRunner runner; 61 | 62 | AlertingNotifier notifier = new AlertingNotifier(); 63 | try { 64 | runner = new SerenityReportingRunner(stories.getClass(), stories); 65 | runner.getDescription(); 66 | runner.run(notifier); 67 | } catch(Throwable e) { 68 | e.printStackTrace(); 69 | // throw e; 70 | } finally { 71 | if (notifier.getExceptionThrown() != null) { 72 | raisedErrors.add(notifier.getExceptionThrown()); 73 | } 74 | } 75 | } 76 | 77 | protected List loadTestOutcomes() { 78 | TestOutcomeLoader loader = new TestOutcomeLoader(); 79 | return loader.loadFrom(outputDirectory); 80 | } 81 | 82 | protected SerenityStories newStory(String storyPattern) { 83 | return new AStorySample(storyPattern, systemConfiguration, environmentVariables); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AllBehaviors.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class AllBehaviors extends SerenityStories { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/AnotherPassingBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class AnotherPassingBehavior extends SerenityStory { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/BehaviorWithEmbeddedTables.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | /** 4 | * Created by john on 30/05/2014. 5 | */ 6 | public class BehaviorWithEmbeddedTables extends SerenityStory { 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/BehaviorsForUatAndTestEnvironments.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.webdriver.Configuration; 4 | 5 | public class BehaviorsForUatAndTestEnvironments extends SerenityStories { 6 | public BehaviorsForUatAndTestEnvironments() { 7 | super(); 8 | } 9 | 10 | public BehaviorsForUatAndTestEnvironments(Configuration configuration) { 11 | // super(configuration); 12 | findStoriesCalled("behavior_uat_tagged.story"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/DataDrivenBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class DataDrivenBehavior extends SerenityStory { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/DataDrivenBehaviorWithSelenium.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class DataDrivenBehaviorWithSelenium extends SerenityStory { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/FixtureMethods.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import org.jbehave.core.annotations.BeforeScenario; 4 | import org.jbehave.core.annotations.BeforeStory; 5 | 6 | public class FixtureMethods { 7 | 8 | public static int beforeStoryCalledCount = 0; 9 | public static int beforeScenarioCalledCount = 0; 10 | 11 | @BeforeStory 12 | public void beforeStory() { 13 | beforeStoryCalledCount++; 14 | } 15 | 16 | @BeforeScenario 17 | public void beforeScenario() { 18 | beforeScenarioCalledCount++; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/TestOutcomeFinder.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | 5 | import java.util.List; 6 | 7 | public class TestOutcomeFinder { 8 | 9 | private final String name; 10 | 11 | public TestOutcomeFinder(String name) { 12 | this.name = name; 13 | } 14 | 15 | public static TestOutcomeFinder theScenarioCalled(String name) { 16 | return new TestOutcomeFinder(name); 17 | } 18 | 19 | public TestOutcome in(List testOutcomes) { 20 | for(TestOutcome testOutcome : testOutcomes) { 21 | if (testOutcome.getName().equalsIgnoreCase(name)) { 22 | return testOutcome; 23 | } 24 | } 25 | return null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenConfiguringJBehaveStorySteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.is; 11 | 12 | public class WhenConfiguringJBehaveStorySteps extends AbstractJBehaveStory { 13 | 14 | @Test 15 | public void should_find_stories_in_a_jar_file() { 16 | 17 | // Given 18 | SerenityStories story = newStory("a_top_level_story.story"); 19 | 20 | // When 21 | run(story); 22 | 23 | // Then 24 | List outcomes = loadTestOutcomes(); 25 | assertThat(outcomes.size(), is(1)); 26 | } 27 | 28 | @Test 29 | public void should_find_stories_in_a_subdirectory_in_the_jar_file() { 30 | 31 | // Given 32 | SerenityStories story = newStory("annotatedstories/a_story_in_the_stories_directory.story"); 33 | 34 | // When 35 | run(story); 36 | 37 | // Then 38 | List outcomes = loadTestOutcomes(); 39 | assertThat(outcomes.size(), is(1)); 40 | } 41 | 42 | @Test 43 | public void spring_autowiring_in_jbehave_steps_should_be_supported() { 44 | 45 | // Given 46 | SerenityStories passingStory = newStory("aBehaviorWithSpringBeans.story"); 47 | 48 | // When 49 | run(passingStory); 50 | 51 | // Then 52 | List outcomes = loadTestOutcomes(); 53 | assertThat(outcomes.size(), is(1)); 54 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 55 | } 56 | 57 | @Test 58 | public void should_instantiate_page_objects_in_jbehave_steps() { 59 | 60 | // Given 61 | SerenityStories passingStory = newStory("aBehaviorWithSeleniumPageObjects.story"); 62 | 63 | // When 64 | run(passingStory); 65 | 66 | // Then 67 | List outcomes = loadTestOutcomes(); 68 | assertThat(outcomes.size(), is(1)); 69 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenDeterminingTheRootPathOfAPackage.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import com.ClassWithOnePackage; 4 | import org.junit.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | public class WhenDeterminingTheRootPathOfAPackage { 9 | 10 | static class SomeClass {} 11 | 12 | @Test 13 | public void should_find_the_parent_package_of_a_class() { 14 | Package somePackage = SomeClass.class.getPackage(); 15 | 16 | assertThat(RootPackage.forPackage(somePackage)).isEqualTo("net.serenitybdd"); 17 | } 18 | 19 | @Test 20 | public void should_find_the_parent_package_of_a_class_when_there_is_only_one_package() { 21 | Package somePackage = ClassWithOnePackage.class.getPackage(); 22 | 23 | assertThat(RootPackage.forPackage(somePackage)).isEqualTo("com"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenFindingStoriesOnTheClasspath.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.util.EnvironmentVariables; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.mockito.Mock; 7 | import org.mockito.MockitoAnnotations; 8 | 9 | import java.util.Set; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class WhenFindingStoriesOnTheClasspath { 14 | 15 | @Mock 16 | EnvironmentVariables environmentVariables; 17 | 18 | @Before 19 | public void setup() { 20 | MockitoAnnotations.initMocks(this); 21 | } 22 | 23 | @Test 24 | public void should_find_stories_in_the_specfied_directory() { 25 | StoryPathFinder finder = new StoryPathFinder(environmentVariables, "stories/samples/*.story"); 26 | Set storyElements = finder.findAllElements(); 27 | assertThat(storyElements).containsOnly("**/stories/samples/*.story"); 28 | } 29 | 30 | @Test 31 | public void should_find_specific_stories_on_the_classpath() { 32 | StoryPathFinder finder = new StoryPathFinder(environmentVariables, "stories/samples/SomeBehavior.story"); 33 | Set storyElements = finder.findAllElements(); 34 | assertThat(storyElements).containsOnly("stories/samples/SomeBehavior.story"); 35 | } 36 | 37 | @Test 38 | public void should_add_wildcard_to_stories_not_found_on_the_classpath() { 39 | StoryPathFinder finder = new StoryPathFinder(environmentVariables, "samples/MoreBehavior.story"); 40 | Set storyElements = finder.findAllElements(); 41 | assertThat(storyElements).contains("**/samples/MoreBehavior.story"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenHandlingJodaStepParameters.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class WhenHandlingJodaStepParameters extends SerenityStory { 4 | 5 | public WhenHandlingJodaStepParameters() { 6 | this.findStoriesCalled("HandlingJodaStepParameters.story"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningDataDrivenJBehaveStories.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.DataTable; 4 | import net.thucydides.core.model.TestOutcome; 5 | import net.thucydides.core.model.TestResult; 6 | import net.thucydides.core.model.TestStep; 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | import static org.hamcrest.MatcherAssert.assertThat; 12 | import static org.hamcrest.Matchers.containsString; 13 | import static org.hamcrest.Matchers.is; 14 | 15 | public class WhenRunningDataDrivenJBehaveStories extends AbstractJBehaveStory { 16 | 17 | @Test 18 | public void a_data_driven_test_should_produce_a_set_of_steps_per_line_of_data() { 19 | 20 | // Given 21 | SerenityStories story = newStory("aDataDrivenBehavior.story"); 22 | 23 | // When 24 | run(story); 25 | 26 | // Then 27 | List outcomes = loadTestOutcomes(); 28 | assertThat(outcomes.size(), is(2)); 29 | assertThat(outcomes.get(0).getTestSteps().size(), is(3)); 30 | assertThat(outcomes.get(0).getTestSteps().get(0).getChildren().size(), is(3)); 31 | } 32 | 33 | @Test 34 | public void a_data_driven_test_should_produce_a_steps_with_the_data_values_in_the_titles() { 35 | 36 | // Given 37 | SerenityStories story = newStory("aDataDrivenBehavior.story"); 38 | 39 | // When 40 | run(story); 41 | 42 | // Then 43 | List outcomes = loadTestOutcomes(); 44 | List steps = outcomes.get(0).getTestSteps(); 45 | assertThat(steps.get(0).getDescription(), containsString("10")); 46 | assertThat(steps.get(1).getDescription(), containsString("11")); 47 | assertThat(steps.get(2).getDescription(), containsString("12")); 48 | } 49 | 50 | @Test 51 | public void a_data_driven_test_should_produce_a_successful_result_if_all_rows_are_successful() { 52 | 53 | // Given 54 | SerenityStories story = newStory("aDataDrivenBehavior.story"); 55 | // When 56 | run(story); 57 | // Then 58 | List outcomes = loadTestOutcomes(); 59 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 60 | assertThat(outcomes.get(1).getResult(), is(TestResult.SUCCESS)); 61 | } 62 | 63 | 64 | @Test 65 | public void a_failing_step_in_a_data_driven_test_should_not_affect_subsequent_steps() { 66 | 67 | // Given 68 | SerenityStories story = newStory("aFailingDataDrivenBehavior.story"); 69 | 70 | // When 71 | run(story); 72 | 73 | // Then 74 | List outcomes = loadTestOutcomes(); 75 | 76 | List steps = outcomes.get(0).getTestSteps(); 77 | assertThat(steps.get(0).getResult(), is(TestResult.SUCCESS)); 78 | assertThat(steps.get(1).getResult(), is(TestResult.FAILURE)); 79 | assertThat(steps.get(2).getResult(), is(TestResult.SUCCESS)); 80 | 81 | assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE)); 82 | } 83 | 84 | @Test 85 | public void a_failing_step_in_a_data_driven_test_should_be_recorded_in_the_examples_table() { 86 | 87 | // Given 88 | SerenityStories story = newStory("aFailingDataDrivenBehavior.story"); 89 | 90 | // When 91 | run(story); 92 | 93 | // Then 94 | List outcomes = loadTestOutcomes(); 95 | 96 | 97 | DataTable table = outcomes.get(0).getDataTable(); 98 | assertThat(table.getRows().get(0).getResult(), is(TestResult.SUCCESS)); 99 | assertThat(table.getRows().get(1).getResult(), is(TestResult.FAILURE)); 100 | assertThat(table.getRows().get(2).getResult(), is(TestResult.SUCCESS)); 101 | } 102 | 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStories.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import org.junit.Test; 5 | 6 | import java.util.List; 7 | 8 | import static net.thucydides.core.steps.TestSourceType.TEST_SOURCE_JBEHAVE; 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.is; 11 | 12 | public class WhenRunningJBehaveStories extends AbstractJBehaveStory { 13 | 14 | @Test 15 | public void for_jbehave_stories_the_test_source_is_saved_in_the_outcome() { 16 | 17 | // Given 18 | SerenityStories storyWithTitle = newStory("aBehaviorWithATitle.story"); 19 | 20 | // When 21 | run(storyWithTitle); 22 | 23 | // Then 24 | List outcomes = loadTestOutcomes(); 25 | assertThat(outcomes.size(),is(1)); 26 | assertThat(outcomes.get(0).getTestSource(),is(TEST_SOURCE_JBEHAVE.getValue())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesManualTags.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import net.thucydides.core.model.TestTag; 6 | 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | import static net.thucydides.core.reports.matchers.TestOutcomeMatchers.havingTag; 12 | import static org.hamcrest.MatcherAssert.assertThat; 13 | import static org.hamcrest.Matchers.*; 14 | 15 | public class WhenRunningJBehaveStoriesManualTags extends AbstractJBehaveStory { 16 | 17 | @Test 18 | public void a_test_should_be_marked_as_manual_when_manual_tag_provided() { 19 | 20 | // Given 21 | SerenityStories story = newStory("aBehaviorWithManualScenario.story"); 22 | 23 | // When 24 | run(story); 25 | 26 | // Then 27 | List outcomes = loadTestOutcomes(); 28 | assertThat(outcomes.get(0), havingTag(TestTag.withName("Manual").andType("External Tests"))); 29 | assertThat(outcomes.get(0).isManual(), equalTo(true)); 30 | assertThat(outcomes.get(0).getResult(), is(TestResult.PENDING)); 31 | } 32 | 33 | @Test 34 | public void steps_should_be_marked_manual_if_tag_provided_at_story_level() { 35 | 36 | // Given 37 | SerenityStories story = newStory("aBehaviorWithManualStory.story"); 38 | 39 | // When 40 | run(story); 41 | 42 | // Then 43 | List outcomes = loadTestOutcomes(); 44 | assertThat(outcomes.get(0), havingTag(TestTag.withName("Manual").andType("External Tests"))); 45 | assertThat(outcomes.get(0).isManual(), equalTo(true)); 46 | assertThat(outcomes.get(0).getResult(), is(TestResult.PENDING)); 47 | assertThat(outcomes.get(1), havingTag(TestTag.withName("Manual").andType("External Tests"))); 48 | assertThat(outcomes.get(1).isManual(), equalTo(true)); 49 | assertThat(outcomes.get(1).getResult(), is(TestResult.PENDING)); 50 | 51 | } 52 | 53 | @Test 54 | public void steps_should_be_marked_skipped_and_manual_if_annotated_skipped() { 55 | 56 | // Given 57 | SerenityStories story = newStory("aBehaviorWithSkippedManualScenario.story"); 58 | 59 | // When 60 | run(story); 61 | 62 | // Then 63 | List outcomes = loadTestOutcomes(); 64 | assertThat(outcomes.get(0), havingTag(TestTag.withName("Manual").andType("External Tests"))); 65 | assertThat(outcomes.get(0).isManual(), equalTo(true)); 66 | assertThat(outcomes.get(0).getResult(), is(TestResult.SKIPPED)); 67 | 68 | } 69 | 70 | @Test 71 | public void scenario_manual_tags_should_not_be_shared_between_scenarios() { 72 | 73 | // Given 74 | SerenityStories story = newStory("aBehaviorWithManualAndNotManualScenario.story"); 75 | 76 | // When 77 | run(story); 78 | 79 | // Then 80 | List outcomes = loadTestOutcomes(); 81 | assertThat(outcomes.get(0), havingTag(TestTag.withName("Manual").andType("External Tests"))); 82 | assertThat(outcomes.get(0).isManual(), equalTo(true)); 83 | assertThat(outcomes.get(0).getResult(), is(TestResult.PENDING)); 84 | 85 | assertThat(outcomes.get(1).getResult(), is(TestResult.SUCCESS)); 86 | assertThat(outcomes.get(1).isManual(), equalTo(false)); 87 | assertThat(outcomes.get(1).getTags().size(), is(1)); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesWithError.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import net.thucydides.core.util.EnvironmentVariables; 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | public class WhenRunningJBehaveStoriesWithError extends AbstractJBehaveStory { 14 | 15 | final static class AStorySample extends SerenityStories { 16 | 17 | public AStorySample(EnvironmentVariables environmentVariables) { 18 | super(environmentVariables); 19 | } 20 | 21 | protected AStorySample(String storyName) { 22 | findStoriesCalled(storyName); 23 | } 24 | } 25 | 26 | @Test 27 | public void stories_with_errors_should_be_reported_as_failing() { 28 | 29 | // Given 30 | SerenityStories failingStory = newStory("aBehaviorThrowingAnException.story"); 31 | 32 | // When 33 | run(failingStory); 34 | 35 | // Then 36 | List outcomes = loadTestOutcomes(); 37 | assertThat(outcomes.size(), is(1)); 38 | assertThat(outcomes.get(0).getResult(), is(TestResult.ERROR)); 39 | } 40 | 41 | @Test 42 | public void stories_with_undefined_steps_should_be_reported_as_pending() { 43 | 44 | // Given 45 | SerenityStories failingStory = newStory("aBehaviorWithAnUndefinedStep.story"); 46 | 47 | // When 48 | run(failingStory); 49 | 50 | // Then 51 | List outcomes = loadTestOutcomes(); 52 | assertThat(outcomes.size(), is(1)); 53 | assertThat(outcomes.get(0).getResult(), is(TestResult.PENDING)); 54 | } 55 | 56 | private void runStories(SerenityStories stories) { 57 | run(stories); 58 | } 59 | 60 | @Test 61 | public void errored_stories_should_be_reported_as_having_an_error() { 62 | 63 | // Given 64 | SerenityStories failingStory = newStory("aBehaviorWithAnError.story"); 65 | 66 | // When 67 | run(failingStory); 68 | 69 | // Then 70 | List outcomes = loadTestOutcomes(); 71 | assertThat(outcomes.size(), is(1)); 72 | assertThat(outcomes.get(0).getResult(), is(TestResult.ERROR)); 73 | } 74 | 75 | @Test 76 | public void a_test_running_a_failing_story_should_fail() { 77 | SerenityStories stories = newStory("aFailingBehavior.story"); 78 | stories.setSystemConfiguration(systemConfiguration); 79 | runStories(stories); 80 | 81 | List outcomes = loadTestOutcomes(); 82 | assertThat(outcomes.size(), is(1)); 83 | assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE)); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesWithFailure.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import net.thucydides.core.util.EnvironmentVariables; 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static net.thucydides.core.model.TestResult.FAILURE; 11 | import static net.thucydides.core.model.TestResult.SUCCESS; 12 | import static org.hamcrest.MatcherAssert.assertThat; 13 | import static org.hamcrest.Matchers.is; 14 | 15 | public class WhenRunningJBehaveStoriesWithFailure extends AbstractJBehaveStory { 16 | 17 | final static class AStorySample extends SerenityStories { 18 | 19 | public AStorySample(EnvironmentVariables environmentVariables) { 20 | super(environmentVariables); 21 | } 22 | 23 | protected AStorySample(String storyName) { 24 | findStoriesCalled(storyName); 25 | } 26 | } 27 | 28 | @Test 29 | public void failing_stories_should_be_reported_as_failing() { 30 | 31 | // Given 32 | SerenityStories failingStory = newStory("aFailingBehavior.story"); 33 | 34 | try { 35 | // When 36 | run(failingStory); 37 | } catch(RuntimeException e) {} 38 | // Then 39 | List outcomes = loadTestOutcomes(); 40 | assertThat(outcomes.size(), is(1)); 41 | assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE)); 42 | } 43 | 44 | @Test 45 | public void should_not_reset_steps_for_each_scenario_if_configured() { 46 | 47 | // environmentVariables.setProperty("reset.steps.each.scenario", "false"); 48 | environmentVariables.setProperty("reset.steps.each.scenario", "false"); 49 | // Given 50 | SerenityStories passingStory = newStory("aPassingBehaviorWithSeveralScenarios.story"); 51 | 52 | try { 53 | // When 54 | run(passingStory); 55 | } catch(RuntimeException e) {} 56 | 57 | // Then 58 | List outcomes = loadTestOutcomes(); 59 | assertThat(outcomes.size(), is(2)); 60 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 61 | assertThat(outcomes.get(1).getResult(), is(TestResult.FAILURE)); 62 | } 63 | 64 | @Test 65 | public void variables_are_reset_between_steps_by_default() { 66 | 67 | // Given 68 | SerenityStories sharedVariablesStory = newStory("aBehaviorWithSharedVariables.story"); 69 | 70 | try { 71 | // When 72 | run(sharedVariablesStory); 73 | } catch(RuntimeException e) {} 74 | 75 | // Then 76 | List outcomes = loadTestOutcomes(); 77 | assertThat(outcomes.size(), is(2)); 78 | assertThat(outcomes.get(0).getResult(), is(SUCCESS)); 79 | assertThat(outcomes.get(1).getResult(), is(FAILURE)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesWithIgnored.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import net.thucydides.core.util.EnvironmentVariables; 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static net.thucydides.core.model.TestResult.IGNORED; 11 | import static net.thucydides.core.model.TestResult.SUCCESS; 12 | import static org.hamcrest.MatcherAssert.assertThat; 13 | import static org.hamcrest.Matchers.is; 14 | 15 | public class WhenRunningJBehaveStoriesWithIgnored extends AbstractJBehaveStory { 16 | 17 | final static class AStorySample extends SerenityStories { 18 | 19 | public AStorySample(EnvironmentVariables environmentVariables) { 20 | super(environmentVariables); 21 | } 22 | 23 | protected AStorySample(String storyName) { 24 | findStoriesCalled(storyName); 25 | } 26 | } 27 | 28 | private void runStories(SerenityStories stories) { 29 | run(stories); 30 | } 31 | 32 | @Test 33 | public void a_test_running_a_failing_story_should_not_fail_if_ignore_failures_in_stories_is_set_to_true() { 34 | 35 | systemConfiguration.getEnvironmentVariables().setProperty("ignore.failures.in.stories", "true"); 36 | SerenityStories stories = new AFailingBehavior(); 37 | stories.setSystemConfiguration(systemConfiguration); 38 | runStories(stories); 39 | } 40 | 41 | @Test 42 | public void should_mark_scenarios_with_failing_assumption_as_skipped() { 43 | 44 | // Given 45 | SerenityStories stories = new ABehaviorWithAFailingAssumption(environmentVariables); 46 | 47 | // When 48 | run(stories); 49 | 50 | // Then 51 | List outcomes = loadTestOutcomes(); 52 | assertThat(outcomes.size(), is(2)); 53 | assertThat(outcomes.get(0).getResult(), is(IGNORED)); 54 | assertThat(outcomes.get(1).getResult(), is(SUCCESS)); 55 | } 56 | 57 | @Test 58 | public void stories_with_failing_assumptions_should_be_ignored() { 59 | 60 | // Given 61 | SerenityStories pendingStory = newStory("aBehaviorWithAFailingAssumption.story"); 62 | 63 | // When 64 | run(pendingStory); 65 | 66 | // Then 67 | List outcomes = loadTestOutcomes(); 68 | assertThat(outcomes.get(0).getResult(), is(TestResult.IGNORED)); 69 | assertThat(outcomes.get(1).getResult(), is(TestResult.SUCCESS)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesWithScreenshots.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.greaterThan; 11 | 12 | public class WhenRunningJBehaveStoriesWithScreenshots extends AbstractJBehaveStory { 13 | 14 | final static class AStorySample extends SerenityStories { 15 | public AStorySample() { 16 | super(); 17 | } 18 | 19 | protected AStorySample(String storyName) { 20 | findStoriesCalled(storyName); 21 | } 22 | } 23 | 24 | @Test 25 | public void web_tests_should_take_screenshots() { 26 | // Given 27 | SerenityStories story = newStory("aPassingBehaviorWithSeleniumAndFirefox.story"); 28 | 29 | // When 30 | run(story); 31 | 32 | // Then 33 | List outcomes = loadTestOutcomes(); 34 | assertThat(outcomes.get(0).getScreenshots().size(), greaterThan(0)); 35 | } 36 | 37 | @Test 38 | public void web_tests_should_take_screenshots_with_multiple_scenarios() { 39 | 40 | // Given 41 | SerenityStories story = newStory("aPassingBehaviorWithSeleniumAndSeveralScenarios.story"); 42 | story.setEnvironmentVariables(environmentVariables); 43 | 44 | // When 45 | run(story); 46 | 47 | // Then 48 | List outcomes = loadTestOutcomes(); 49 | assertThat(outcomes.get(0).getScreenshots().size(), greaterThan(0)); 50 | } 51 | 52 | 53 | @Test 54 | public void web_tests_should_take_screenshots_for_multiple_tests() { 55 | 56 | // Given 57 | SerenityStories story = newStory("*PassingBehaviorWithSeleniumAndSeveralScenarios.story"); 58 | 59 | // When 60 | run(story); 61 | 62 | // Then 63 | List outcomes = loadTestOutcomes(); 64 | assertThat(outcomes.get(0).getScreenshots().size(), greaterThan(0)); 65 | assertThat(outcomes.get(1).getScreenshots().size(), greaterThan(0)); 66 | assertThat(outcomes.get(2).getScreenshots().size(), greaterThan(0)); 67 | assertThat(outcomes.get(3).getScreenshots().size(), greaterThan(0)); 68 | } 69 | 70 | @Test 71 | public void web_tests_should_take_screenshots_with_nested_step_libraries() { 72 | 73 | // Given 74 | SerenityStories story = newStory("**/aPassingWebTestSampleWithNestedSteps.story"); 75 | story.setEnvironmentVariables(environmentVariables); 76 | 77 | // When 78 | run(story); 79 | 80 | // Then 81 | List outcomes = loadTestOutcomes(); 82 | assertThat(outcomes.get(0).getScreenshots().size(), greaterThan(0)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStoriesWithTitle.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestTag; 5 | 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | public class WhenRunningJBehaveStoriesWithTitle extends AbstractJBehaveStory { 14 | 15 | @Test 16 | public void for_stories_with_title_use_the_title_as_tag_name() { 17 | 18 | // Given 19 | SerenityStories storyWithTitle = newStory("aBehaviorWithATitle.story"); 20 | 21 | // When 22 | run(storyWithTitle); 23 | 24 | // Then 25 | List outcomes = loadTestOutcomes(); 26 | assertThat(outcomes.size(),is(1)); 27 | assertThat(outcomes.get(0).getTags().size(),is(1)); 28 | TestTag[] testTags = outcomes.get(0).getTags().toArray(new TestTag[0]); 29 | assertThat(testTags[0].getName(),is("This is the story title")); 30 | assertThat(testTags[0].getType(),is("story")); 31 | } 32 | 33 | @Test 34 | public void for_stories_with_no_title_use_the_story_file_name_as_tag_name() { 35 | 36 | // Given 37 | SerenityStories storyWithTitle = newStory("aBehaviorWithNoTitle.story"); 38 | 39 | // When 40 | run(storyWithTitle); 41 | 42 | // Then 43 | List outcomes = loadTestOutcomes(); 44 | assertThat(outcomes.size(),is(1)); 45 | assertThat(outcomes.get(0).getTags().size(),is(1)); 46 | TestTag[] testTags = outcomes.get(0).getTags().toArray(new TestTag[0]); 47 | assertThat(testTags[0].getName(),is("A Behavior With No Title")); 48 | assertThat(testTags[0].getType(),is("story")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningWebJBehaveStories.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | public class WhenRunningWebJBehaveStories extends AbstractJBehaveStory { 14 | 15 | final static class AStorySample extends SerenityStories { 16 | public AStorySample() { 17 | super(); 18 | } 19 | 20 | protected AStorySample(String storyName) { 21 | findStoriesCalled(storyName); 22 | } 23 | } 24 | 25 | @Test 26 | public void a_simple_web_test_should_run_correctly() { 27 | 28 | // Given 29 | SerenityStories story = newStory("aPassingBehaviorWithSelenium.story"); 30 | 31 | // When 32 | run(story); 33 | 34 | // Then 35 | List outcomes = loadTestOutcomes(); 36 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 37 | } 38 | 39 | @Test(expected = Throwable.class) 40 | public void a_failing_story_should_fail_in_junit() { 41 | 42 | SerenityStories story = newStory("aFailingBehaviorWithSelenium.story"); 43 | 44 | story.run(); 45 | 46 | } 47 | 48 | @Test 49 | public void should_be_able_to_set_thucydides_properties_in_the_base_test() { 50 | 51 | // Given 52 | SerenityStories story = new APassingWebTestSampleWithThucydidesPropertiesDefined(systemConfiguration); 53 | story.setEnvironmentVariables(environmentVariables); 54 | 55 | // When 56 | run(story); 57 | 58 | // Then 59 | 60 | assertThat(story.getSystemConfiguration().getBaseUrl(), is("some-base-url")); 61 | assertThat(story.getSystemConfiguration().getElementTimeout(), is(5)); 62 | assertThat(story.getSystemConfiguration().shouldUseAUniqueBrowser(), is(true)); 63 | } 64 | 65 | @Test(expected = Throwable.class) 66 | public void stories_with_errors_run_in_junit_should_fail() { 67 | 68 | // Given 69 | SerenityStories failingStory = newStory("aFailingBehaviorWithSelenium.story"); 70 | 71 | // When 72 | failingStory.run(); 73 | 74 | assert !raisedErrors.isEmpty(); 75 | } 76 | 77 | @Test 78 | public void stories_with_errors_in_one_scenario_should_still_run_subsequent_scenarios() { 79 | 80 | //environmentVariables.setProperty("restart.browser.each.scenario","true"); 81 | 82 | // Given 83 | SerenityStories story = newStory("failingAndPassingBehaviorsWithSelenium.story"); 84 | 85 | // When 86 | run(story); 87 | 88 | // Then 89 | List outcomes = loadTestOutcomes(); 90 | assertThat(outcomes.size(), is(2)); 91 | assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE)); 92 | assertThat(outcomes.get(1).getResult(), is(TestResult.SUCCESS)); 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningWebJBehaveStoriesUsingAdvancedBrowserManagement.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | import net.thucydides.core.util.EnvironmentVariables; 6 | import net.thucydides.core.util.MockEnvironmentVariables; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.util.List; 11 | 12 | import static org.hamcrest.MatcherAssert.assertThat; 13 | import static org.hamcrest.Matchers.is; 14 | 15 | public class WhenRunningWebJBehaveStoriesUsingAdvancedBrowserManagement extends AbstractJBehaveStory { 16 | 17 | final static class AStorySample extends SerenityStories { 18 | public AStorySample() { 19 | super(); 20 | } 21 | 22 | protected AStorySample(String storyName) { 23 | findStoriesCalled(storyName); 24 | } 25 | } 26 | 27 | @Before 28 | public void reset_driver() { 29 | environmentVariables.setProperty("webdriver.driver", "phantomjs"); 30 | } 31 | 32 | @Test 33 | public void a_test_should_use_a_different_browser_if_requested() { 34 | 35 | // Given 36 | EnvironmentVariables environmentVariables = new MockEnvironmentVariables(); 37 | SerenityStories story = newStory("aBehaviorWithSeleniumUsingADifferentBrowser.story"); 38 | 39 | // When 40 | run(story); 41 | 42 | // Then 43 | List outcomes = loadTestOutcomes(); 44 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 45 | } 46 | 47 | @Test 48 | public void should_be_able_to_specify_the_browser_in_the_base_test() { 49 | 50 | // Given 51 | SerenityStories story = new APassingWebTestSampleWithASpecifiedBrowser(); 52 | story.setEnvironmentVariables(environmentVariables); 53 | 54 | System.out.println("Output dir = " + outputDirectory.getAbsolutePath()); 55 | // When 56 | run(story); 57 | 58 | // Then 59 | System.out.println("Loading from output dir = " + outputDirectory.getAbsolutePath()); 60 | List outcomes = loadTestOutcomes(); 61 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningWebJBehaveStoriesUsingDataDriven.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestStep; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | public class WhenRunningWebJBehaveStoriesUsingDataDriven extends AbstractJBehaveStory { 14 | 15 | final static class AStorySample extends SerenityStories { 16 | public AStorySample() { 17 | super(); 18 | } 19 | 20 | protected AStorySample(String storyName) { 21 | findStoriesCalled(storyName); 22 | } 23 | } 24 | 25 | @Before 26 | public void reset_driver() { 27 | environmentVariables.setProperty("webdriver.driver", "phantomjs"); 28 | } 29 | 30 | @Test 31 | public void data_driven_steps_should_appear_as_nested_steps() { 32 | 33 | // Given 34 | SerenityStories story = newStory("dataDrivenBehavior.story"); 35 | 36 | // When 37 | run(story); 38 | 39 | // Then 40 | List allOutcomes = loadTestOutcomes(); 41 | assertThat(allOutcomes.size(), is(1)); 42 | 43 | List topLevelSteps = allOutcomes.get(0).getTestSteps(); 44 | assertThat(topLevelSteps.size(), is(3)); 45 | 46 | List nestedDataDrivenSteps = topLevelSteps.get(2).getChildren().get(0).getChildren(); 47 | assertThat(nestedDataDrivenSteps.size(), is(3)); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WhenRunningWebJBehaveStoriesUsingPageObjects.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.thucydides.core.model.TestOutcome; 4 | import net.thucydides.core.model.TestResult; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | import static org.hamcrest.MatcherAssert.assertThat; 12 | import static org.hamcrest.Matchers.is; 13 | 14 | public class WhenRunningWebJBehaveStoriesUsingPageObjects extends AbstractJBehaveStory { 15 | 16 | final static class AStorySample extends SerenityStories { 17 | public AStorySample() { 18 | super(); 19 | } 20 | 21 | protected AStorySample(String storyName) { 22 | findStoriesCalled(storyName); 23 | } 24 | } 25 | 26 | @Before 27 | public void reset_driver() { 28 | environmentVariables.setProperty("webdriver.driver", "phantomjs"); 29 | } 30 | 31 | 32 | @Test 33 | public void a_jbehave_step_library_can_use_page_objects_directly() { 34 | 35 | // Given 36 | SerenityStories story = newStory("aBehaviorWithSeleniumPageObjects.story"); 37 | 38 | // When 39 | run(story); 40 | 41 | // Then 42 | List outcomes = loadTestOutcomes(); 43 | assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/WithAnAnnotatedMetafilter.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | import net.serenitybdd.jbehave.annotations.Metafilter; 4 | 5 | @Metafilter("+environment uat") 6 | public class WithAnAnnotatedMetafilter extends SerenityStories { 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/YetAnotherPassingBehavior.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave; 2 | 3 | public class YetAnotherPassingBehavior extends SerenityStory { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/converters/WhenConvertingJodaDateTimes.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.converters; 2 | 3 | import org.joda.time.DateTime; 4 | import org.joda.time.LocalTime; 5 | import org.joda.time.YearMonth; 6 | import org.junit.Test; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | public class WhenConvertingJodaDateTimes { 11 | 12 | @Test 13 | public void should_convert_time_string_to_LocalTimes() { 14 | TimeConverter converter = new TimeConverter(); 15 | LocalTime convertedTime = converter.convertValue("18:12", LocalTime.class); 16 | 17 | assertThat(convertedTime.getHourOfDay()).isEqualTo(18); 18 | assertThat(convertedTime.getMinuteOfHour()).isEqualTo(12); 19 | } 20 | 21 | @Test 22 | public void should_convert_date_string_to_LocalTimes() { 23 | DateTimeConverter converter = new DateTimeConverter(); 24 | DateTime convertedTime = converter.convertValue("10/04/1942", LocalTime.class); 25 | 26 | assertThat(convertedTime.getDayOfMonth()).isEqualTo(10); 27 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(4); 28 | assertThat(convertedTime.getYear()).isEqualTo(1942); 29 | } 30 | 31 | @Test 32 | public void should_convert_date_string_with_dashes_to_LocalTimes() { 33 | DateTimeConverter converter = new DateTimeConverter(); 34 | DateTime convertedTime = converter.convertValue("10-04-1942", LocalTime.class); 35 | 36 | assertThat(convertedTime.getDayOfMonth()).isEqualTo(10); 37 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(4); 38 | assertThat(convertedTime.getYear()).isEqualTo(1942); 39 | } 40 | 41 | @Test 42 | public void should_detect_iso_date_format() { 43 | DateTimeConverter converter = new DateTimeConverter(); 44 | DateTime convertedTime = converter.convertValue("1942-04-10", LocalTime.class); 45 | 46 | assertThat(convertedTime.getDayOfMonth()).isEqualTo(10); 47 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(4); 48 | assertThat(convertedTime.getYear()).isEqualTo(1942); 49 | } 50 | 51 | @Test 52 | public void should_accept_YearMonth_values() { 53 | YearMonthConverter converter = new YearMonthConverter(); 54 | assertThat(converter.accept(YearMonth.class)).isTrue(); 55 | } 56 | 57 | @Test 58 | public void should_not_accept_non_YearMonth_value() { 59 | YearMonthConverter converter = new YearMonthConverter(); 60 | assertThat(converter.accept(DateTime.class)).isFalse(); 61 | } 62 | 63 | @Test 64 | public void should_detect_YearMonth_format() { 65 | YearMonthConverter converter = new YearMonthConverter(); 66 | YearMonth convertedTime = converter.convertValue("10-1942", YearMonth.class); 67 | 68 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(10); 69 | assertThat(convertedTime.getYear()).isEqualTo(1942); 70 | } 71 | 72 | @Test 73 | public void should_detect_MonthYear_format() { 74 | YearMonthConverter converter = new YearMonthConverter(); 75 | YearMonth convertedTime = converter.convertValue("1942-10", YearMonth.class); 76 | 77 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(10); 78 | assertThat(convertedTime.getYear()).isEqualTo(1942); 79 | } 80 | 81 | @Test 82 | public void should_detect_YearMonth_format_with_slash() { 83 | YearMonthConverter converter = new YearMonthConverter(); 84 | YearMonth convertedTime = converter.convertValue("10/1942", YearMonth.class); 85 | 86 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(10); 87 | assertThat(convertedTime.getYear()).isEqualTo(1942); 88 | } 89 | 90 | 91 | @Test 92 | public void should_detect_MonthYear_format_with_slash() { 93 | YearMonthConverter converter = new YearMonthConverter(); 94 | YearMonth convertedTime = converter.convertValue("1942/10", YearMonth.class); 95 | 96 | assertThat(convertedTime.getMonthOfYear()).isEqualTo(10); 97 | assertThat(convertedTime.getYear()).isEqualTo(1942); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/pages/StaticSitePage.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.pages; 2 | 3 | import net.serenitybdd.core.pages.WebElementFacade; 4 | import net.thucydides.core.annotations.DefaultUrl; 5 | import net.thucydides.core.pages.PageObject; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.ui.ExpectedCondition; 10 | 11 | @DefaultUrl("classpath:static-site/index.html") 12 | public class StaticSitePage extends PageObject { 13 | 14 | @FindBy(name = "firstname") 15 | protected WebElement firstName; 16 | 17 | @FindBy(name = "lastname") 18 | protected WebElement lastName; 19 | 20 | @FindBy(name = "city") 21 | protected WebElement city; 22 | 23 | @FindBy(name = "country") 24 | protected WebElement country; 25 | 26 | @FindBy(name = "hiddenfield") 27 | protected WebElement hiddenField; 28 | 29 | protected WebElement csshiddenfield; 30 | 31 | protected WebElement readonlyField; 32 | 33 | protected WebElement doesNotExist; 34 | 35 | protected WebElement textField; 36 | 37 | protected WebElement checkbox; 38 | 39 | protected WebElement radioButton1; 40 | protected WebElement radioButton2; 41 | 42 | protected WebElement selectedCheckbox; 43 | 44 | protected WebElement buttonThatIsInitiallyDisabled; 45 | 46 | protected WebElement buttonThatIsInitiallyEnabled; 47 | 48 | protected WebElement placetitle; 49 | 50 | protected WebElement dissapearingtext; 51 | 52 | @FindBy(id = "visible") 53 | protected WebElement visibleTitle; 54 | 55 | @FindBy(id = "color") 56 | protected WebElement colors; 57 | 58 | protected WebElement elements; 59 | 60 | protected WebElement grid; 61 | 62 | protected WebElement emptylist; 63 | 64 | @FindBy(name = "fieldDoesNotExist") 65 | protected WebElement fieldDoesNotExist; 66 | 67 | @FindBy(id = "emptyLabelID") 68 | protected WebElement emptyLabel; 69 | 70 | @FindBy(id = "nonEmptyLabelID") 71 | protected WebElement nonEmptyLabel; 72 | 73 | protected WebElement focusmessage; 74 | 75 | protected WebElement clients; 76 | 77 | protected WebElement clients_with_extra_cells; 78 | 79 | protected WebElement clients_with_missing_cells; 80 | 81 | protected WebElement table_with_merged_cells; 82 | 83 | protected WebElement table_with_empty_headers; 84 | 85 | protected WebElement table_with_td_headers; 86 | 87 | protected WebElement alertButton; 88 | 89 | protected WebElementFacade alertButton() { 90 | return element(alertButton); 91 | } 92 | 93 | public StaticSitePage(WebDriver driver) { 94 | super(driver); 95 | } 96 | 97 | public void setFirstName(String value) { 98 | element(firstName).type(value); 99 | } 100 | 101 | public void setLastName(String value) { 102 | element(lastName).type(value); 103 | } 104 | 105 | public void fieldDoesNotExistShouldNotBePresent() { 106 | element(fieldDoesNotExist).shouldNotBePresent(); 107 | } 108 | 109 | public void fieldDoesNotExistShouldBePresent() { 110 | element(fieldDoesNotExist).shouldBePresent(); 111 | } 112 | 113 | public void hiddenFieldShouldNotBePresent() { 114 | element(hiddenField).shouldNotBePresent(); 115 | } 116 | 117 | public void fieldDoesNotExistShouldContainText(String value) { 118 | element(fieldDoesNotExist).shouldContainText(value); 119 | } 120 | 121 | public WebElementFacade firstName() { 122 | return element(firstName); 123 | } 124 | 125 | public WebElementFacade lastName() { 126 | return element(lastName); 127 | } 128 | 129 | public void waitForFirstNameField() { 130 | waitForCondition().until(firstAndLastNameAreEnabled()); 131 | } 132 | 133 | public ExpectedCondition firstNameIsVisibleAndDisabled() { 134 | return driver -> (firstName.isDisplayed() && firstName.isEnabled()); 135 | } 136 | 137 | public ExpectedCondition firstAndLastNameAreEnabled() { 138 | return driver -> (firstName.isEnabled() && lastName.isEnabled()); 139 | } 140 | 141 | public ExpectedCondition twoFieldsAreDisabled() { 142 | return driver -> (!buttonThatIsInitiallyEnabled.isEnabled() && !readonlyField.isEnabled()); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/samples/levels/first/SerenityStorySampleForFistLevel.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.samples.levels.first; 2 | 3 | import net.serenitybdd.jbehave.SerenityStories; 4 | 5 | public class SerenityStorySampleForFistLevel extends SerenityStories { 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/samples/levels/second/SerenityStorySampleForSecondLevel.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.samples.levels.second; 2 | 3 | import net.serenitybdd.jbehave.SerenityStories; 4 | 5 | public class SerenityStorySampleForSecondLevel extends SerenityStories { 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/LifecycleStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | import net.thucydides.core.annotations.Steps; 5 | import org.jbehave.core.annotations.Given; 6 | import org.jbehave.core.annotations.Then; 7 | import org.jbehave.core.annotations.When; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | public class LifecycleStepDefinitions { 12 | 13 | static class Calculations { 14 | 15 | int total = 0; 16 | 17 | @Step 18 | public void add(int amount) { 19 | total += amount; 20 | } 21 | 22 | @Step 23 | public void substract(int amount) { 24 | total -= amount; 25 | } 26 | 27 | public int getTotal() { return total; } 28 | 29 | } 30 | 31 | @Steps 32 | Calculations calculations; 33 | 34 | @Given("I have a calculator") 35 | public void givenIHaveACalculator() { 36 | } 37 | 38 | @Given("I add $amount") 39 | public void givenIAdd(int amount) { 40 | calculations.add(amount); 41 | } 42 | 43 | @When("I add $amount") 44 | public void whenIAdd(int amount) { 45 | calculations.add(amount); 46 | } 47 | 48 | @When("I substract $amount") 49 | public void whenISubstract(int amount) { 50 | calculations.substract(amount); 51 | } 52 | 53 | @Then("the total should be $total") 54 | public void thenTheTotalShouldBe(int total) { 55 | assertThat(calculations.total).isEqualTo(total); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/SkippingScenariosStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.serenitybdd.core.pages.PageObject; 4 | import net.serenitybdd.core.pages.WebElementFacade; 5 | import net.thucydides.core.annotations.DefaultUrl; 6 | import net.thucydides.core.annotations.Step; 7 | import net.thucydides.core.annotations.Steps; 8 | import org.jbehave.core.annotations.Given; 9 | import org.jbehave.core.annotations.Then; 10 | import org.jbehave.core.annotations.When; 11 | import org.openqa.selenium.support.FindBy; 12 | 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | 18 | public class SkippingScenariosStepDefinitions { 19 | 20 | @DefaultUrl("https://duckduckgo.com") 21 | public static class DuckDuckGoSearchPage extends PageObject { 22 | 23 | @FindBy(id="search_form_input_homepage") 24 | WebElementFacade searchField; 25 | 26 | @FindBy(id="search_button_homepage") 27 | WebElementFacade searchButton; 28 | 29 | @FindBy(css = "#links .result__title") 30 | List results; 31 | 32 | public void enterSearchTerm(String searchTerm) { 33 | searchField.type(searchTerm); 34 | } 35 | 36 | public void requestSearch() { 37 | searchButton.click(); 38 | } 39 | 40 | public List getResults() { 41 | return results.stream().map(WebElementFacade::getText).collect(Collectors.toList()); 42 | } 43 | } 44 | 45 | public static class CuriousSurfer { 46 | 47 | DuckDuckGoSearchPage searchPage; 48 | 49 | @Step 50 | public void opensTheSearchApp() { 51 | searchPage.open(); 52 | } 53 | 54 | @Step 55 | public void searchesFor(String searchTerm) { 56 | searchPage.enterSearchTerm(searchTerm); 57 | searchPage.requestSearch(); 58 | } 59 | 60 | @Step 61 | public void shouldSeeTitle(String title) { 62 | assertThat(searchPage.getTitle()).contains(title); 63 | } 64 | 65 | @Step 66 | public void shouldSeeAListOfResults() { 67 | assertThat(searchPage.getResults().size()).isGreaterThan(0); 68 | } 69 | } 70 | 71 | @Steps 72 | CuriousSurfer connor; 73 | 74 | @Given("I want to search for something") 75 | public void givenIWantToSearchForFruit() { 76 | connor.opensTheSearchApp(); 77 | } 78 | 79 | @When("I lookup $searchTerm") 80 | public void whenILookup(String searchTerm) { 81 | connor.searchesFor(searchTerm); 82 | } 83 | 84 | @Then("I should see \"$title\" in the page title") 85 | public void thenIShouldSeeTitle(String title) { 86 | connor.shouldSeeTitle(title); 87 | } 88 | 89 | @Then("I should see search results") 90 | public void thenIShouldSeeSearchResults() { 91 | connor.shouldSeeAListOfResults(); 92 | } 93 | 94 | @Given("I want to indicate that a scenario should be performed manually") 95 | public void manual() {} 96 | 97 | @Given("I also want it appearing in the skipped scenarios") 98 | public void appear_as_skipped() {} 99 | 100 | @When("I tag it as ${tags}") 101 | public void tag_as(String tags) {} 102 | 103 | @Then("it should be reported as ${state}") 104 | public void reported_as(String states) {} 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/UsingStepLibrariesStepDefinitions.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | import net.thucydides.core.annotations.Steps; 5 | import org.jbehave.core.annotations.*; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.*; 9 | 10 | public class UsingStepLibrariesStepDefinitions { 11 | 12 | 13 | public static class SomeStepLibrary { 14 | 15 | public int stepRunCount = 0; 16 | 17 | @Step 18 | public void doSomething() { 19 | stepRunCount++; 20 | } 21 | 22 | @Step 23 | public void doSomethingElse() { 24 | stepRunCount++; 25 | } 26 | 27 | @Step 28 | public void doSomeOtherThing() { 29 | stepRunCount++; 30 | } 31 | } 32 | 33 | @Steps 34 | private SomeStepLibrary someStepLibrary; 35 | 36 | @Given("I want to use a step library") 37 | public void givenIWantToUseAStepLibrary() { 38 | } 39 | 40 | @When("I use a step library field annotated with @Steps") 41 | public void whenIAddAStepLibraryFieldAnnotatedWithSteps() { 42 | } 43 | 44 | @Then("Serenity should instantiate the field") 45 | public void thenSerenityShouldInstantiateTheField() { 46 | assertThat(someStepLibrary, notNullValue()); 47 | } 48 | 49 | ////// 50 | 51 | @Steps 52 | private SomeStepLibrary someOtherStepLibrary; 53 | 54 | @Given("I want to use several step library fields of the same type") 55 | public void givenIWantToUseSeveralStepLibraryFieldsOfTheSameType() { 56 | } 57 | 58 | @When("I use a step library fields to each of them") 59 | public void whenIAddAStepLibraryFieldsToEachOfThem() { 60 | } 61 | 62 | @Then("Serenity should instantiate a different library for each field") 63 | public void thenSerenityShouldInstantiateADifferentLibraryForEachField() { 64 | assertThat(someOtherStepLibrary, is(not(sameInstance(someStepLibrary)))); 65 | } 66 | 67 | ///// 68 | @Steps 69 | private SomeStepLibrary myStepLibrary; 70 | 71 | @Given("I have a Serenity step library") 72 | public void givenIHaveASerenityStepLibrary() { 73 | } 74 | 75 | @When("I do something with the library") 76 | public void whenIDoSomethingWithTheLibrary() { 77 | myStepLibrary.doSomething(); 78 | } 79 | 80 | @Then("the state of the library should be updated") 81 | public void thenTheStateOfTheLibraryShouldBeUpdated() { 82 | assertThat(myStepLibrary.stepRunCount, is(1)); 83 | } 84 | 85 | //// 86 | 87 | 88 | @When("I start a new scenario") 89 | public void whenIStartANewScenario() { 90 | } 91 | 92 | @Then("the step library should be reinitialised") 93 | public void thenTheStepLibraryShouldBeReinitialised() { 94 | assertThat(myStepLibrary.stepRunCount, is(0)); 95 | } 96 | 97 | @Steps(shared = true) 98 | private SomeStepLibrary aSharedStepLibrary; 99 | 100 | @Steps(shared = true) 101 | private SomeStepLibrary anotherSharedStepLibrary; 102 | 103 | @Given("I have two Serenity step libraries") 104 | public void givenIHaveTwoSerenityStepLibraries() { 105 | } 106 | 107 | @When("they are annotated with @Steps(shared=true)") 108 | public void whenTheyAreAnnotatedWithStepssharedtrue() { 109 | } 110 | 111 | @Then("both should refer to the same instance") 112 | public void thenBothShouldReferToTheSameInstance() { 113 | assertThat(aSharedStepLibrary, is(sameInstance(anotherSharedStepLibrary))); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/WhenSkippingScenarios.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenSkippingScenarios extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/WhenUsingGivenStoriesWithWebTests.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingGivenStoriesWithWebTests extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/WhenUsingSimpleLifecycleSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingSimpleLifecycleSteps extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/smoketests/WhenUsingStepLibraries.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.smoketests; 2 | 3 | import net.serenitybdd.jbehave.SerenityStory; 4 | 5 | public class WhenUsingStepLibraries extends SerenityStory {} 6 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/CheckValuesStep.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | import net.thucydides.core.annotations.Steps; 5 | 6 | public class CheckValuesStep { 7 | String firstname; 8 | String lastname; 9 | String expectedFirstname; 10 | String expectedLastname; 11 | 12 | @Steps 13 | SomeNormalSteps normalSteps; 14 | 15 | @Step 16 | public void checkValues() { 17 | normalSteps.processFirstName(firstname); 18 | normalSteps.processSecondName(lastname); 19 | normalSteps.checkResults(expectedFirstname, expectedLastname); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/CompositeSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.jbehave.core.annotations.Composite; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | 8 | public class CompositeSteps { 9 | 10 | @Given("G") 11 | public void dummyGiven() { 12 | System.out.println("--> dummyGiven()"); 13 | } 14 | 15 | @When("W") 16 | public void dummyWhen() { 17 | System.out.println("--> dummyWhen()"); 18 | } 19 | 20 | @Then("T") 21 | public void dummyThen() { 22 | System.out.println("--> dummyThen()"); 23 | } 24 | 25 | @Given("GW") 26 | @Composite(steps = { "Given G", "When W" }) 27 | public void dummyCompositeStep() { 28 | System.out.println("--> dummyCompositeStep()"); 29 | } 30 | 31 | @When("W2") 32 | public void dummyWhen2() { 33 | System.out.println("--> dummyWhen2()"); 34 | } 35 | 36 | @Then("T2") 37 | public void dummyThen2() { 38 | System.out.println("--> dummyThen2()"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/EnterNamesStep.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | import net.thucydides.core.annotations.Steps; 5 | 6 | public class EnterNamesStep { 7 | String firstname; 8 | String lastname; 9 | String expectedFirstname; 10 | String expectedLastname; 11 | 12 | @Steps 13 | SomeSeleniumSteps steps; 14 | 15 | @Step 16 | public void enterAndCheckName() { 17 | steps.whenIEnterTheFirstName(firstname); 18 | steps.whenIEnterTheLastName(lastname); 19 | steps.thenIShouldSeeInTheNamesFields(expectedFirstname, expectedLastname); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/NestedSpringEnabledSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Steps; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | 10 | import static org.hamcrest.MatcherAssert.assertThat; 11 | import static org.hamcrest.Matchers.is; 12 | import static org.hamcrest.Matchers.notNullValue; 13 | 14 | @ContextConfiguration(locations = "/spring/config.xml") 15 | public class NestedSpringEnabledSteps { 16 | 17 | @Autowired 18 | public WidgetService widgetService; 19 | 20 | private String widgetName; 21 | 22 | @Steps 23 | private NestedSteps nestedSteps; 24 | 25 | @Given("I hava a nested autowired Spring bean") 26 | public void givenIHavaAnAutowiredSpringBean() { 27 | assertThat(nestedSteps.widgetService, notNullValue()); 28 | } 29 | 30 | @When("I use the nested bean") 31 | public void whenIUseTheBean() { 32 | widgetName = nestedSteps.widgetService.getName(); 33 | } 34 | 35 | @Then("the nested bean should be instanciated") 36 | public void thenItShouldBeInstanciated() { 37 | assertThat(widgetName, is("Widgets")); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/NestedSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | @ContextConfiguration(locations = "/spring/config.xml") 7 | public class NestedSteps { 8 | @Autowired 9 | public WidgetService widgetService; 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/ParameterizedSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.jbehave.core.annotations.Given; 4 | import org.jbehave.core.annotations.Then; 5 | import org.jbehave.core.annotations.When; 6 | import org.joda.time.DateTime; 7 | import org.joda.time.LocalTime; 8 | 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | import static junit.framework.TestCase.assertNotNull; 13 | 14 | public class ParameterizedSteps { 15 | 16 | Date date; 17 | List dates; 18 | 19 | DateTime dateTime; 20 | List dateTimes; 21 | 22 | LocalTime time; 23 | List times; 24 | 25 | @Given("I have a date $date") 26 | public void singleDate(Date date) { 27 | this.date = date; 28 | } 29 | 30 | @Given("I have a list of dates $dateList") 31 | public void dateList(List dates) { 32 | this.dates = dates; 33 | } 34 | 35 | @Given("I have a joda date $date") 36 | public void singleJodaDate(DateTime dateTime) { 37 | this.dateTime = dateTime; 38 | } 39 | 40 | @Given("I have a list of joda dates $dateList") 41 | public void jodaDateList(List dateTimes) { 42 | this.dateTimes = dateTimes; 43 | } 44 | 45 | 46 | @Given("I have a time $time") 47 | public void singleTime(LocalTime time) { 48 | this.time = time; 49 | } 50 | @Given("I have a list of times $times") 51 | public void listOfTimes(List times) { 52 | this.times = times; 53 | } 54 | 55 | @When("I run the story") 56 | public void run() {} 57 | 58 | @Then("the parameters should be converted") 59 | public void parametersAreConverted() { 60 | assertNotNull(date); 61 | assertNotNull(dates); 62 | assertNotNull(dateTime); 63 | assertNotNull(dateTimes); 64 | assertNotNull(time); 65 | assertNotNull(times); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeDataDrivenSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.ManagedPages; 4 | import net.thucydides.core.annotations.Steps; 5 | import net.thucydides.core.pages.Pages; 6 | import net.thucydides.core.steps.StepFactory; 7 | import org.jbehave.core.annotations.Given; 8 | import org.jbehave.core.annotations.Then; 9 | import org.jbehave.core.annotations.When; 10 | 11 | import java.io.IOException; 12 | 13 | import static net.thucydides.core.steps.stepdata.StepData.withTestDataFrom; 14 | 15 | public class SomeDataDrivenSteps { 16 | 17 | @ManagedPages 18 | Pages pages; 19 | 20 | @Steps 21 | SomeSeleniumSteps steps; 22 | 23 | @Steps 24 | SomeNormalSteps normalSteps; 25 | 26 | @Steps 27 | EnterNamesStep enterNameSteps; 28 | 29 | String dataSource; 30 | 31 | @Given("the names in $dataSource") 32 | public void givenTheNamesIn(String dataSource) { 33 | this.dataSource = dataSource; 34 | } 35 | 36 | @When("we enter these values") 37 | public void whenWeEnterTheseValues() { 38 | steps.givenIAmOnTheTestPage(); 39 | } 40 | 41 | @Then("we should see them on the screen") 42 | public void thenWeShouldSeeThemOnTheScreen() throws IOException { 43 | StepFactory factory = new StepFactory(pages); 44 | withTestDataFrom(dataSource).usingFactory(factory).run(enterNameSteps).enterAndCheckName(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeNestedSeleniumSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.serenitybdd.jbehave.pages.StaticSitePage; 4 | import net.thucydides.core.annotations.Step; 5 | 6 | public class SomeNestedSeleniumSteps { 7 | 8 | // @Managed 9 | // public WebDriver webDriver; 10 | 11 | StaticSitePage staticSitePage; 12 | 13 | @Step 14 | public void enters_the_first_name(String firstname) { 15 | staticSitePage.setFirstName(firstname); 16 | } 17 | 18 | @Step 19 | public void enters_the_last_name(String lastname) { 20 | staticSitePage.setLastName(lastname); 21 | } 22 | 23 | @Step 24 | public void open_first_page() { 25 | staticSitePage.open(); 26 | } 27 | 28 | @Step 29 | public void reads_first_name() { 30 | staticSitePage.firstName().getValue(); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeNonWebDataDrivenSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Steps; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | 8 | import java.io.IOException; 9 | 10 | import static net.thucydides.core.steps.stepdata.StepData.withTestDataFrom; 11 | 12 | public class SomeNonWebDataDrivenSteps { 13 | 14 | @Steps 15 | CheckValuesStep checkValueSteps; 16 | 17 | String dataSource; 18 | 19 | @Given("the data in $dataSource") 20 | public void givenTheNamesIn(String dataSource) { 21 | this.dataSource = dataSource; 22 | } 23 | 24 | @When("we enter this data") 25 | public void whenWeEnterThisData() {} 26 | 27 | @Then("the values should be correct") 28 | public void thenTheValuesShouldBeCorrect() throws IOException { 29 | withTestDataFrom(dataSource).run(checkValueSteps).checkValues(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeNormalSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Step; 4 | 5 | public class SomeNormalSteps { 6 | 7 | @Step 8 | public void processFirstName(String firstname) { 9 | } 10 | 11 | @Step 12 | public void processSecondName(String lastname) { 13 | } 14 | 15 | @Step 16 | public void checkResults(String expectedFirstname, String expectedLastname) { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeSeleniumSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.serenitybdd.jbehave.pages.StaticSitePage; 4 | import net.thucydides.core.annotations.Managed; 5 | import net.thucydides.core.annotations.ManagedPages; 6 | import net.thucydides.core.annotations.Steps; 7 | import net.thucydides.core.pages.Pages; 8 | import net.thucydides.core.webdriver.WebDriverFacade; 9 | import org.jbehave.core.annotations.Alias; 10 | import org.jbehave.core.annotations.Given; 11 | import org.jbehave.core.annotations.Then; 12 | import org.jbehave.core.annotations.When; 13 | import org.openqa.selenium.ElementNotVisibleException; 14 | import org.openqa.selenium.WebDriver; 15 | 16 | import static org.hamcrest.MatcherAssert.assertThat; 17 | import static org.hamcrest.Matchers.*; 18 | 19 | public class SomeSeleniumSteps { 20 | 21 | @Managed(driver="chrome") 22 | public WebDriver webDriver; 23 | 24 | @ManagedPages 25 | public Pages pages; 26 | 27 | @Steps 28 | SomeNestedSeleniumSteps the_user; 29 | 30 | StaticSitePage page; 31 | public SomeSeleniumSteps(Pages pages) { 32 | this.pages = pages; 33 | page = pages.get(StaticSitePage.class); 34 | } 35 | 36 | @Given("I have an implemented JBehave scenario that uses selenium") 37 | public void givenIHaveAnImplementedJBehaveScenarioThatUsesSelenium() { 38 | } 39 | 40 | @Given("the scenario uses selenium") 41 | public void givenTheScenarioUsesSelenium() { 42 | } 43 | 44 | @When("I run the web scenario") 45 | public void whenIRunTheWebScenario() { 46 | page.open(); 47 | } 48 | 49 | @Then("the webdriver variable should be correctly instantiated") 50 | public void thenTheWebdriverVariableShouldBeCorrectlyInstantiated() { 51 | assertThat(webDriver, is(notNullValue())); 52 | } 53 | 54 | @Then("the pages variable should be correctly instantiated") 55 | public void thenThePagesVariableShouldBeCorrectlyInstantiated() { 56 | assertThat(pages, is(notNullValue())); 57 | } 58 | 59 | @Given("I am on the test page") 60 | public void givenIAmOnTheTestPage() { 61 | page.open(); 62 | } 63 | 64 | @When("I enter the first name $firstname") 65 | public void whenIEnterTheFirstName(String firstname) { 66 | page.setFirstName(firstname); 67 | } 68 | 69 | @When("I enter the last name $lastname") 70 | public void whenIEnterTheLastName(String lastname) { 71 | page.setLastName(lastname); 72 | } 73 | 74 | @When("I type in the first name ") 75 | public void whenITypeInTheFirstName(String firstname) { 76 | the_user.enters_the_first_name(firstname); 77 | } 78 | 79 | @When("I type in the last name ") 80 | public void whenITypeInTheLastName(String lastname) { 81 | the_user.enters_the_last_name(lastname); 82 | } 83 | 84 | @Then("I should see entered values of and ") 85 | @Alias("I should see and in the names fields") 86 | public void thenIShouldSeeInTheNamesFields(String expectedFirstname, 87 | String expectedLastname) { 88 | assertThat(page.firstName().getValue(), is(expectedFirstname)); 89 | assertThat(page.lastName().getValue(), is(expectedLastname)); 90 | } 91 | 92 | @Then("I should see first name $expectedFirstname on the screen") 93 | public void thenIShouldSeeFirstNameOnTheScreen(String $expectedFirstname) { 94 | assertThat(page.firstName().getValue(), is($expectedFirstname)); 95 | } 96 | 97 | @Then("I should see last name $expectedLastname on the screen") 98 | public void thenIShouldSeeLastNameOnTheScreen(String $expectedLastname) { 99 | assertThat(page.lastName().getValue(), is($expectedLastname)); 100 | } 101 | 102 | @Then("I should be using $browser") 103 | public void andIShouldBeUsingHtmlUnit(String browser) { 104 | assertThat(((WebDriverFacade)webDriver).getDriverName(), equalTo(browser)); 105 | } 106 | 107 | @Given("the scenario throws an exception") 108 | public void throwAnException() { 109 | throw new ElementNotVisibleException("Oops"); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeSerenitySteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Pending; 4 | import net.thucydides.core.annotations.Step; 5 | 6 | import static org.junit.Assume.assumeTrue; 7 | 8 | public class SomeSerenitySteps { 9 | 10 | @Step 11 | public void step1() { 12 | System.out.println("STEP 1"); 13 | } 14 | 15 | @Step 16 | public void step2() { 17 | System.out.println("STEP 2");} 18 | 19 | @Step 20 | public void step3() { 21 | System.out.println("STEP 3"); 22 | } 23 | 24 | @Pending 25 | @Step 26 | public void pendingStep() { 27 | System.out.println("PENDING STEP"); 28 | } 29 | 30 | @Step 31 | public void failedAssumption() { 32 | assumeTrue(false); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SomeStepsWithState.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.jbehave.core.annotations.Given; 4 | import org.jbehave.core.annotations.Then; 5 | import org.jbehave.core.annotations.When; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.nullValue; 10 | 11 | public class SomeStepsWithState { 12 | 13 | public enum Color { 14 | RED, BLUE, GREEN 15 | } 16 | 17 | Color field; 18 | 19 | @Given("I have a field") 20 | public void setupField() { 21 | } 22 | 23 | @When("I instantiate that field with value $value") 24 | public void instantiateFieldWith(Color value) { 25 | this.field = value; 26 | 27 | } 28 | 29 | @Then("the field should be set to $value in the following steps") 30 | public void checkValueIsSet(Color value) { 31 | assertThat(field, is(value)); 32 | } 33 | 34 | @When("I instantiate do not that field") 35 | public void doNothing() { 36 | } 37 | 38 | @Then("the field should not be set") 39 | public void checkFieldIsNull() { 40 | assertThat(field, is(nullValue())); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/SpringEnabledSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.jbehave.core.annotations.Given; 4 | import org.jbehave.core.annotations.Then; 5 | import org.jbehave.core.annotations.When; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ContextConfiguration; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.is; 11 | import static org.hamcrest.Matchers.notNullValue; 12 | 13 | @ContextConfiguration(locations = "/spring/config.xml") 14 | public class SpringEnabledSteps { 15 | 16 | @Autowired 17 | public WidgetService widgetService; 18 | 19 | private String widgetName; 20 | 21 | @Given("I hava an autowired Spring bean") 22 | public void givenIHavaAnAutowiredSpringBean() { 23 | assertThat(widgetService, notNullValue()); 24 | } 25 | 26 | @When("I use the bean") 27 | public void whenIUseTheBean() { 28 | widgetName = widgetService.getName(); 29 | } 30 | 31 | @Then("it should be instanciated") 32 | public void thenItShouldBeInstanciated() { 33 | assertThat(widgetName, is("Widgets")); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/StepsWithSharedVariables.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import org.jbehave.core.annotations.Then; 4 | import org.jbehave.core.annotations.When; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | /** 9 | * Created by john on 8/10/2014. 10 | */ 11 | public class StepsWithSharedVariables { 12 | int value = 0; 13 | 14 | @When("a field is initialized to $n") 15 | public void whenAFieldIsInitializedTo(int n) { 16 | value = n; 17 | } 18 | 19 | @Then("it should have a value of $n") 20 | public void thenItShouldHaveAValueOf(int n) { 21 | assertThat(value).isEqualTo(n); 22 | } 23 | 24 | @When("the same field is incremented") 25 | public void incrementField() { 26 | value++; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/StoryStepsUsingACustomTag.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.serenitybdd.core.Serenity; 4 | import org.jbehave.core.annotations.BeforeStory; 5 | import org.jbehave.core.annotations.Given; 6 | import org.jbehave.core.annotations.Then; 7 | 8 | import java.util.Map; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | public class StoryStepsUsingACustomTag { 13 | 14 | @Given("the scenario uses a custom tag") 15 | public void givenTheScenarioUsesACustomTag() { 16 | } 17 | 18 | @Then("I should be able to read the custom tag") 19 | public void thenIShouldBeAbleToReadTheCustomTag() { 20 | Map metadata = Serenity.getCurrentSession().getMetaData(); 21 | assertThat(metadata).isNotEmpty(); 22 | } 23 | 24 | @Then("I should be able to read the issue tag") 25 | public void thenIShouldBeAbleToReadTheIssueTag() { 26 | Map metadata = Serenity.getCurrentSession().getMetaData(); 27 | assertThat(metadata.get("issue")).isEqualTo("ISSUE-1"); 28 | } 29 | 30 | @Given("the scenario uses the custom tag $tagvalue") 31 | public void givenTheScenarioUsesTheCustomTag(String tagvalue) { 32 | } 33 | 34 | @Then("I should be able to read the custom tag $tagvalue and the global tag '$global'") 35 | public void thenIShouldBeAbleToReadTheCustomTag(String tagvalue, String global) { 36 | Map metadata = Serenity.getCurrentSession().getMetaData(); 37 | assertThat(metadata).isNotEmpty(); 38 | assertThat(metadata.get("sql")).containsIgnoringCase(tagvalue); 39 | assertThat(metadata.get("global")).containsIgnoringCase(global); 40 | } 41 | 42 | @Then("I should be able to use the and the field in my stored procedure") 43 | public void thenIShouldBeAbleToUseThenameAndTheageFieldInMyStoredProcedure(String name, String age) { 44 | } 45 | 46 | @Then("the local variable should be defined") 47 | public void thenTheLocalVariableShouldBeDefined() { 48 | Map metadata = Serenity.getCurrentSession().getMetaData(); 49 | assertThat(metadata.get("local")).isEqualTo("defined"); 50 | } 51 | 52 | 53 | @Then("the local variable should not be defined") 54 | public void thenTheLocalVariableShouldNotBeDefined() { 55 | Map metadata = Serenity.getCurrentSession().getMetaData(); 56 | assertThat(metadata.get("local")).isNull(); 57 | } 58 | 59 | @BeforeStory 60 | public void beforeStory() { 61 | Map metadata = Serenity.getCurrentSession().getMetaData(); 62 | if (!metadata.isEmpty() && metadata.get("global") != null) { 63 | assertThat(metadata.get("global")).containsIgnoringCase("shared"); 64 | } 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/StoryStepsWithPageObjects.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.serenitybdd.jbehave.pages.StaticSitePage; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | 8 | import static org.hamcrest.MatcherAssert.assertThat; 9 | import static org.hamcrest.Matchers.is; 10 | 11 | public class StoryStepsWithPageObjects { 12 | 13 | StaticSitePage indexPage; 14 | 15 | @Given("I start on the test page") 16 | public void givenIAmOnTheTestPage() { 17 | indexPage.open(); 18 | } 19 | 20 | @When("I enter a first name $firstname") 21 | public void whenIEnterTheFirstName(String firstname) { 22 | indexPage.setFirstName(firstname); 23 | } 24 | 25 | @When("I enter a last name $lastname") 26 | public void whenIEnterTheLastName(String lastname) { 27 | indexPage.setLastName(lastname); 28 | } 29 | 30 | @Then("I should see the $firstname and $lastname in the names fields") 31 | public void thenIShouldSeeInTheNamesFields(String firstname, 32 | String lastname) { 33 | assertThat(indexPage.firstName().getValue(), is(firstname)); 34 | assertThat(indexPage.lastName().getValue(), is(lastname)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/StoryStepsWithSerenitySteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | import net.thucydides.core.annotations.Steps; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | 8 | public class StoryStepsWithSerenitySteps { 9 | 10 | @Steps 11 | SomeSerenitySteps steps; 12 | 13 | @Given("the scenario has steps") 14 | public void givenTheScenarioHasSteps() { 15 | steps.step1(); 16 | steps.step2(); 17 | steps.step3(); 18 | } 19 | 20 | @Then("the steps should appear in the outcome") 21 | public void thenTheStepsShouldAppearInTheOutcome() { 22 | } 23 | 24 | 25 | @When("one of the steps is pending") 26 | public void whenOneOfTheStepsIsPending() { 27 | steps.pendingStep(); 28 | } 29 | 30 | @Then("the test outcome should be pending") 31 | public void thenTheTestOutcomeShouldBePending() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/WidgetService.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps; 2 | 3 | public class WidgetService { 4 | 5 | private String name; 6 | private int quota; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public int getQuota() { 17 | return quota; 18 | } 19 | 20 | public void setQuota(int quota) { 21 | this.quota = quota; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/dateconversions/DateTimeConversionSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps.dateconversions; 2 | 3 | import org.jbehave.core.annotations.Alias; 4 | import org.jbehave.core.annotations.Given; 5 | import org.jbehave.core.annotations.Then; 6 | import org.jbehave.core.annotations.When; 7 | import org.joda.time.DateTime; 8 | 9 | import java.util.List; 10 | 11 | import static java.util.stream.Collectors.toList; 12 | import static org.assertj.core.api.Assertions.assertThat; 13 | 14 | public class DateTimeConversionSteps { 15 | 16 | DateTime dateTimeParameter; 17 | List dateTimeParameterList; 18 | @Given("I want to convert a list of string values to Joda DateTime objects") 19 | @Alias("I want to convert string values to Joda DateTime objects") 20 | public void converting_joda_datetime_objects() {} 21 | 22 | @When("I pass a DateTime parameter a value of ") 23 | public void convert_datetime(DateTime value) { 24 | dateTimeParameter = value; 25 | } 26 | 27 | @Then("the parameter should be converted to a DateTime with a value of ") 28 | public void should_get_expected_value(String expectedValue) { 29 | assertThat(dateTimeParameter).isEqualTo(new DateTime(expectedValue)); 30 | } 31 | 32 | @When("I pass a DateTime List parameter a value of ") 33 | public void convert_datetimes(List value) { 34 | dateTimeParameterList = value; 35 | } 36 | 37 | @Then("the parameter should be converted to a list of DateTimes with values ") 38 | public void thenTheParameterShouldBeConvertedToAListOfDateTimesWithValues(List expected) { 39 | assertThat(dateTimeParameterList).isEqualTo(expected.stream().map(DateTime::new).collect(toList())); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/dateconversions/LocalTimeConversionSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps.dateconversions; 2 | 3 | import org.jbehave.core.annotations.Given; 4 | import org.jbehave.core.annotations.Then; 5 | import org.jbehave.core.annotations.When; 6 | import org.joda.time.LocalTime; 7 | 8 | import java.util.List; 9 | 10 | import static java.util.stream.Collectors.toList; 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class LocalTimeConversionSteps { 14 | 15 | LocalTime localTimeParameter; 16 | List localTimeParameterList; 17 | 18 | @Given("I want to convert string values to Joda LocalTime objects") 19 | public void converting_joda_datetime_objects() {} 20 | 21 | @When("I pass a LocalTime parameter a value of ") 22 | public void convert_localtime(LocalTime value) { 23 | localTimeParameter = value; 24 | } 25 | 26 | @Then("the parameter should be converted to a LocalTime with a value of ") 27 | public void should_get_expected_localtime_value(String expected) { 28 | assertThat(localTimeParameter).isEqualTo(new LocalTime(expected)); 29 | } 30 | 31 | @When("I pass a LocalTime List parameter a value of ") 32 | public void convert_localtimes(List value) { 33 | localTimeParameterList = value; 34 | } 35 | 36 | 37 | @Then("the parameter should be converted to a list of LocalTimes with values ") 38 | public void should_get_expected_localtime_value_list(List expected) { 39 | assertThat(localTimeParameterList).isEqualTo(expected.stream().map(LocalTime::new).collect(toList())); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/serenitybdd/jbehave/steps/dateconversions/MonthYearConversionSteps.java: -------------------------------------------------------------------------------- 1 | package net.serenitybdd.jbehave.steps.dateconversions; 2 | 3 | import org.jbehave.core.annotations.Given; 4 | import org.jbehave.core.annotations.Then; 5 | import org.jbehave.core.annotations.When; 6 | import org.joda.time.YearMonth; 7 | 8 | import java.util.List; 9 | 10 | import static java.util.stream.Collectors.toList; 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class MonthYearConversionSteps { 14 | 15 | private YearMonth yearMonthParameter; 16 | private List yearMonthList; 17 | 18 | @Given("I want to convert string values to Joda MonthYear objects") 19 | public void givenIWantToConvertStringValuesToJodaMonthYearObjects() {} 20 | 21 | @When("I pass a YearMonth parameter a value of ") 22 | public void whenIPassAMonthYearParameterAValueOf(YearMonth value) { 23 | yearMonthParameter = value; 24 | } 25 | 26 | @Then("the parameter should be converted to a YearMonth with a value of ") 27 | public void thenTheParameterShouldBeConvertedToAYearMonthWithAValueOf(String expectedValue) { 28 | YearMonth expectedYearMonthValue = new YearMonth(expectedValue); 29 | assertThat(yearMonthParameter).isEqualTo(expectedYearMonthValue); 30 | } 31 | 32 | @When("I pass a list of YearMonth parameter a value of ") 33 | public void passYearMonthParameterList(List value) { 34 | this.yearMonthList = value; 35 | } 36 | 37 | @Then("the parameter should be converted to a list of YearMonth with a value of ") 38 | public void convertToListOfYearMonths(List expected) { 39 | assertThat(yearMonthList).isEqualTo(expected.stream().map(YearMonth::new).collect(toList())); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/resources/data/names-data.csv: -------------------------------------------------------------------------------- 1 | firstname,lastname,expectedFirstname, expectedLastname 2 | Joe,Smith,Will,Smith 3 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.logger.org.hibernate=warn 2 | log4j.logger.net.serenitybdd=info 3 | -------------------------------------------------------------------------------- /src/test/resources/spring/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Widgets 8 | 1 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/resources/stories/BehaviorWithEmbeddedTables.story: -------------------------------------------------------------------------------- 1 | Scenario: a scenario with embedded tables 2 | Given that I sell the following fruit 3 | | fruit | price | 4 | | apples | 5.00 | 5 | | pears | 6.00 | 6 | And I sell the following vegetables 7 | | vegetable | price | 8 | | potatoe | 4.00 | 9 | | carrot | 5.50 | 10 | When I sell fruit 11 | Then the total cost should be total 12 | Examples: 13 | | goods | total | 14 | | apples, carrot | 11.50 | 15 | | apples, pears | 11.00 | 16 | | potatoe, carrot | 9.50 | -------------------------------------------------------------------------------- /src/test/resources/stories/LookupADefinitionSuite.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver phantomjs 3 | 4 | Scenario: Looking up the definition of 'apple' 5 | GivenStories: stories/precondition/aPreconditionToLookUpADefinition.story 6 | When the user looks up the definition of the word 'apple' 7 | Then they should see the definition 'A common, round fruit produced by the tree Malus domestica, cultivated in temperate climates.' 8 | 9 | 10 | Scenario: Looking up the definition of 'pear' 11 | GivenStories: stories/precondition/aPreconditionToLookUpADefinition.story 12 | When the user looks up the definition of the word 'pear' 13 | Then they should see the definition 'A common, round fruit produced by the tree Malus domestica, cultivated in temperate climates.' -------------------------------------------------------------------------------- /src/test/resources/stories/RunningASimpleJBehaveBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: Running a simple successful JBehave story 2 | 3 | Given a JBehave story 4 | When we run the story with Serenity 5 | Then it should generate a Serenity report for this story 6 | And it should throw an exception 7 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorThrowingAnException.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that uses selenium 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario throws an exception 5 | When I run the scenario 6 | Then I should get a failed result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithADescription.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithAFailingAssumption.story: -------------------------------------------------------------------------------- 1 | 2 | Scenario: A scenario that fails its precondition 3 | Given I have a failing precondition 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result 7 | 8 | Scenario: Another scenario that works 9 | Given I have a passing precondition 10 | And the scenario works 11 | When I run the scenario 12 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithAPendingStep.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with a pending step 2 | 3 | Given I have an implemented JBehave scenario 4 | When I run the scenario 5 | And one of the steps is pending 6 | Then the test outcome should be pending -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithATaggedPendingAndSkippedScenarios.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result 7 | 8 | Scenario: A scenario that is pending 9 | Meta: 10 | @pending 11 | 12 | Given I have an implemented JBehave scenario 13 | And the scenario works 14 | When I run the scenario 15 | Then I should get a successful result 16 | 17 | Scenario: A scenario that is work-in-progress 18 | Meta: 19 | @wip 20 | 21 | Given I have an implemented JBehave scenario 22 | And the scenario works 23 | When I run the scenario 24 | Then I should get a successful result 25 | 26 | Scenario: scenario that is work-in-progress 27 | Meta: 28 | @skip 29 | 30 | Given I have an implemented JBehave scenario 31 | And the scenario works 32 | When I run the scenario 33 | Then I should get a successful result 34 | 35 | Scenario: A scenario that is ignored 36 | Meta: 37 | @ignore 38 | 39 | Given I have an implemented JBehave scenario 40 | And the scenario works 41 | When I run the scenario 42 | Then I should get a successful result 43 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithATitle.story: -------------------------------------------------------------------------------- 1 | This is the story title 2 | Scenario: A scenario that works 3 | 4 | Given I have an implemented JBehave scenario 5 | And the scenario works 6 | When I run the scenario 7 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithAnError.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that fails 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario contains an error 5 | When I run the scenario 6 | Then I should get a failed result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithAnIssue.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | Meta: 3 | @issue MYPROJ-456 4 | 5 | Given I have an implemented JBehave scenario 6 | And the scenario works 7 | When I run the scenario 8 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithAnUndefinedStep.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with a pending step 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario has steps 5 | When I run the scenario 6 | And one of the steps is pending 7 | Then the test outcome should be pending -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithCompositeSteps.story: -------------------------------------------------------------------------------- 1 | Scenario: Normal GWT should just work 2 | 3 | Given G 4 | When W 5 | Then T 6 | 7 | Scenario: Should be able to use composite steps 8 | 9 | Given GW 10 | When W2 11 | Then T2 -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithCustomMetaTags.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with a SQL tag 2 | Meta: 3 | @sql MY_STORED_PROCEDURE($param1, $param2) 4 | @issue ISSUE-1 5 | 6 | Given I have an implemented JBehave scenario 7 | And the scenario uses a custom tag 8 | When I run the scenario 9 | Then I should be able to read the custom tag 10 | And I should be able to read the issue tag -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithCustomMetaTagsAtSeveralLevels.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @global shared 3 | 4 | Scenario: A scenario with a SQL tag 5 | Meta: 6 | @sql MY_STORED_PROCEDURE($param1, $param2) 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario uses the custom tag MY_STORED_PROCEDURE 10 | When I run the scenario 11 | Then I should be able to read the custom tag MY_STORED_PROCEDURE and the global tag 'shared' 12 | 13 | Scenario: A scenario with another SQL tag 14 | Meta: 15 | @sql MY_OTHER_STORED_PROCEDURE($name, $age) 16 | 17 | Given I have an implemented JBehave scenario 18 | And the scenario uses the custom tag MY_OTHER_STORED_PROCEDURE 19 | When I run the scenario 20 | Then I should be able to read the custom tag MY_OTHER_STORED_PROCEDURE and the global tag 'shared' 21 | And I should be able to use the and the field in my stored procedure 22 | Examples: 23 | |name |age| 24 | |Bill |20 | 25 | |Kim |24 | 26 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithCustomMetaTagsInSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @global shared 3 | 4 | Scenario: A scenario with a local metadata field defined 5 | Meta: 6 | @local defined 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario uses a custom tag 10 | When I run the scenario 11 | Then the local variable should be defined 12 | 13 | Scenario: A scenario with no local metadata field defined 14 | 15 | Given I have an implemented JBehave scenario 16 | And the scenario uses the custom tag MY_OTHER_STORED_PROCEDURE 17 | When I run the scenario 18 | Then the local variable should not be defined 19 | 20 | Scenario: A scenario with no local metadata field defined 21 | 22 | Given I have an implemented JBehave scenario 23 | And the scenario uses the custom tag MY_OTHER_STORED_PROCEDURE 24 | When I run the scenario 25 | Then the local variable should not be defined 26 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithDatesAndTimes.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that uses dates and times 2 | 3 | Given I have a date 10/10/2000 4 | And I have a list of dates 11/10/2000,12/10/2000 5 | Given I have a joda date 10/10/2000 6 | And I have a list of joda dates 11/10/2000,12/10/2000 7 | And I have a time 15:00 8 | And I have a list of times 16:00,17:00 9 | When I run the story 10 | Then the parameters should be converted -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithFeatures.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @feature a feature 3 | 4 | Scenario: A scenario that works 5 | Meta: 6 | @feature another feature 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithGivenStories.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver phantomjs 3 | 4 | GivenStories: stories/precondition/aPreconditionToFile.story 5 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithIssues.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @issue MYPROJ-123 3 | 4 | Scenario: A scenario that works 5 | Meta: 6 | @issue MYPROJ-456 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result 12 | 13 | Scenario: Another scenario that works 14 | Meta: 15 | @issue MYPROJ-789 16 | 17 | Given I have an implemented JBehave scenario 18 | And the scenario works 19 | When I run the scenario 20 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithManualAndNotManualScenario.story: -------------------------------------------------------------------------------- 1 | Narrative: 2 | In order to provide some business value 3 | As a user 4 | I want to perform an action 5 | 6 | Scenario: A scenario that works and should be manual 7 | Meta: 8 | @manual 9 | 10 | Given I have an implemented JBehave scenario 11 | And the scenario works 12 | When I run the scenario 13 | Then I should get a successful result 14 | 15 | Scenario: A scenario that works and should not be manual 16 | 17 | Given I have an implemented JBehave scenario 18 | And the scenario works 19 | When I run the scenario 20 | Then I should get a successful result 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithManualScenario.story: -------------------------------------------------------------------------------- 1 | Narrative: 2 | In order to provide some business value 3 | As a user 4 | I want to perform an action 5 | 6 | Scenario: A scenario that works and should me manual 7 | Meta: 8 | @manual 9 | 10 | Given I have an implemented JBehave scenario 11 | And the scenario works 12 | When I run the scenario 13 | Then I should get a successful result 14 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithManualStory.story: -------------------------------------------------------------------------------- 1 | Narrative: 2 | In order to provide some business value 3 | As a user 4 | I want to perform an action 5 | 6 | Meta: 7 | @manual 8 | Scenario: A scenario that works and should me manual 9 | Given I have an implemented JBehave scenario 10 | And the scenario works 11 | When I run the scenario 12 | Then I should get a successful result 13 | 14 | Scenario: A scenario that works and should me manual too 15 | Given I have an implemented JBehave scenario 16 | And the scenario works 17 | When I run the scenario 18 | Then I should get a successful result 19 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithMultipleFeatures.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @feature a feature 3 | 4 | Scenario: A scenario that works 5 | Meta: 6 | @features another feature, yet another feature 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithMultipleIssues.story: -------------------------------------------------------------------------------- 1 | 2 | 3 | Scenario: Another scenario that works 4 | Meta: 5 | @issues MYPROJ-6,MYPROJ-7 6 | 7 | Given I have an implemented JBehave scenario 8 | And the scenario works 9 | When I run the scenario 10 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithNoTitle.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithOneGivenStoriesBeforeAScenario.story: -------------------------------------------------------------------------------- 1 | Some Behavior 2 | 3 | Narrative: 4 | In order to provide some business value 5 | As a user 6 | I want to perform an action 7 | 8 | GivenStories: stories/samples/GivenSomePrecondition.story 9 | 10 | Scenario: some scenario with givens 11 | 12 | Given a system state 13 | When I do something 14 | Then system is in a different state 15 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithOneStoryAndMultipleIssues.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @issues MYPROJ-8 3 | 4 | Scenario: Another scenario that works 5 | Meta: 6 | @issues MYPROJ-6,MYPROJ-7 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithSeleniumPageObjects.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver htmlunit 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I start on the test page 7 | When I enter a first name 8 | And I enter a last name 9 | Then I should see the and in the names fields 10 | 11 | Examples: 12 | |firstname|lastname| 13 | |Joe | Bloggs| 14 | |John | Doe | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithSeleniumUsingADifferentBrowser.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver chrome 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I type in the first name 8 | And I type in the last name 9 | Then I should see entered values of and 10 | And I should be using chrome 11 | 12 | Examples: 13 | |firstname|lastname| expectedFirstname | expectedLastname | 14 | |Joe | Blanc | Joe | Blanc | 15 | |John | Doe | John | Doe | 16 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithSharedVariables.story: -------------------------------------------------------------------------------- 1 | A story with variable shared between normal step definitions and fixture methods 2 | 3 | Scenario: First scenario 4 | 5 | When a field is initialized to 1 6 | Then it should have a value of 1 7 | 8 | Scenario: Second scenario 9 | 10 | When the same field is incremented 11 | Then it should have a value of 2 -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithSkippedManualScenario.story: -------------------------------------------------------------------------------- 1 | Narrative: 2 | In order to provide some business value 3 | As a user 4 | I want to perform an action 5 | 6 | Scenario: A scenario that works and should be manual 7 | Meta: 8 | @skip 9 | @manual 10 | 11 | Given I have an implemented JBehave scenario 12 | And the scenario works 13 | When I run the scenario 14 | Then I should get a successful result 15 | -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithSpringBeans.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that uses Spring 2 | 3 | Given I hava an autowired Spring bean 4 | When I use the bean 5 | Then it should be instanciated 6 | 7 | Given I hava a nested autowired Spring bean 8 | When I use the nested bean 9 | Then the nested bean should be instanciated -------------------------------------------------------------------------------- /src/test/resources/stories/aBehaviorWithTags.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @tag capability:a capability 3 | 4 | Scenario: A scenario that works 5 | Meta: 6 | @tags domain:a domain, iteration: iteration 1, security 7 | @end-to-end 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/aComplexFailingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that fails 2 | 3 | Given I have a badly implemented JBehave scenario 4 | And the scenario fails 5 | When I run the scenario 6 | Then I should get a failed result 7 | And I should skip subsequent results -------------------------------------------------------------------------------- /src/test/resources/stories/aDataDrivenBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: data-driven scenario 1 2 | 3 | Given a stock of and a threshold of 4 | When the stock is traded at 5 | Then the alert status should be 6 | 7 | Examples: 8 | |symbol|threshold|price|status| 9 | |STK1|10.0|5.0|OFF| 10 | |STK1|11.0|11.0|ON| 11 | |STK1|12.0|12.0|ON| 12 | 13 | Scenario: data-driven scenario 2 14 | 15 | Given a stock of and a threshold of 16 | When the stock is traded at 17 | Then the alert status should be 18 | 19 | Examples: 20 | |symbol|threshold|price|status| 21 | |STK2|13.0|5.0|OFF| 22 | |STK2|14.0|11.0|ON| 23 | |STK2|15.0|12.0|ON| 24 | |STK2|65.0|12gi.0|ON| 25 | 26 | -------------------------------------------------------------------------------- /src/test/resources/stories/aFailingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that fails 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario fails 5 | When I run the scenario 6 | Then I should get a failed result -------------------------------------------------------------------------------- /src/test/resources/stories/aFailingBehaviorWithSelenium.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver htmlunit 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I type in the first name 8 | And I type in the last name 9 | Then I should see entered values of and 10 | 11 | Examples: 12 | |firstname|lastname| expectedFirstname | expectedLastname | 13 | |Joe | Blanc | Jack | Black | 14 | |John | Doe | John | Doe | 15 | -------------------------------------------------------------------------------- /src/test/resources/stories/aFailingDataDrivenBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A data-driven test 2 | Given a stock of and a threshold of 3 | When the stock is traded at 4 | Then the alert status should be 5 | And some other stuff should also work 6 | 7 | Examples: 8 | |symbol|threshold|price|status| 9 | |STK2|10.0|5.0|OFF| 10 | |STK2|11.0|11.0|FAIL| 11 | |STK2|12.0|12.0|ON| 12 | 13 | 14 | Scenario: Buying lots of widgets 15 | Given I want to purchase gizmos 16 | And a gizmo costs 17 | When I order the gizmos 18 | Then I should pay 19 | 20 | Examples: 21 | | amount | cost | total | 22 | | 0 | 10 | 0 | 23 | | -1 | 10 | 10 | 24 | | 2 | 10 | 50 | 25 | | 2 | 0 | 0 | -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehavior.story: -------------------------------------------------------------------------------- 1 | 2 | Scenario: A scenario that works 3 | 4 | Given I have an implemented JBehave scenario 5 | And the scenario works 6 | When I run the scenario 7 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithABeforeClause.story: -------------------------------------------------------------------------------- 1 | 2 | Lifecycle: 3 | Before: 4 | Given a step that is executed before each scenario 5 | 6 | After: 7 | Outcome: ANY 8 | Then a step that is executed after each scenario regardless of outcome 9 | 10 | Scenario: A scenario that works 11 | 12 | Given I have an implemented JBehave scenario 13 | And the scenario fails 14 | When I run the scenario 15 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithALongName.story: -------------------------------------------------------------------------------- 1 | An example of a passing behavior with a long name 2 | 3 | Scenario: A scenario that works 4 | 5 | Given I have an implemented JBehave scenario 6 | And the scenario works 7 | When I run the scenario 8 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithSelenium.story: -------------------------------------------------------------------------------- 1 | !-- Meta: 2 | !-- @driver chrome 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I type in the first name 8 | And I type in the last name 9 | Then I should see entered values of and 10 | 11 | Examples: 12 | |firstname|lastname| expectedFirstname | expectedLastname | 13 | |Joe | Blanc | Joe | Blanc | 14 | |John | Doe | John | Doe | -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithSeleniumAndFirefox.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver phantomjs! 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I type in the first name 8 | And I type in the last name 9 | Then I should see entered values of and 10 | 11 | Examples: 12 | |firstname|lastname| expectedFirstname | expectedLastname | 13 | |Joe | Blanc | Joe | Blanc | 14 | |John | Doe | John | Doe | -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithSeleniumAndSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver phantomjs! 3 | 4 | Scenario: A web scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I enter the first name Jack 8 | Then I should see first name Jack on the screen 9 | 10 | Scenario: A web scenario that uses selenium v2 11 | 12 | Given I am on the test page 13 | When I enter the first name Jill 14 | Then I should see first name Jill on the screen -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result 7 | 8 | Scenario: Another scenario that works 9 | 10 | Given I have an implemented JBehave scenario 11 | And the scenario works 12 | When I run the scenario 13 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithState.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that uses state 2 | 3 | Given I have a field 4 | When I instantiate that field with value RED 5 | Then the field should be set to RED in the following steps 6 | -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingBehaviorWithSteps.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario using steps 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario has steps 5 | When I run the scenario 6 | Then the steps should appear in the outcome -------------------------------------------------------------------------------- /src/test/resources/stories/aPassingWebTestSampleWithNestedSteps.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver chrome! 3 | 4 | Scenario: A scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I type in the first name 8 | And I type in the last name 9 | Then I should see and in the names fields 10 | 11 | Examples: 12 | |firstname|lastname| 13 | |Joe | Blanc | 14 | |John | Doe | -------------------------------------------------------------------------------- /src/test/resources/stories/aPendingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with pending steps 2 | 3 | Given JBehave story with no implementation 4 | When the story is executed 5 | Then the steps should be marked as pending 6 | And sample implementations should be proposed -------------------------------------------------------------------------------- /src/test/resources/stories/aPendingDataDrivenBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: data-driven scenario 1 2 | 3 | Given a stock of and a threshold of 4 | And I need this test to be pending 5 | When the stock is traded at 6 | Then the alert status should be 7 | 8 | Examples: 9 | |symbol|threshold|price|status| 10 | |STK1|10.0|5.0|OFF| 11 | |STK1|11.0|11.0|ON| 12 | |STK1|12.0|12.0|ON| 13 | 14 | Scenario: data-driven scenario 2 15 | 16 | Given a stock of and a threshold of 17 | When the stock is traded at 18 | Then the alert status should be 19 | 20 | Examples: 21 | |symbol|threshold|price|status| 22 | |STK2|10.0|5.0|OFF| 23 | |STK2|11.0|11.0|ON| 24 | |STK2|12.0|12.0|ON| -------------------------------------------------------------------------------- /src/test/resources/stories/aPendingImplementedBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with implemented pending steps 2 | 3 | Given a JBehave story with a pending implementation 4 | When the story is executed 5 | Then the steps should be marked as pending -------------------------------------------------------------------------------- /src/test/resources/stories/aSampleBehaviorForUatOnly.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @environment uat 3 | 4 | Scenario: A scenario that works 5 | Given I have an implemented JBehave scenario 6 | And the scenario works 7 | When I run the scenario 8 | Then I should get a successful result 9 | -------------------------------------------------------------------------------- /src/test/resources/stories/aSecondPassingBehaviorWithState.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that uses state again 2 | 3 | Given I have a field 4 | When I instantiate do not that field 5 | Then the field should not be set -------------------------------------------------------------------------------- /src/test/resources/stories/aSkippedBehavior.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @skip 3 | 4 | Scenario: 1) A scenario that works 5 | 6 | Given I have an implemented JBehave scenario 7 | And the scenario works 8 | When I run the scenario 9 | Then I should get a successful result 10 | 11 | Scenario: 2) A scenario that also works 12 | 13 | Given I have an implemented JBehave scenario 14 | And the scenario works 15 | When I run the scenario 16 | Then I should get a successful result 17 | 18 | -------------------------------------------------------------------------------- /src/test/resources/stories/aSlowBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that runs slowly 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario runs slowly 5 | When I run the scenario 6 | Then the test should time out -------------------------------------------------------------------------------- /src/test/resources/stories/aTaggedPendingBehaviorWithSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @pending 3 | 4 | Scenario: A scenario that works 5 | 6 | Given I have an implemented JBehave scenario 7 | And the scenario works 8 | When I run the scenario 9 | Then I should get a successful result 10 | 11 | Scenario: Another scenario that works 12 | 13 | Given I have an implemented JBehave scenario 14 | And the scenario works 15 | When I run the scenario 16 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aTaggedWIPBehaviorWithSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @wip 3 | 4 | Scenario: A scenario that works 5 | 6 | Given I have an implemented JBehave scenario 7 | And the scenario works 8 | When I run the scenario 9 | Then I should get a successful result 10 | 11 | Scenario: Another scenario that works 12 | 13 | Given I have an implemented JBehave scenario 14 | And the scenario works 15 | When I run the scenario 16 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/aWIPBehavior.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @wip 3 | 4 | Scenario: 1) A scenario that works 5 | 6 | Given I have an implemented JBehave scenario 7 | And the scenario works 8 | When I run the scenario 9 | Then I should get a successful result 10 | 11 | Scenario: 2) A scenario that also works 12 | 13 | Given I have an implemented JBehave scenario 14 | And the scenario works 15 | When I run the scenario 16 | Then I should get a successful result 17 | 18 | -------------------------------------------------------------------------------- /src/test/resources/stories/acceptance_criteria/HandlingJodaStepParameters.story: -------------------------------------------------------------------------------- 1 | Scenario: Convert date times 2 | Given I want to convert string values to Joda DateTime objects 3 | When I pass a DateTime parameter a value of 4 | Then the parameter should be converted to a DateTime with a value of 5 | Examples: 6 | |value | expectedValue | 7 | |31-10-2013 | 2013-10-31 | 8 | |31/10/2013 | 2013-10-31 | 9 | 10 | Scenario: Convert date time lists 11 | Given I want to convert a list of string values to Joda DateTime objects 12 | When I pass a DateTime List parameter a value of 13 | Then the parameter should be converted to a list of DateTimes with values 14 | Examples: 15 | |value | expected | 16 | |31-10-2013 | 2013-10-31 | 17 | |31/10/2013, 21-11-2013 | 2013-10-31, 2013-11-21 | 18 | 19 | Scenario: Convert times 20 | Given I want to convert string values to Joda LocalTime objects 21 | When I pass a LocalTime parameter a value of 22 | Then the parameter should be converted to a LocalTime with a value of 23 | Examples: 24 | |value | expected | 25 | |10:46 | 10:46 | 26 | |14:20 | 14:20 | 27 | 28 | Scenario: Convert lists of times 29 | Given I want to convert string values to Joda LocalTime objects 30 | When I pass a LocalTime List parameter a value of 31 | Then the parameter should be converted to a list of LocalTimes with values 32 | Examples: 33 | |value | expected | 34 | |10:46 | 10:46 | 35 | |10:46,14:20 | 10:46, 14:20 | 36 | 37 | 38 | Scenario: Should convert month-year values 39 | Given I want to convert string values to Joda MonthYear objects 40 | When I pass a YearMonth parameter a value of 41 | Then the parameter should be converted to a YearMonth with a value of 42 | Examples: 43 | |value | expectedValue | 44 | |10-2013 | 2013-10 | 45 | |10/2013 | 2013-10 | 46 | 47 | Scenario: Should convert lists of month-year values 48 | Given I want to convert string values to Joda MonthYear objects 49 | When I pass a list of YearMonth parameter a value of 50 | Then the parameter should be converted to a list of YearMonth with a value of 51 | Examples: 52 | |value | expected | 53 | |10-2013 | 2013-10 | 54 | |10/2013,11/2013 | 2013-10,2013-11 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/test/resources/stories/anotherPassingBehaviorWithSeleniumAndSeveralScenarios.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver phantomjs! 3 | 4 | Scenario: Another web scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I enter the first name Bob 8 | Then I should see first name Bob on the screen 9 | 10 | Scenario: Another web scenario that uses selenium v2 11 | 12 | Given I am on the test page 13 | When I enter the first name Mary 14 | Then I should see first name Mary on the screen -------------------------------------------------------------------------------- /src/test/resources/stories/anotherSlowBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: Another scenario that runs slowly 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario runs slowly 5 | When I run the scenario 6 | Then the test should time out -------------------------------------------------------------------------------- /src/test/resources/stories/another_passing_behavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/behavior_dev_tagged.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @environment dev 3 | @speed fast 4 | @driver phantomjs 5 | 6 | Scenario: A scenario for DEV 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/behavior_test_tagged.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @environment test 3 | @speed fast 4 | @driver phantomjs 5 | 6 | Scenario: A scenario for TEST 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/behavior_uat_tagged.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @environment uat 3 | @speed slow 4 | @driver phantomjs 5 | 6 | Scenario: A scenario for UAT 7 | 8 | Given I have an implemented JBehave scenario 9 | And the scenario works 10 | When I run the scenario 11 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/dataDrivenBehavior.story: -------------------------------------------------------------------------------- 1 | 2 | Scenario: Non-web Data-driven testing from an external CSV file 3 | 4 | Given the data in data/names-data.csv 5 | When we enter this data 6 | Then the values should be correct 7 | -------------------------------------------------------------------------------- /src/test/resources/stories/dataDrivenBehaviorWithSelenium.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver htmlunit 3 | 4 | Scenario: Data-driven testing from an external CSV file 5 | 6 | Given the names in data/names-data.csv 7 | When we enter these values 8 | Then we should see them on the screen 9 | -------------------------------------------------------------------------------- /src/test/resources/stories/failingAndPassingBehaviorsWithSelenium.story: -------------------------------------------------------------------------------- 1 | Meta: 2 | @driver chrome 3 | 4 | Scenario: A failing scenario that uses selenium 5 | 6 | Given I am on the test page 7 | When I enter the first name Joe 8 | And I enter the last name Smith 9 | Then I should see first name Joe on the screen 10 | Then I should see last name Black on the screen 11 | 12 | Scenario: A passing scenario that uses selenium 13 | 14 | Given I am on the test page 15 | When I enter the first name Joe 16 | And I enter the last name Smith 17 | Then I should see first name Joe on the screen 18 | Then I should see last name Smith on the screen 19 | -------------------------------------------------------------------------------- /src/test/resources/stories/precondition/aPreconditionDuckDuckGo.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that opens the DuckDuckGo home page 2 | 3 | Given I want to search for something -------------------------------------------------------------------------------- /src/test/resources/stories/precondition/aPreconditionToFile.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that open start page 2 | 3 | Given I start on the test page -------------------------------------------------------------------------------- /src/test/resources/stories/precondition/aPreconditionToLookUpADefinition.story: -------------------------------------------------------------------------------- 1 | 2 | Scenario: scenario description 3 | Given the user is on the Wikionary home page 4 | -------------------------------------------------------------------------------- /src/test/resources/stories/precondition/aPreconditionToScenario1.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that enter a first name 2 | 3 | When I enter a first name Joe -------------------------------------------------------------------------------- /src/test/resources/stories/precondition/aPreconditionToScenario2.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that enter a last name 2 | 3 | When I enter a last name Bloggs 4 | -------------------------------------------------------------------------------- /src/test/resources/stories/samples/GivenSomeOtherPrecondition.story: -------------------------------------------------------------------------------- 1 | Some Other Preconditions 2 | Scenario: other precondition description 3 | Given some pre-precondition 4 | When I set up my precondition 5 | Then I should be ready for the real test 6 | 7 | Scenario: and another other precondition description 8 | Given some other pre-precondition 9 | When I set up my other precondition 10 | And I do some other stuff 11 | Then I should be even more ready for the real test 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/samples/GivenSomePrecondition.story: -------------------------------------------------------------------------------- 1 | Some Preconditions 2 | Scenario: precondition description 3 | Given some pre-precondition 4 | When I set up my precondition 5 | Then I should be ready for the real test 6 | 7 | Scenario: another precondition description 8 | Given some other pre-precondition 9 | When I set up my other precondition 10 | And I do some other stuff 11 | Then I should be even more ready for the real test 12 | -------------------------------------------------------------------------------- /src/test/resources/stories/samples/SomeBehavior.story: -------------------------------------------------------------------------------- 1 | Some Behavior 2 | 3 | Narrative: 4 | In order to provide some business value 5 | As a user 6 | I want to perform an action 7 | 8 | GivenStories: stories/samples/GivenSomePrecondition.story 9 | 10 | Scenario: some scenario 11 | Given a system state 12 | When I do something 13 | Then system is in a different state -------------------------------------------------------------------------------- /src/test/resources/stories/samples/SomeMoreBehavior.story: -------------------------------------------------------------------------------- 1 | Some Behavior 2 | 3 | Narrative: 4 | In order to provide some business value 5 | As a user 6 | I want to perform an action 7 | 8 | GivenStories: stories/samples/GivenSomePrecondition.story 9 | 10 | Scenario: some scenario with givens 11 | 12 | Given a system state 13 | When I do something 14 | Then system is in a different state -------------------------------------------------------------------------------- /src/test/resources/stories/samples/SomeOtherBehavior.story: -------------------------------------------------------------------------------- 1 | Some Other Behavior 2 | 3 | Narrative: 4 | In order to provide some more business value 5 | As a user 6 | I want to perform another action 7 | 8 | Scenario: some other scenario 9 | Given another system state 10 | When I do something else 11 | Then system is in yet another different state -------------------------------------------------------------------------------- /src/test/resources/stories/smoketests/when_skipping_scenarios.story: -------------------------------------------------------------------------------- 1 | Skipping and Pending scenarios using metadata 2 | 3 | Scenario: 1 Skipping a scenario 4 | Meta: 5 | @skip 6 | Given I want to search for something 7 | When I lookup apple 8 | Then I should see "apple at DuckDuckGo" in the page title 9 | 10 | Scenario: 2 Running a scenario 11 | Meta: 12 | @driver htmlunit 13 | 14 | Given I want to search for something 15 | When I lookup pear 16 | Then I should see "pear at DuckDuckGo" in the page title 17 | 18 | Scenario: 3 A manual scenario 19 | Meta: 20 | @manual 21 | Given I want to search for something 22 | When I lookup apple 23 | Then I should see "apple at DuckDuckGo" in the page title 24 | 25 | Scenario: 4 An ignored scenario 26 | Meta: 27 | @ignore 28 | Given I want to search for something 29 | When I lookup apple 30 | Then I should see "apple at DuckDuckGo" in the page title 31 | 32 | Scenario: 5 Running another scenario 33 | Meta: 34 | @driver htmlunit 35 | 36 | Given I want to search for something 37 | When I lookup pear 38 | Then I should see "pear at DuckDuckGo" in the page title 39 | 40 | Scenario: 6 A pending scenario 41 | Meta: 42 | @pending 43 | Given I want to search for something 44 | When I lookup apple 45 | Then I should see "apple at DuckDuckGo" in the page title 46 | 47 | Scenario: 7 A scenario with no step definitions 48 | Given I want to do something that is undefined 49 | When I lookup apple 50 | Then I should see "apple at DuckDuckGo" in the page title 51 | 52 | Scenario: 8 A scenario marked as skipped with no step definitions 53 | Meta: 54 | @skip 55 | Given I want to do something that is undefined 56 | When I lookup apple 57 | Then I should see "apple at DuckDuckGo" in the page title 58 | 59 | Scenario: 9 A skipped manual scenario 60 | Meta: 61 | @manual 62 | @skip 63 | Given I want to search for something 64 | When I lookup apple 65 | Then I should see "apple at DuckDuckGo" in the page title 66 | -------------------------------------------------------------------------------- /src/test/resources/stories/smoketests/when_using_given_stories_with_web_tests.story: -------------------------------------------------------------------------------- 1 | A scenario that uses lifecycle phases 2 | 3 | GivenStories: stories/precondition/aPreconditionDuckDuckGo.story 4 | 5 | Scenario: Look for apples 6 | When I lookup apple 7 | Then I should see "apple at DuckDuckGo" in the page title 8 | -------------------------------------------------------------------------------- /src/test/resources/stories/smoketests/when_using_lifecycle_steps.story: -------------------------------------------------------------------------------- 1 | A scenario that uses lifecycle phases 2 | 3 | Lifecycle: 4 | Before: 5 | Given I have a calculator 6 | And I add 1 7 | 8 | Scenario: Add a number 9 | When I add 2 10 | Then the total should be 3 11 | -------------------------------------------------------------------------------- /src/test/resources/stories/smoketests/when_using_simple_lifecycle_steps.story: -------------------------------------------------------------------------------- 1 | A scenario that uses lifecycle phases 2 | 3 | Lifecycle: 4 | Before: 5 | Given I have a calculator 6 | And I add 1 7 | 8 | Scenario: Add a number 9 | When I add 2 10 | Then the total should be 3 11 | -------------------------------------------------------------------------------- /src/test/resources/stories/smoketests/when_using_step_libraries.story: -------------------------------------------------------------------------------- 1 | Using Serenity step libraries in Cucumber step definitions 2 | 3 | Scenario: Serenity instantiates step library fields in the Cucumber step definitions 4 | Given I want to use a step library 5 | When I use a step library field annotated with @Steps 6 | Then Serenity should instantiate the field 7 | 8 | Scenario: Serenity instantiates different step libraries for each field by default 9 | Given I want to use several step library fields of the same type 10 | When I use a step library fields to each of them 11 | Then Serenity should instantiate a different library for each field 12 | 13 | Scenario: Serenity preserves the state of a step library instance during a scenario 14 | Given I have a Serenity step library 15 | When I do something with the library 16 | Then the state of the library should be updated 17 | 18 | Scenario: Serenity refreshes the step libraries for each new scenario 19 | Given I have a Serenity step library 20 | When I start a new scenario 21 | Then the step library should be reinitialised 22 | 23 | Scenario: Shared step libraries refer to the same instance 24 | Given I have two Serenity step libraries 25 | When they are annotated with @Steps(shared=true) 26 | Then both should refer to the same instance 27 | -------------------------------------------------------------------------------- /src/test/resources/stories/subset/andAnotherPassingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario that works 2 | 3 | Given I have an implemented JBehave scenario 4 | And the scenario works 5 | When I run the scenario 6 | Then I should get a successful result -------------------------------------------------------------------------------- /src/test/resources/stories/subset/anotherPassingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with groovy steps 2 | 3 | Given a date of 10/16/2010 4 | When 4 days pass 5 | Then the date is 10/18/2010 6 | And some otherwise ambiguous two string step, with one and two as strings 7 | 8 | 9 | Scenario: Another scenario with groovy steps 10 | 11 | Given a date of 10/16/2010 12 | When 4 days pass 13 | Then the date is 10/18/2010 14 | And some otherwise ambiguous two string step, with one and two as strings 15 | 16 | -------------------------------------------------------------------------------- /src/test/resources/stories/subset/yetAnotherPassingBehavior.story: -------------------------------------------------------------------------------- 1 | Scenario: A scenario with groovy steps 2 | 3 | Given a date of 10/16/2010 4 | When 4 days pass 5 | Then the date is 10/18/2010 6 | And some otherwise ambiguous two string step, with one and two as strings 7 | 8 | 9 | Scenario: Another scenario with groovy steps 10 | 11 | Given a date of 10/16/2010 12 | When 4 days pass 13 | Then the date is 10/18/2010 14 | And some otherwise ambiguous two string step, with one and two as strings 15 | 16 | -------------------------------------------------------------------------------- /src/test/resources/thucydides.properties: -------------------------------------------------------------------------------- 1 | environment.variables.are.set=true --------------------------------------------------------------------------------