0
votes

I've managed to build some fairly simple tests that do not utilise a Page Object Model structure. The Specflow steps will just call the driver methods (such as finding an element on the page and asserting the text is correct).

The tests use NUnit as the runner and I have managed to add parallel execution by adding [Parallelizable(ParallelScope.Fixtures)] to the assembly class for the solution. This works well, but the reports that come out of NUnit are a bit messy and I'd like more useful information on them (such as screenshots).

I have since added Extent reports to the solution, whilst this works fine for when the tests run sequentially, an error message appears when running them in parallel.

The FeatureContext.Current static accessor cannot be used in multi- 
threaded execution. Try injecting the feature context to the binding 
class.

The Context.Current steps are used in the creation of the Extent reports. I've been reading the documentation relating to multithreading from the Specflow site, but I'm having issues understanding the concept and figuring out how I can inject FeatureContext into the binding class. I'm trying to follow this example from the site:

[Binding]
public class StepsWithScenarioContext : Steps
{
    [Given(@"I put something into the context")]
    public void GivenIPutSomethingIntoTheContext()
    {
      this.ScenarioContext.Set("test-value", "test-key");
    }
}

I've also been trying to follow other examples, but I've yet to see any documentation relating how to use ScenarioContext with something like driver.findElement(By.Id("blah")).

Any help would be appreciated, I am fairly new to test automation.

1

1 Answers

1
votes

You need to have a property in your Steps class: ScenarioContext _scenarioContext. In Constructor you adding ScenarioContext scenarioContext as a parameter and initilizing it using:

_scenarioContext = scenarioContext

Simple example:

class Steps
ScenarioContext _scenarioContext;
public Steps (ScenarioContext scenarioContext)
{
  _scenarioContext = scenarioContext;
}

Only I don't know, how it will work with inheritance.