Reputation: 65
I have a Jbehave and selenium project in eclipse using maven.initially i was doing it for one story but now i have written two stories and i want that two stories to be run in tests.but only one story file is locating by the program.how can i locate all the story files in the folder resources?
here is my code so far 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", "");
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);
}
And i have two story files named as google.story and yahoo.story
my folder structure is as follows
What am i doing wrong here or what i have to do?any help would be very helpful.
Upvotes: 1
Views: 285
Reputation: 65
Found out what was i doing wrong.I was extending the class from JUnitStory.JunitStory class doesn't allow you to override storyPath method.but for running multiple stories i have to extend it from JUnitStories and override Storypath method.Doing this Solved my problem.Thank you bill for your answer again.
Upvotes: 1
Reputation: 2838
Here's how I do it:
@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"));
}
The extra element in the first array list is probably not necessary, but I include it because the example I originally got my information from did it that way, but I can add several stories this way, just add more elements for each new story, and if I want to make a run of just one story, I can precede each story I don't want to run with comment double-slashes (//) i.e.
return new StoryFinder().findPaths(searchLoc, Arrays.asList("**/google.story",
//"**/yahoo.story",
""),
Arrays.asList("**/excluded*.story"));
Would only run google.story.
Upvotes: 1