2016-09-22 55 views
-1

我正在爲使用jbehave故事文件和junit運行它進行自動化測試創建框架工作。無法通過junit運行jbehave故事文件

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 [email protected] 
    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) 

如果我改變了storypath如下然後在控制檯得到這個:

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) 

我都堅持這個從兩天嘗試很多東西,從谷歌,但無法解決它呢..請幫助我解決這個問題。

回答

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; 
}