My scenario reads a file with hundreds of lines. Each line calls an API Service, but the service may not be running. If I get a non-200 response (available inside the 'Then' method), I want to abandon the Scenario & save time. How can I tell TechTalk SpecFlow to not carry on with the other tests?
Asked
Active
Viewed 42 times
0
-
I would question the approach here. Wouldn't you want to make sure your api service is active and 'warm' before running tests against it? – Konzy262 Nov 17 '19 at 19:27
-
@Konzy262 that would make the test script more complicated - and I'm not the one who wrote it. It's quite difficult to follow, as it looks like it's written by an English major rather than a computer programmer, and the mapping to actual code almost but not quite quite different to the method names e.g. something like "If I read the file and call the functional api then verify that the names match what's on the label" but of course those are not the names of the methods. – brewmanz Nov 19 '19 at 06:14
1 Answers
0
You can use a concept like this .
public static FeatureContext _featureContext;
public binding( FeatureContext featureContext)
{
_featureContext = featureContext;
}
[Given(@"user login")]
public void login(){
// do test
bool testPassed = //set based on test. true or false
binding._featureContext.Current["testPass"] = testPassed;
}
Then in BeforeScenario()
[BeforeScenario(Order = 1)]
public void BeforeScenario()
{
Assert.IsTrue(FeatureContext.Current["testPass"];);
}

user1207289
- 3,060
- 6
- 30
- 66
-
This may be what I'm looking for, but IIRC I tried using the dictionary but it get's reset for each call. I'll have a look again later – brewmanz Nov 19 '19 at 06:17