3

I have been using set up method to launch site but it has made made it difficult for me to maintain tests, especially now when there are multiple URLs for application -

public void setUP() {
  WebDriver driver = new FirefoxDriver();
  driver.get("appURL")
}

Problem I face is that the application has two URLs for two different roles - Admin and normal User. Depending on the kind of URL I would do -

public void setUP() {
          WebDriver driver = new FirefoxDriver();
if(appURL.contains("admin") {
          driver.get("adminappURL") 
} else {
driver.get("userURL")
}

}

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

4

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.

1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.