URL is externalized to an xml file and tests are grouped in small set of tags depending on role, but there is overlapping at times. Hence There are instances when I need to log in to both admin and user facing site from one test. In this case I end up in launching adminURL first and then user facing URL to begin with test operations. Here launch of admin URL at first instance is unnecessary.

I am willing to know what others follow with their test automation. URL invocation in set up method or in individual tests?

3 Answers
3

The setUp method is just a place to put code that needs to run before every test. It sounds to me as if you feel compelled to use it but do not believe it meets your needs. Judging from your description, driver.get(URL) belongs in the individual tests, not in the setUp method.

Alternatively, you could structure your tests as two suites: one with a setUp that launches the user URL, and one that launches the admin URL. That seems like the wrong organizing principle, but perhaps there are additional, role-dependent initialization steps that you did not mention.

Generally I don't do this, although sometimes I have found it necessary when trying to maintain tests to be consistent and to get the most out of them. When doing BDD sometimes my Setup will start at a specific URL for a role, generally I do this with a tag and try to start up my scenarios with specific settings from XML and pulled in depending on a tag. In some ways this makes things easier since I can run multiple tests by starting the test runner with a tag and get the values, scenarios I need. It makes some tests simpler since I can fit more actions into the rest of the test steps (I'm using SpecFlow).

In the past when I had my tests shorter and more targeted, I did this work within the test steps and used the Setup to get my environment in order.

For me it comes down to what works better with the Framework and tests I am using.

We actually build the driver in our test client, but leave it to the test to call the get method to open the page. The only time we ever call the get method in set up is if we are going to be doing a lot of things that need to be repeated in several tests.