Hi Julien,
I found the root cause. In your Home class, you're trying to get the
WebDriver instance in the constructor:
public class Home extends AbstractPage {
private final WebDriver driver;
public Home(WebDriverProvider driverProvider) {
super(driverProvider);
this.driver = driverProvider.get();
}
public void doRegister() {
driver.findElement(By.name("member.doRegister")).submit();
}
}
This is not the way the WebDriverProvider is meant to work. Instead, you
should keep a reference of the provider and invoke the get() method
every time you need it.
public class Home extends AbstractPage {
private WebDriverProvider driverProvider;
public Home(WebDriverProvider driverProvider) {
super(driverProvider);
this.driverProvider = driverProvider;
}
public void doRegister() {
driverProvider.get().findElement(By.name("member.doRegister")).submit();
}
}
The reason is that at instantiation of the class the DriverProvider has
not been initialised.
Please raise a documentation JIRA issue so we can explain it in more
detail for the benefit of others.
Cheers
On 17/02/2013 13:00, Mauro Talevi wrote:
The cause is that (most often) it's not set properly in the first
place. Normally, this happens in the @BeforeScenario/Story annotated
methods (in the PerScenario/StoryWebDriverSteps).
I notice you're using a mixed setup (@UsingSpring and @UsingSteps).
That may well get the DI injection confused. Otherwise, please debug
and check that the PerStoryWebDriverSteps class is instanciated and
the @Before method is invoked before the running of the stories.
Try using only one, e.g. the spring one. I'll investigate further.
Cheers
On 16/02/2013 18:41, Julien Martin wrote:
Still no luck with this issue....
I think I found the relevant code that causes the error:
public WebDriver get() {
WebDriver webDriver = delegate.get();
if (webDriver == null) {
throw new DelegateWebDriverNotFound();
}
return webDriver;
}
In my case the local variable webDriver is null! Now I would be very grateful
if someone told me what could cause the Threalocal delegate to return null in
the first place?
Regards,
Julien.
2013/2/12 Mauro Talevi <[email protected]
<mailto:[email protected]>>
Yes please send me the project.
On 12 Feb 2013, at 21:14, Julien Martin <[email protected]
<mailto:[email protected]>> wrote:
Hi Mauro,
Thanks for your reply. I am sorry I can't provide a code on
github. However, I can send a zipped maven project to your email
if you wish.
As far as the extra steps are concerned, I removed the steps
with the @BeforeScenario and it does not make any difference. I
am really not sure where the problem comes from...
Let me know if I can mail you the maven project.
Regards,
Julien.
2013/2/12 Mauro Talevi <[email protected]
<mailto:[email protected]>>
I've not been able to investigate your problem as I would
need to first reproduce it. This is why I was asking for a
fork on github where we could reproduce and investigate it.
WRT your questions:
1. the issue is most likely in the extra
@BeforeScenario/Story steps that you've defined. The
WebDriver is set in the PerScenario/StoryWebDriverSteps
annotated methods
2. it's got nothing to do with the location of the
java/story files.
On 12/02/2013 16:41, Julien Martin wrote:
Hi Mauro!
My codebase is actually slightly different from the one
described in the JIRA. I do get the same error message
though...
I've spent the best of the day trying to figure out the
difference between my codebase and that of the maven
archetype (spring+web) which does work fine. To no avail.
I have two questions:
1. By looking at the code provided in my prior email, can
you spot something wrong?
2. Can you tell me whether all my JBehave code (java files,
story files) should be located in src/main/ or src/test?
Regards,
Julien.
2013/2/12 Mauro Talevi <[email protected]
<mailto:[email protected]>>
I've commented on it.
Same advice to you:
Would it be possible for you to clone the
jbehave-tutorial in github and provide your
modifications in different branches?
In this way, it's much easier to see what changing wrt
to a working scenario to work with an easily
reproducible codebase.
Cheers
On 12/02/2013 14:28, Julien Martin wrote:
Hi,
I noticed someone has encountered the same problem.
See here: http://jira.codehaus.org/browse/JBEHAVE-790
Any update on this issue?
Julien.
2013/2/11 Julien Martin <[email protected]
<mailto:[email protected]>>
Hello,
I am trying to set up a JBehave + Spring based on
the Etsy samples.
However, here is what I get when I run the stories:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'steps' defined in
class path resource [META-INF/spring/steps.xml]:
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class
[com.bignibou.bdd.steps.WebSteps]: Constructor
threw exception; nested exception is
org.jbehave.web.selenium.DelegatingWebDriverProvider$DelegateWebDriverNotFound:
WebDriver has not been found for this thread.
Please verify you are using the correct
WebDriverProvider, with the appropriate
credentials if using remote access, e.g. to
SauceLabs: -DSAUCE_USERNAME=xxxxxx
-DSAUCE_ACCESS_KEY=xxx-xxxx-xxxx-xxxx-xxx
Can anyone please help?
Regards,
Julien.
Here is my Stories source:
@RunWith(SpringAnnotatedEmbedderRunner.class)
@Configure()
@UsingEmbedder(embedder = Embedder.class,
generateViewAfterStories = true,
ignoreFailureInStories = true, ignoreFailureInView
= true)
@UsingSpring(resources = {
"classpath:META-INF/spring/applicationContext.xml",
"classpath:META-INF/spring/steps.xml"
})
@UsingSteps(instances = { WebSteps.class })
public class SpringWebStories extends
InjectableEmbedder {
@Test
public void run() {
injectedEmbedder().runStoriesAsPaths(storyPaths());
}
protected List<String> storyPaths() {
String searchInDirectory =
CodeLocations.codeLocationFromPath("src/test/java").getFile();
return new
StoryFinder().findPaths(searchInDirectory,
Arrays.asList("**/*.story"), null);
}
}
Here is my WebSteps source:
public class WebSteps {
@Autowired
private JavaMailSender javaMailSender;
private Home home;
public WebSteps(PageFactory factory) {
this.home = factory.home();
}
@Given("the following email address: $email and a
chosen member status of $status and the following
password: $password")
public void anonymousVisitorEntersDetails(String
email, String status, String password) {
System.out.println("instance:" + javaMailSender);
home.open();
home.enterDetails(email, status, password);
}
@When("the anonymous visitor signs up")
public void anonymousVisitorDoesRegister(String
login, String password) {
home.doRegister();
}
@Then("a confirmation email with activation
information is sent to the anonymous visitor")
public void activationInformationIsSent() {
}
...
Here is my steps.xml:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="driverProvider"
class="org.jbehave.web.selenium.FirefoxWebDriverProvider">
</bean>
<bean id="webDriverProvider"
class="org.jbehave.web.selenium.PerStoryWebDriverSteps">
<constructor-arg ref="driverProvider" />
</bean>
<bean id="lifecycleSteps"
class="com.bignibou.bdd.steps.LifecycleSteps">
<constructor-arg ref="driverProvider" />
</bean>
<bean id="pageFactory"
class="com.bignibou.bdd.pages.PageFactory">
<constructor-arg ref="driverProvider" />
</bean>
<bean id="steps"
class="com.bignibou.bdd.steps.WebSteps">
<constructor-arg ref="pageFactory" />
</bean>
</beans>