Specflow Context Injection of IWebDriver failing
up vote
2
down vote
favorite
We have a suite of UI tests being run using Specflow and Selenium WebDriver. Overnight these suddenly stopped working and now throw the following error on each Scenario:
BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver (resolution path: Steps class)
We're using the Specflow Context Injection on register our webdriver before each scenario, which we then use in each of our steps classes:
[Binding]
public class Base
{
private readonly IObjectContainer _objectContainer;
private IWebDriver _webDriver;
public Base(IObjectContainer objectContainer)
{
_objectContainer = objectContainer;
}
[BeforeScenario]
public void Setup()
{
_webDriver = new ChromeDriver();
_objectContainer.RegisterInstanceAs<IWebDriver>(_webDriver);
}
....
}
Steps file:
[Binding]
public class ProductSteps : TechTalk.SpecFlow.Steps
{
private readonly IWebDriver _driver;
public ProductSteps(IWebDriver driver)
{
_driver = driver;
}
}
Looking online at the Specflow documentation I can see nothing wrong - and I can also find little to show anyone else ever having this problem!
I've spent a fair bit of time trying to get to the bottom of this but have had no luck whatsoever.
We're using NUnit as our test runner and have all the latest updates via nuget.
c# selenium webdriver specflow
add a comment |
up vote
2
down vote
favorite
We have a suite of UI tests being run using Specflow and Selenium WebDriver. Overnight these suddenly stopped working and now throw the following error on each Scenario:
BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver (resolution path: Steps class)
We're using the Specflow Context Injection on register our webdriver before each scenario, which we then use in each of our steps classes:
[Binding]
public class Base
{
private readonly IObjectContainer _objectContainer;
private IWebDriver _webDriver;
public Base(IObjectContainer objectContainer)
{
_objectContainer = objectContainer;
}
[BeforeScenario]
public void Setup()
{
_webDriver = new ChromeDriver();
_objectContainer.RegisterInstanceAs<IWebDriver>(_webDriver);
}
....
}
Steps file:
[Binding]
public class ProductSteps : TechTalk.SpecFlow.Steps
{
private readonly IWebDriver _driver;
public ProductSteps(IWebDriver driver)
{
_driver = driver;
}
}
Looking online at the Specflow documentation I can see nothing wrong - and I can also find little to show anyone else ever having this problem!
I've spent a fair bit of time trying to get to the bottom of this but have had no luck whatsoever.
We're using NUnit as our test runner and have all the latest updates via nuget.
c# selenium webdriver specflow
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
We have a suite of UI tests being run using Specflow and Selenium WebDriver. Overnight these suddenly stopped working and now throw the following error on each Scenario:
BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver (resolution path: Steps class)
We're using the Specflow Context Injection on register our webdriver before each scenario, which we then use in each of our steps classes:
[Binding]
public class Base
{
private readonly IObjectContainer _objectContainer;
private IWebDriver _webDriver;
public Base(IObjectContainer objectContainer)
{
_objectContainer = objectContainer;
}
[BeforeScenario]
public void Setup()
{
_webDriver = new ChromeDriver();
_objectContainer.RegisterInstanceAs<IWebDriver>(_webDriver);
}
....
}
Steps file:
[Binding]
public class ProductSteps : TechTalk.SpecFlow.Steps
{
private readonly IWebDriver _driver;
public ProductSteps(IWebDriver driver)
{
_driver = driver;
}
}
Looking online at the Specflow documentation I can see nothing wrong - and I can also find little to show anyone else ever having this problem!
I've spent a fair bit of time trying to get to the bottom of this but have had no luck whatsoever.
We're using NUnit as our test runner and have all the latest updates via nuget.
c# selenium webdriver specflow
We have a suite of UI tests being run using Specflow and Selenium WebDriver. Overnight these suddenly stopped working and now throw the following error on each Scenario:
BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver (resolution path: Steps class)
We're using the Specflow Context Injection on register our webdriver before each scenario, which we then use in each of our steps classes:
[Binding]
public class Base
{
private readonly IObjectContainer _objectContainer;
private IWebDriver _webDriver;
public Base(IObjectContainer objectContainer)
{
_objectContainer = objectContainer;
}
[BeforeScenario]
public void Setup()
{
_webDriver = new ChromeDriver();
_objectContainer.RegisterInstanceAs<IWebDriver>(_webDriver);
}
....
}
Steps file:
[Binding]
public class ProductSteps : TechTalk.SpecFlow.Steps
{
private readonly IWebDriver _driver;
public ProductSteps(IWebDriver driver)
{
_driver = driver;
}
}
Looking online at the Specflow documentation I can see nothing wrong - and I can also find little to show anyone else ever having this problem!
I've spent a fair bit of time trying to get to the bottom of this but have had no luck whatsoever.
We're using NUnit as our test runner and have all the latest updates via nuget.
c# selenium webdriver specflow
c# selenium webdriver specflow
edited Aug 24 '16 at 15:09
FrankerZ
15.6k72859
15.6k72859
asked Aug 24 '16 at 8:41
Piers Gwynn
133
133
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
My guess is that you have another BeforeScenario hook on the ProductSteps class that might run earlier and forces the creating of the instance earlier than the other BeforeScenatio is triggered, so the web driver is not registered yet.
You can control the order of the execution of the hooks, you can use the Order
parameter of the attribute (see http://www.specflow.org/documentation/Hooks/): [BeforeScenario(Order = 0)]
.
You can also check my post at http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/ that gives a more robust solution with more complex dependencies using Autofac.
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
add a comment |
up vote
1
down vote
Things don't just stop working over night.
I would look at what changed between yesterday and today. Did you update any of the packages used? Any changes related to your IOC? Your error message is pointing in that direction.
Try to roll back to what you had when it was still working and bring changes in one by one to see which caused the issue. Then you can take it from there.
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
add a comment |
up vote
0
down vote
I found solution here https://stackoverflow.com/a/26402692/10148657. Basically I got rid of RegisterInstanceAs and wrapped IWebDriver in SeleniumContext class which can now be freely passed as injected dependency.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
My guess is that you have another BeforeScenario hook on the ProductSteps class that might run earlier and forces the creating of the instance earlier than the other BeforeScenatio is triggered, so the web driver is not registered yet.
You can control the order of the execution of the hooks, you can use the Order
parameter of the attribute (see http://www.specflow.org/documentation/Hooks/): [BeforeScenario(Order = 0)]
.
You can also check my post at http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/ that gives a more robust solution with more complex dependencies using Autofac.
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
add a comment |
up vote
3
down vote
accepted
My guess is that you have another BeforeScenario hook on the ProductSteps class that might run earlier and forces the creating of the instance earlier than the other BeforeScenatio is triggered, so the web driver is not registered yet.
You can control the order of the execution of the hooks, you can use the Order
parameter of the attribute (see http://www.specflow.org/documentation/Hooks/): [BeforeScenario(Order = 0)]
.
You can also check my post at http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/ that gives a more robust solution with more complex dependencies using Autofac.
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
My guess is that you have another BeforeScenario hook on the ProductSteps class that might run earlier and forces the creating of the instance earlier than the other BeforeScenatio is triggered, so the web driver is not registered yet.
You can control the order of the execution of the hooks, you can use the Order
parameter of the attribute (see http://www.specflow.org/documentation/Hooks/): [BeforeScenario(Order = 0)]
.
You can also check my post at http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/ that gives a more robust solution with more complex dependencies using Autofac.
My guess is that you have another BeforeScenario hook on the ProductSteps class that might run earlier and forces the creating of the instance earlier than the other BeforeScenatio is triggered, so the web driver is not registered yet.
You can control the order of the execution of the hooks, you can use the Order
parameter of the attribute (see http://www.specflow.org/documentation/Hooks/): [BeforeScenario(Order = 0)]
.
You can also check my post at http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/ that gives a more robust solution with more complex dependencies using Autofac.
answered Aug 31 '16 at 9:37
Gaspar Nagy
3,7622436
3,7622436
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
add a comment |
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
Hi Gaspar, thanks a lot for these links. Sadly we don't have another BeforeScenario hook set anywhere however we'll definitely take a look at setting the order of the hooks to see if this helps. Your second link also looks interesting - will read through and see if we can apply some changes that help us out.
– Piers Gwynn
Sep 2 '16 at 14:11
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
In this case it can happen that it is a bug (although I haven't seen such error, although I use this pattern). Which SpecFlow version produces this? If it would be possible to create a small repro, please post it to github. (The Autofac solution could still fix it.)
– Gaspar Nagy
Sep 5 '16 at 6:37
add a comment |
up vote
1
down vote
Things don't just stop working over night.
I would look at what changed between yesterday and today. Did you update any of the packages used? Any changes related to your IOC? Your error message is pointing in that direction.
Try to roll back to what you had when it was still working and bring changes in one by one to see which caused the issue. Then you can take it from there.
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
add a comment |
up vote
1
down vote
Things don't just stop working over night.
I would look at what changed between yesterday and today. Did you update any of the packages used? Any changes related to your IOC? Your error message is pointing in that direction.
Try to roll back to what you had when it was still working and bring changes in one by one to see which caused the issue. Then you can take it from there.
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
add a comment |
up vote
1
down vote
up vote
1
down vote
Things don't just stop working over night.
I would look at what changed between yesterday and today. Did you update any of the packages used? Any changes related to your IOC? Your error message is pointing in that direction.
Try to roll back to what you had when it was still working and bring changes in one by one to see which caused the issue. Then you can take it from there.
Things don't just stop working over night.
I would look at what changed between yesterday and today. Did you update any of the packages used? Any changes related to your IOC? Your error message is pointing in that direction.
Try to roll back to what you had when it was still working and bring changes in one by one to see which caused the issue. Then you can take it from there.
answered Aug 24 '16 at 8:53
Andrei Dragotoniu
3,23211118
3,23211118
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
add a comment |
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
We've changed very little in the solution recently - only simple changes to things like button Ids in our UI tests etc. One weird thing is that occasionally we can try changing something - like removing and re-adding a reference and the error will go away, but will then reappear if we close and re-open the solution. I'll try rolling specflow, selenium, webdriver and nunit back a few versions to see if that helps, although all of these packages are official packages from nuget and it's all been installed as per the Specflow docs. Thanks
– Piers Gwynn
Aug 25 '16 at 8:40
add a comment |
up vote
0
down vote
I found solution here https://stackoverflow.com/a/26402692/10148657. Basically I got rid of RegisterInstanceAs and wrapped IWebDriver in SeleniumContext class which can now be freely passed as injected dependency.
add a comment |
up vote
0
down vote
I found solution here https://stackoverflow.com/a/26402692/10148657. Basically I got rid of RegisterInstanceAs and wrapped IWebDriver in SeleniumContext class which can now be freely passed as injected dependency.
add a comment |
up vote
0
down vote
up vote
0
down vote
I found solution here https://stackoverflow.com/a/26402692/10148657. Basically I got rid of RegisterInstanceAs and wrapped IWebDriver in SeleniumContext class which can now be freely passed as injected dependency.
I found solution here https://stackoverflow.com/a/26402692/10148657. Basically I got rid of RegisterInstanceAs and wrapped IWebDriver in SeleniumContext class which can now be freely passed as injected dependency.
edited Nov 8 at 0:47
Stephen Rauch
27.4k153156
27.4k153156
answered Nov 8 at 0:27
Dariusz Kijania
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39118432%2fspecflow-context-injection-of-iwebdriver-failing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown