Coming from Rails/cucumber I am very pleased to find JBehave in the Java world
:-)
I am trying to get my JBehave 3/Selenium tests running, but weird things happen
with selenium (startup). selenium starts up BUT weird URLS (file paths) are
being sent. I have "plain" selenium test (SeleneseTestCase) which run, i.e.
selenium et al are setup correctly.
I guess it has to do with the @BeforeStory/@AfterStory...?
I have
i_can_login.story:
-------------------
Scenario: User can login
Given nobody is logged in
When I login as 'clemens' with password 'pw'
Then I should see 'Clemens Wyss'
ICanLogin.java:
------------------
package ch.mysign.integrationtests;
import org.jbehave.core.JUnitStory;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.UnderscoredCamelCaseResolver;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.junit.Test;
public class ICanLogin extends JUnitStory
{
public ICanLogin ()
{
ClassLoader classLoader = this.getClass().getClassLoader();
Configuration configuration = new MostUsefulConfiguration()
.useStoryPathResolver(new UnderscoredCamelCaseResolver(".story"))
.useStoryLoader( new LoadFromClasspath(classLoader) )
.useStoryReporterBuilder(new StoryReporterBuilder()
.withDefaultFormats()
.withFailureTrace(false)
);
useConfiguration(configuration);
addSteps( new InstanceStepsFactory( configuration, new SeleniumLoginSteps() )
.createCandidateSteps() ); // varargs, can have lots of steps
}
@Test
public void runScenario () throws Throwable
{
super.run();
}
}
SeleniumLoginSteps.java:
----------------------------
package ch.mysign.integrationtests;
import junit.framework.Assert;
import org.jbehave.core.annotations.AfterStory;
import org.jbehave.core.annotations.BeforeStory;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.web.selenium.SeleniumPerStorySteps;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class SeleniumLoginSteps extends SeleniumPerStorySteps
{
static int EMBEDDED_TOMCAT_PORT = 8080;
static int SELENIUM_PORT = 4444;
private Selenium selenium = null;
@BeforeStory
public void setupSelenium()
{
selenium = new DefaultSelenium( "localhost", SELENIUM_PORT, "*iexplore",
"http://localhost:" + EMBEDDED_TOMCAT_PORT + "/" );
selenium.start();
}
@AfterStory
public void tearDownSelenium()
{
selenium.close();
}
@Given("nobody is loged in")
public void nobodyIsLoggedIn()
{
AdminLoginPage.logout( selenium );
}
@When("I login as '$username' with password '$password'")
public void loginAs(String username, String password)
{
AdminLoginPage.loginAs( selenium, username, password );
}
@Then("I should see '$seen'")
public void iShouldSee(String seen)
{
Assert.assertTrue( selenium.isTextPresent( seen ) );
}
}
----------
I also looked (and adapted)
http://jbehave.org/reference/latest/running-stories.html, but this code does
not compile (StoryFinder, asList, storyClass).
So my question is: can anybody provide a JBehave 3/Selenium example which for
example makes a google search?
Thx in advance
Clemens
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email