无法通过junit运行jbehave故事文件

时间:2016-09-22 12:22:12

标签: junit4 jbehave

我正在使用jbehave故事文件和junit来创建自动化测试的框架工作。

PFB:

this is  my story file which is located in src/test/java/com/cdm/story/

这是我运行代码的类文件:

class which extends the junitstories

我已经定义了故事文件的路径,即使然后junit也无法收集故事以供执行。得到这个回应:

org.jbehave.core.io.StoryResourceNotFound: Story path 'ConnectedDevicesManagementPage.story' not found by class loader sun.misc.Launcher$AppClassLoader@2f0e140b
    at org.jbehave.core.io.LoadFromClasspath.resourceAsStream(LoadFromClasspath.java:44)
    at org.jbehave.core.io.LoadFromClasspath.loadResourceAsText(LoadFromClasspath.java:29)
    at org.jbehave.core.io.LoadFromClasspath.loadStoryAsText(LoadFromClasspath.java:38)
    at org.jbehave.core.embedder.PerformableTree.storyOfPath(PerformableTree.java:193)
    at org.jbehave.core.embedder.PerformableTree.addStories(PerformableTree.java:68)
    at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:78)
    at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:203)
    at com.cdm.BrowserFactory.BrowserSelector.storyPaths(BrowserSelector.java:142)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.getStoryPathsFromJUnitStories(JUnitReportingRunner.java:142)
    at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.<init>(JUnitReportingRunner.java:45)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

如果我正在更改故事路径,请按照下面的说明进行操作:

Sep 23, 2016 5:43:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1474632816231   Marionette  INFO    Listening on port 53647
Sep 23, 2016 5:43:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,threads=1]

(BeforeStories)


(AfterStories)

Generating reports view to 'C:\Users\CMD_AUTOMATION\CDM_AUTOMATIOM\target\jbehave' using formats '[stats, console, txt, junitscenarioreporter]' and view properties '{reports=ftl/jbehave-reports-with-totals.ftl, decorateNonHtml=true}'
Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)

我已经坚持了两天,从谷歌尝试很多东西,但无法解决它..请帮助我解决这个问题。

1 个答案:

答案 0 :(得分:0)

首先,将jbehave核心从4.0更新到4.0.5,因为junit runner使用反射来完成工作。

然后,在你的storyPaths方法中,不需要调用embedder.runStoriesAsPaths,它将从run方法中调用。

只需在storyPaths方法中添加:

@Override
public List<String> storyPaths() {
    List<String> stories = new StoryFinder().findPaths(
            codeLocationFromClass(this.getClass()), "**/*.story", "**/excluded*.story");
    return stories;
}