Jbehave(2)Some Improvement and POM changes

Jbehave(2)Some Improvement and POM changes

I design the Jbehave project at first. And my colleagues have some new idea about that and he made some changes to that.

First one is about how to run Jbehave, before, I configure annotation and spring configuration in my project. Right now he has cleaned up them.

The JUnit class which can be run in eclipse is as follow:
package com.easybddweb.vendors.baidu;
import static java.util.Arrays.asList;
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
import java.util.ArrayList;
import java.util.List;
import org.jbehave.core.io.StoryFinder;
import com.easybddweb.core.story.WebsiteStory;

public class BaiduStories extends WebsiteStory {
     protected List<String> storyPaths() {
          List<String> list = new StoryFinder().findPaths(
                    codeLocationFromClass(this.getClass()).getFile(),
                    asList("**/baidu/*.story"), null);
          return list;
     }
     @Override
     protected List<Object> getStepsInstances() {
          BaiduSteps steps = new BaiduSteps(super.getFirefoxWebDriverProvider());
          List<Object> list = new ArrayList<Object>();
          list.add(steps);
          return list;
     }
}

And the basic class used here is as follow:
package com.easybddweb.core.story;
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
import static org.jbehave.core.reporters.Format.CONSOLE;
import static org.jbehave.web.selenium.WebDriverHtmlOutput.WEB_DRIVER_HTML;
import java.util.List;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.embedder.StoryControls;
import org.jbehave.core.failures.FailingUponPendingStep;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.CandidateSteps;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.web.selenium.ContextView;
import org.jbehave.web.selenium.FirefoxWebDriverProvider;
import org.jbehave.web.selenium.LocalFrameContextView;
import org.jbehave.web.selenium.SeleniumConfiguration;
import org.jbehave.web.selenium.SeleniumContext;
import org.jbehave.web.selenium.SeleniumContextOutput;
import org.jbehave.web.selenium.SeleniumStepMonitor;
import org.jbehave.web.selenium.WebDriverProvider;

public abstract class WebsiteStory extends JUnitStories {

     CrossReference crossReference = new CrossReference().withJsonOnly()
               .withOutputAfterEachStory(true)
               .excludingStoriesWithNoExecutedScenarios(true);
     ContextView contextView = new LocalFrameContextView().sized(500, 100);
     SeleniumContext seleniumContext = new SeleniumContext();
     SeleniumStepMonitor stepMonitor = new SeleniumStepMonitor(contextView,
               seleniumContext, crossReference.getStepMonitor());
     Format[] formats = new Format[] {
               new SeleniumContextOutput(seleniumContext), CONSOLE,
               WEB_DRIVER_HTML };
     StoryReporterBuilder reporterBuilder = new StoryReporterBuilder()
               .withCodeLocation(codeLocationFromClass(this.getClass()))
               .withFailureTrace(true).withFailureTraceCompression(true)
               .withDefaultFormats().withFormats(formats)
               .withCrossReference(crossReference);

     public Configuration configuration() {
          return new SeleniumConfiguration()
                    .useSeleniumContext(seleniumContext)
                    .useFailureStrategy(new FailingUponPendingStep())
                    .useStoryControls(
                              new StoryControls().doResetStateBeforeScenario(false))
                    .useStepMonitor(stepMonitor)
                    .useStoryLoader(new LoadFromClasspath(this.getClass()))
                    .useStoryReporterBuilder(reporterBuilder);
     }

     public List<CandidateSteps> candidateSteps() {
          return new InstanceStepsFactory(configuration(), getStepsInstances())
                    .createCandidateSteps();
     }

     protected abstract List<Object> getStepsInstances();

     protected WebDriverProvider getFirefoxWebDriverProvider() {
          return new FirefoxWebDriverProvider();
     }

}

And he also have some new idea about how to run the story. For example, if I want to select only baidu stories. I can use MAVEN2 command like this:
>mvn clean install -Pbaidu

The related maven2 configuration in pom.xml is as follow:
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"]] >
<modelVersion]] > 4.0.0</modelVersion]] >
<groupId]] > com.sillycat.easybddweb</groupId]] >
<artifactId]] > easybddweb</artifactId]] >
<name]] > easybddweb</name]] >
<version]] > 1.0</version]] >




<properties]] >
<jbehave.core.version]] > 3.5.4</jbehave.core.version]] >
<jbehave.web.version]] > 3.4.3</jbehave.web.version]] >
<jbehave.site.version]] > 3.1.1</jbehave.site.version]] >
<selenium.version]] > 2.17.0</selenium.version]] >
<ignore.failures]] > false</ignore.failures]] >
<meta.filter></meta.filter]] >
<threads]] > 1</threads]] >
<skip]] > false</skip]] >
<stories]] > **/*Stories.java</stories]] >
</properties]] >


<build]] >
<pluginManagement]] >
<plugins]] >
<plugin]] >
<groupId]] > org.apache.maven.plugins</groupId]] >
<artifactId]] > maven-compiler-plugin</artifactId]] >
<version]] > 2.3.2</version]] >
<configuration]] >
<source]] > 1.6</source]] >
<target]] > 1.6</target]] >
</configuration]] >
</plugin]] >
</plugins]] >
</pluginManagement]] >
<resources]] >
<resource]] >
<directory]] > ${basedir}/src/main/resources</directory]] >
<filtering]] > false</filtering]] >
</resource]] >
<resource]] >
<directory]] > ${basedir}/src/main/stories</directory]] >
<filtering]] > false</filtering]] >
</resource]] >
</resources]] >
<plugins]] >
<plugin]] >
<groupId]] > org.jbehave</groupId]] >
<artifactId]] > jbehave-maven-plugin</artifactId]] >
<version]] > ${jbehave.core.version}</version]] >
<executions]] >
<execution]] >
<id]] > unpack-view-resources</id]] >
<phase]] > process-resources</phase]] >
<goals]] >
<goal]] > unpack-view-resources</goal]] >
</goals]] >
</execution]] >
<execution]] >
<id]] > embeddable-stories</id]] >
<phase]] > integration-test</phase]] >
<configuration]] >
<includes]] >
<include]] > ${stories}</include]] >
</includes]] >
<excludes/>
<generateViewAfterStories]] > true</generateViewAfterStories]] >
<ignoreFailureInStories]] > ${ignore.failures}</ignoreFailureInStories]] >
<ignoreFailureInView]] > ${ignore.failures}</ignoreFailureInView]] >
<threads]] > ${threads}</threads]] >
<skip]] > ${skip}</skip]] >
<metaFilters]] >
<metaFilter]] > ${meta.filter}</metaFilter]] >
</metaFilters]] >
</configuration]] >
<goals]] >
<goal]] > run-stories-as-embeddables</goal]] >
</goals]] >
</execution]] >
<execution]] >
<id]] > report-stepdocs</id]] >
<phase]] > integration-test</phase]] >
<configuration]] >
<includes]] >
<include]] > ${stories}</include]] >
</includes]] >
</configuration]] >
<goals]] >
<goal]] > report-stepdocs-as-embeddables</goal]] >
</goals]] >
</execution]] >
</executions]] >
</plugin]] >
</plugins]] >
</build]] >



<dependencies]] >
<!-- Jackson -->
<dependency]] >
<groupId]] > org.codehaus.jackson</groupId]] >
<artifactId]] > jackson-mapper-asl</artifactId]] >
<version]] > 1.9.5</version]] >
</dependency]] >

<!-- JBehave -->
<dependency]] >
<groupId]] > org.jbehave</groupId]] >
<artifactId]] > jbehave-core</artifactId]] >
<version]] > ${jbehave.core.version}</version]] >
<classifier]] > resources</classifier]] >
<type]] > zip</type]] >
</dependency]] >


<dependency]] >
<groupId]] > org.jbehave.site</groupId]] >
<artifactId]] > jbehave-site-resources</artifactId]] >
<version]] > ${jbehave.site.version}</version]] >
<type]] > zip</type]] >
</dependency]] >


<dependency]] >
<groupId]] > org.jbehave.web</groupId]] >
<artifactId]] > jbehave-web-selenium</artifactId]] >
<version]] > ${jbehave.web.version}</version]] >
<exclusions]] >
<exclusion]] >
<groupId]] > org.seleniumhq.selenium</groupId]] >
<artifactId]] > selenium-java</artifactId]] >
</exclusion]] >
</exclusions]] >
</dependency]] >


<dependency]] >
<groupId]] > org.seleniumhq.selenium.fluent</groupId]] >
<artifactId]] > fluent-selenium</artifactId]] >
<version]] > 1.0-beta-4</version]] >
<optional]] > true</optional]] >
<exclusions]] >
<exclusion]] >
<groupId]] > org.seleniumhq.selenium</groupId]] >
<artifactId]] > selenium-java</artifactId]] >
</exclusion]] >
</exclusions]] >
</dependency]] >


<dependency]] >
<groupId]] > org.seleniumhq.selenium</groupId]] >
<artifactId]] > selenium-java</artifactId]] >
<version]] > ${selenium.version}</version]] >
</dependency]] >


<dependency]] >
<groupId]] > org.jbehave</groupId]] >
<artifactId]] > jbehave-spring</artifactId]] >
<version]] > ${jbehave.core.version}</version]] >
</dependency]] >


<dependency]] >
<groupId]] > org.hamcrest</groupId]] >
<artifactId]] > hamcrest-core</artifactId]] >
<version]] > 1.3.RC2</version]] >
</dependency]] >


<!-- HTTP Apache dependencies -->
<dependency]] >
<groupId]] > org.apache.httpcomponents</groupId]] >
<artifactId]] > httpclient</artifactId]] >
<version]] > 4.1.3</version]] >
</dependency]] >
</dependencies]] >

<profiles]] >
<!-- Story for each website -->
<profile]] >
<!-- baidu -->
<id]] > baidu</id]] >
<properties]] >
<stories]] > **/baidu/*Stories.java</stories]] >
</properties]] >
</profile]] >
<profile]] >
<!-- google -->
<id]] > nba</id]] >
<properties]] >
<stories]] > **/google/*Stories.java</stories]] >
</properties]] >
</profile]] >


</profiles]] >

</project]] >

And this project will be host on easybddweb project in version 2.0.
The project in my dropbox is as follow:
>tar zcvf easybddweb.tar.gz easybddweb
>tar zxvf easybddweb.tar.gz
references:

你可能感兴趣的:(change)