Automating Selenium with Ant
or How to Enable Multi Browser Testing with JUnit Reports
This is a topic from the Introduction to Selenium class at LMN Solutions.
In order to pass in the browser selection from the Ant script code like this is required in your JUnit Selenium Web Driver tests. I put this code into the parent class that all my Selenium JUnit tests extend.
@BeforeClass
public static void startSelenium() throws Exception {
Properties sysProps = System.getProperties();
String browser = sysProps.getProperty("browser.property");
if (browser == null) {
driver = new InternetExplorerDriver();
} else if (browser == "*firefox") {
driver = new FirefoxDriver();
}
}
In the Ant build.xml file you will find the code:
<sysproperty key="browser.property" value="*iexplore" />
Which tells the JUnit code which browser to launch.
You will also see:
<junitreport todir="${reports}">
<fileset dir="${reports}/ie-raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\ie-html\"/>
</junitreport>
This tells JUnit to build a html report of the test results when finished.
In the Ant build.xml file you will find the code:
<sysproperty key="browser.property" value="*iexplore" />
Which tells the JUnit code which browser to launch.
You will also see:
<junitreport todir="${reports}">
<fileset dir="${reports}/ie-raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\ie-html\"/>
</junitreport>
This tells JUnit to build a html report of the test results when finished.
Then I have build an Ant build.xml file that you can download. See if you can get this set up and running while I write up some step by step directions. Please send me any questions you have and make sure to check out our classes at http://lmnsolutions.com/training.html.
