0

I have searched high and low for this answer and I am unable to find the exact answer needed; so bear with me if this feels its repeating another question.

Using C#, .NET, SpecFlow, Selenium

I have several feature files using lines from each other, which is predominantly one of the main reasons for using them. For ease ill water them down to draw the picture of the issue... Ill highlight the reused lines also.

Feature File A - Given I have loaded the website When I type a valid username and password Then I can log in

Feature File B - Given I have loaded the website When I type a invalid username and password Then I cant log in

Feature File C - Given I have loaded the website When I create an account And the login screen is presented upon completion And I enter my new account details Then I can log in

As you can see, my feature files cross over and thus B needs A and C needs A. My question is, how do I run all of these one after another, how do I reuse the driver from A when its quit the browser as that flow has ended?

CalAtk
  • 45
  • 1
  • 10
  • Your test always should be E2E that should be way of using BDD framework.Once Feature File 1 completed there should be new session of Feture File 2.However you can reuse the object any time not the session. – KunduK Dec 19 '19 at 15:33
  • This is where I am confused because Feature File 1 is end to end, however, they share steps from within each other (As standard for this way of working.) So feature file 2 will call the step definition for feature file 1 as they're sharing steps thus feature file 2 doesn't need ```Driver = new ChromeDriver();``` as it already has a chrome session initiated by feature file 1s step definition but does need its own driver to locate the elements? If so, what does this look like? – CalAtk Dec 19 '19 at 15:45
  • see if this link helps https://www.testautomationtribe.com/specflow-with-page-object – KunduK Dec 19 '19 at 15:50
  • 3
    It's bad test practice in general to have your test cases dependent on one another, especially in the context of automation. Each test case should execute independently of every other test case, and the results of one test case should not determine the outcome of another. – CEH Dec 19 '19 at 16:33
  • The main benefit of SpecFlow is that this is possible, amongst many others. – CalAtk Dec 19 '19 at 17:12
  • No one said it's not possible... just that it's not a best practice. It's possible to do this WITHOUT SpecFlow but it's still not a best practice. If B relies on A, what if A crashes or gets into a bad state? B will fail... and so will any other test that relies on A. For each test, you should start a new browser session, conduct the test, and close the browser. That way each run gets a clean slate to run in and reduces a lot of the intermittent failures, etc. – JeffC Dec 19 '19 at 21:18

1 Answers1

1

define multiple drivers maybe? like driver1, driver2 and use them for your different scenarios.They will open 2 browser instances and will work according to your code sequence. IWebDriver driver = new ChromeDriver(options); IWebDriver driver2 = new ChromeDriver(options); It is not a very good approach,as it slows down system, but it works. Another way is using selenium grid.but not sure if you need this for this problem. You can also define multiple drivers with different browsers if you are interested in testing same function on different browsers,

Nina
  • 150
  • 11
  • That sounds like the right solution, I’ll give this a go Monday and let you know; thanks! – CalAtk Dec 21 '19 at 17:57