Java Jbehave无法定位多个楼层

Java Jbehave无法定位多个楼层,java,eclipse,maven,selenium,jbehave,Java,Eclipse,Maven,Selenium,Jbehave,我在eclipse中有一个使用maven的Jbehave和selenium项目。最初我是为了一个故事而做的,但现在我已经写了两个故事,我希望这两个故事可以在测试中运行。但是程序只定位一个故事文件。我如何定位文件夹资源中的所有故事文件 这是到目前为止我的代码 Google.java public class Google extends JUnitStory { @Override public Configuration configuration(){ return new Most

我在eclipse中有一个使用maven的Jbehave和selenium项目。最初我是为了一个故事而做的,但现在我已经写了两个故事,我希望这两个故事可以在测试中运行。但是程序只定位一个故事文件。我如何定位文件夹资源中的所有故事文件

这是到目前为止我的代码 Google.java

public class Google extends JUnitStory {
@Override 
public Configuration configuration(){
    return new MostUsefulConfiguration().useStoryLoader(
        new LoadFromClasspath(this.getClass()))
        .useStoryReporterBuilder(
            new StoryReporterBuilder().withCodeLocation(
                CodeLocations.codeLocationFromClass(this
                    .getClass())).withFormats(    
                Format.CONSOLE, Format.TXT, Format.HTML, Format.STATS))
                ;    
}

@Override 
public List<CandidateSteps> candidateSteps(){
    return new InstanceStepsFactory(configuration(), 
        new GoogleStep()) //can put in a comma separated list of Step implementers here
        .createCandidateSteps();
}
protected List<String> storyPaths(){
   return new StoryFinder().findPaths(
        CodeLocations.codeLocationFromClass(this.getClass()), 
        "*.story", "");
公共类Google扩展JUnitStory{
@凌驾
公共配置(){
返回新的mostuseveConfiguration().useStoryLoader(
新建LoadFromClasspath(this.getClass())
.useStoryReporterBuilder(
使用CodeLocation新建StoryReporterBuilder()(
codeLocationFromClass(此
.getClass())。格式为(
Format.CONSOLE、Format.TXT、Format.HTML、Format.STATS)
;    
}
@凌驾
公开名单{
返回新InstanceStepsFactory(配置(),
new GoogleStep())//可以在此处输入以逗号分隔的步骤实现者列表
.createCandidateSteps();
}
受保护的列表故事路径(){
返回新的StoryFinder().FindPath(
CodeLocations.codeLocationFromClass(this.getClass()),
“*.故事”、”);
GoogleStep.java

public class GoogleStep {

private WebDriver driver;
private FluentWait<WebDriver> fWait;

public GoogleStep() {
    System.setProperty("webdriver.gecko.driver","C:\\Program Files\\GeckoDriver\\geckodriver.exe");
    File pathToBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");

    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);

    FirefoxOptions options = new FirefoxOptions();
    options.setCapability("moz:firefoxOptions", options.setBinary(ffBinary));
    WebDriver driver2 = new FirefoxDriver(options);
    driver = driver2;

    fWait = new FluentWait<WebDriver>(driver).pollingEvery(500, 
        TimeUnit.MILLISECONDS).withTimeout(10,  TimeUnit.SECONDS);

    }

//Google Mapping

@Given("I navigate to google.lk")
public void navigateToGoogle(){
    driver.get("https://www.google.lk/");
    fWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("lst-ib")));
}

@When("I perform a google search for $query")
public void performASearchForGoogleQuery(String query){
    driver.findElement(By.id("lst-ib")).sendKeys(query);
}

@Then("I click google Search Button")
public void clickSearchGoogleButton() {
    driver.findElement(By.xpath("//input[@value='Google Search']")).click();
}

@Then("A google link $text exists in the results")
public void linkContainingTextExistsInTheGoogleResults(String resultText){
    driver.getPageSource().contains(resultText);
}

//yahoo mapping

@Given("I navigate to yahoo.com")
public void navigateToYahoo(){
    driver.get("https://www.yahoo.com/");
    fWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("uh-search-box")));
}

@When("I perform a yahoo search for $query")
public void performASearchForYahooQuery(String query){
    driver.findElement(By.id("uh-search-box")).sendKeys(query);
}

@Then("I click yahoo Search Button")
public void clickSearchYahooButton() {
    driver.findElement(By.xpath("//*[@id='uh-search-button']")).click();
}

@Then("A yahoo link $text exists in the results")
public void linkContainingTextExistsInTheYahooResults(String resultText){
    driver.getPageSource().contains(resultText);
}
public类GoogleStep{
私有网络驱动程序;
私人FluentWait fWait;
公共谷歌步骤(){
System.setProperty(“webdriver.gecko.driver”,“C:\\Program Files\\GeckoDriver\\GeckoDriver.exe”);
File pathToBinary=新文件(“C:\\Program Files\\Mozilla Firefox\\Firefox.exe”);
FirefoxBinary ffBinary=新的FirefoxBinary(路径二进制);
FirefoxOptions=新的FirefoxOptions();
options.setCapability(“moz:firefoxOptions”,options.setBinary(ffBinary));
WebDriver driver2=新的FirefoxDriver(选项);
驾驶员=驾驶员2;
fWait=新FluentWait(驱动程序)。轮询间隔(500,
TimeUnit.ms)。带超时(10,TimeUnit.s);
}
//谷歌地图
@给定(“我导航到google.lk”)
public void navigateToGoogle(){
驱动程序。获取(“https://www.google.lk/");
等待至(预期条件。被定位元素的可视性(通过id(“lst ib”));
}
@当(“我在谷歌上搜索$query”)
public void performASearchForGoogleQuery(字符串查询){
driver.findElement(By.id(“lst ib”)).sendKeys(查询);
}
@然后(“我点击谷歌搜索按钮”)
公共作废clickSearchGoogleButton(){
findElement(By.xpath(“//input[@value='googlesearch']))。单击();
}
@然后(“结果中存在谷歌链接$text”)
Google结果(字符串resultText)中包含文本的公共无效链接{
driver.getPageSource()包含(resultText);
}
//雅虎地图
@给定(“我导航到yahoo.com”)
public void navigateToYahoo(){
驱动程序。获取(“https://www.yahoo.com/");
fWait.until(预期条件。找到的元素的可视性(通过.id(“uh搜索框”));
}
@当(“我对$query执行雅虎搜索”)
public void performasearcholyahoquery(字符串查询){
driver.findElement(By.id(“uh搜索框”)).sendKeys(查询);
}
@然后(“我点击雅虎搜索按钮”)
公共作废clickSearchYahooButton(){
driver.findelelement(By.xpath(“/*[@id='uh-search-button'])。单击();
}
@然后(“结果中存在雅虎链接$text”)
在YahooResults(字符串resultText)中包含文本存在的公共无效链接{
driver.getPageSource()包含(resultText);
}
我有两个故事文件名为google.story和yahoo.story

我的文件夹结构如下

我做错了什么,或者我必须做什么?任何帮助都会非常有用。

以下是我的做法:

@Override
protected List<String> storyPaths() {

    URL searchLoc = CodeLocations.codeLocationFromClass(this.getClass());

    return new StoryFinder().findPaths(searchLoc, Arrays.asList("**/google.story",
                                                                "**/yahoo.story",
                                                                ""),
                                                  Arrays.asList("**/excluded*.story"));

}

将只运行google.story。

发现我做错了什么。我是从JUnitStory扩展类的。JUnitStory类不允许您重写storyPath方法。但要运行多个故事,我必须从JUnitStories扩展它并重写storyPath方法。这样做解决了我的问题。再次感谢比尔的回答。

t感谢你的回答@Bill Hileman。但我这样尝试了,它仍然只运行谷歌故事。无法找出背后的原因。猜猜为什么会发生这种情况?我的testrunner还扩展了JUnitStories。我不知道有一个单一版本(JUnitStory)我知道不要再做那种假设了。谢谢分享你的更新。
    return new StoryFinder().findPaths(searchLoc, Arrays.asList("**/google.story",
                                                                //"**/yahoo.story",
                                                                ""),
                                                  Arrays.asList("**/excluded*.story"));