views:

293

answers:

1

Hi,

I have a set of Selenium tests which run via HTTP - I'd like to run the same tests under HTTPS aswell as HTTP with as little duplication as possible. I guess other people must already be doing this? I use the Java Selenium Remote Control - but I can probably translate a method from another language.

+4  A: 

You could pass the URL of the application under test to your test framework as a parameter, or store it in a properties file. I do this to switch between test environments.

Below is a simple example of reading from a properties file:

protected void startSession() {
 Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox",
  applicationProperties.getProperty("application.url"));
}

And an example of using a parameter (I use TestNG for this):

Add parameters in the TestNG suite XML file:

<parameter name="appURL" value="http://www.example.com/" />

Use the parameter when you create a Selenium instance:

@BeforeMethod(alwaysRun = true)
@Parameters({"appURL"})
protected void startSession(String appURL) {
 Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", appURL);
}
Dave Hunt
Thanks - that gave me some ideas. Since I discovered in JUnit 4 you can include a Suite within a Suite. So I ended up putting all the tests in a common suite and then having HttpSuite and HttpsSuite which both ran the common suite.
Corehpf