我是JBehave的新手,我试图从URL加载Jbehave故事。为了做到这一点,我将我的故事托管到Tomcat服务器上。
我的文件存在于Stories文件夹的桌面上,我编辑了server.xml来托管静态文件并使用url访问它们。例如,我可以使用此网址 http://localhost:8080/static/divide.story
查看我的divide.story我的 divide.story 是
Feature: calculation divide
Narrative:
As a user
I want to perform an action
So that I can achieve a business goal
Scenario: divide by 2
Given a variable x having value 2
When I divide x by 2
Then result should be 1
Scenario: divide by 3
Given a variable x is 3
When I add x with 3
Then result would be 6
我的配置文件是这样的
import static java.util.Arrays.asList;
import static org.jbehave.core.io.CodeLocations.codeLocationFromURL;
import static org.jbehave.core.reporters.Format.CONSOLE;
import static org.jbehave.core.reporters.Format.HTML;
import static org.jbehave.core.reporters.Format.TXT;
import static org.jbehave.core.reporters.Format.XML;
import java.text.SimpleDateFormat;
import java.util.List;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.failures.FailingUponPendingStep;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromRelativeFile;
import org.jbehave.core.io.LoadFromURL;
import org.jbehave.core.io.StoryLoader;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.parsers.gherkin.GherkinStoryParser;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.PrintStreamStepdocReporter;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.ParameterConverters;
import org.jbehave.core.steps.SilentStepMonitor;
import org.jbehave.core.steps.spring.SpringStepsFactory;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { ApplicationToTest.class})
public class RemoteStory extends JUnitStories{
@Autowired
private ApplicationContext applicationContext;
public RemoteStory(){
doConfig();
}
public void doConfig(){
Class<?> thisClass = this.getClass();
useConfiguration(new MostUsefulConfiguration()
.useStoryLoader(new LoadFromURL())
.usePendingStepStrategy(new FailingUponPendingStep())
.useStepdocReporter(new PrintStreamStepdocReporter())
.useStoryReporterBuilder(
new StoryReporterBuilder()
.withCodeLocation(CodeLocations.codeLocationFromURL("http://localhost:8080/static/"))
// .withCodeLocation(CodeLocations.codeLocationFromClass(thisClass))
.withDefaultFormats()
.withFormats(Format.CONSOLE,Format.TXT, Format.HTML, Format.XML, Format.STATS)
.withCrossReference(new CrossReference())
.withFailureTrace(true))
.useParameterConverters(new ParameterConverters()
.addConverters(new ParameterConverters.DateConverter(new SimpleDateFormat("yyyy-MM-dd"))))
.useStoryParser(new GherkinStoryParser())
.useStepMonitor(new SilentStepMonitor()));
}
@Override
public InjectableStepsFactory stepsFactory() {
return new SpringStepsFactory(configuration(), applicationContext);
}
@Override
protected List<String> storyPaths() {
// Specify story paths as remote URLs
String codeLocation = CodeLocations.codeLocationFromURL("http://localhost:8080/static/").toString();
return asList(codeLocation + "*.story");
}
执行后我得到的错误如下:
2016-02-12 14:57:30.106 INFO 5216 --- [ main] com.atul.steps.RemoteStory : Starting RemoteStory on dluarai1350280 with PID 5216 (D:\Jbehave\Learn\TestGradle\bin started by arai13 in D:\Jbehave\Learn\TestGradle)
2016-02-12 14:57:30.107 INFO 5216 --- [ main] com.atul.steps.RemoteStory : No active profile set, falling back to default profiles: default
2016-02-12 14:57:30.156 INFO 5216 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7161d8d1: startup date [Fri Feb 12 14:57:30 IST 2016]; root of context hierarchy
2016-02-12 14:57:31.800 INFO 5216 --- [ main] org.eclipse.jetty.util.log : Logging initialized @2654ms
2016-02-12 14:57:31.884 INFO 5216 --- [ main] com.atul.steps.RemoteStory : Started RemoteStory in 2.066 seconds (JVM running for 2.741)
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,failOnStoryTimeout=false,threads=1]
Generating reports view to 'http:\localhost:8080\jbehave' using formats '[stats, console, txt, html, xml, stats]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports-with-totals.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
Failed to generate reports view to 'http:\localhost:8080\jbehave' using formats '[stats, console, txt, html, xml, stats]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports-with-totals.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
2016-02-12 14:57:31.951 INFO 5216 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7161d8d1: startup date [Fri Feb 12 14:57:30 IST 2016]; root of context hierarchy
java.io.FileNotFoundException: http:\localhost:8080\jbehave\storyDurations.props (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at org.jbehave.core.reporters.TemplateableViewGenerator.storyDurations(TemplateableViewGenerator.java:123)
at org.jbehave.core.reporters.TemplateableViewGenerator.generateReportsView(Temp lateableViewGenerator.java:115)
at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:249)
at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:237)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:213)
at org.jbehave.core.junit.JUnitStories.run(JUnitStories.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
现在我的问题是我正在做的错误导致了这个错误。任何人都可以帮我解决这个错误,或者为我提供正确的代码来访问任何地方保存的故事。