I have been working on a test suite in java using testng as the testing framework. I could not have suggested any other test frame work as it allows me to do a lot of configurable setups and teardowns. Yeah am not gonna promote testng anymore, lol.
I could have started using selenium server using a usual batch file that maven could call in one of its targets but i think doing it this way is cleaner.
public class SeleniumManager {
private SeleniumServer seleniumServer;
private static Selenium selenium;
private RemoteControlConfiguration rcc;
@BeforeSuite
@Parameters( { "selenium.port" })
public void startSeleniumServer(String port) {
rcc = new RemoteControlConfiguration();
rcc.setPort(Integer.parseInt(port));
try {
seleniumServer = new SeleniumServer(false, rcc);
// seleniumServer= new SeleniumServer();
seleniumServer.start();
} catch (Exception e) {
throw new IllegalStateException("Can't start selenium server", e);
}
}
@AfterSuite(alwaysRun = true)
public void stopSeleniumServer() {
if (seleniumServer != null) {
seleniumServer.stop();
}
}
public static Selenium startSelenium(String host, String port, String browser, String url) {
selenium = new DefaultSelenium(host, Integer.parseInt(port), browser, url);
selenium.start();
return selenium;
}
public static void stopSelenium(Selenium selenium) {
selenium.stop();
}
}
As you can see i have a seleniumManager class which would dynamically start the selenium server before my testSuite starts and kill the SeleniumServer after the test suite is completed.
Please try this out and leave comments
My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit
http://samueladesoga.wordpress.com
and update your bookmarks.
Showing posts with label selenium-server. Show all posts
Showing posts with label selenium-server. Show all posts
Monday, 16 November 2009
Setting user extensions when the Selenium Server has been started dynamically
I hope this helps someone someday, I needed to set user extension for a selenium test suite, dynamically in the code as i was starting the Selenium server via same.
public void startSeleniumServer(String port) {
rcc = new RemoteControlConfiguration();
rcc.setPort(Integer.parseInt(port));
try {
seleniumServer = new SeleniumServer(false, rcc);
seleniumServer.start();
} catch (Exception e) {
throw new IllegalStateException("Can't start selenium server", e);
}
}
public void stopSeleniumServer() {
if (seleniumServer != null) {
seleniumServer.stop();
}
}
i was setting the user extension file using the remoteControlConfiguration object
so i had typed:
rcc.setUserExtensions(new File({path_location_to_user_extension.js}));
This didnt work and an extensive search in the api wasnt very useful.
A colleague however found out that doing a
seleniumServer.boot(); would make the user-extension file to work.
Great isn't it ...........
public void startSeleniumServer(String port) {
rcc = new RemoteControlConfiguration();
rcc.setPort(Integer.parseInt(port));
try {
seleniumServer = new SeleniumServer(false, rcc);
seleniumServer.start();
} catch (Exception e) {
throw new IllegalStateException("Can't start selenium server", e);
}
}
public void stopSeleniumServer() {
if (seleniumServer != null) {
seleniumServer.stop();
}
}
i was setting the user extension file using the remoteControlConfiguration object
so i had typed:
rcc.setUserExtensions(new File({path_location_to_user_extension.js}));
This didnt work and an extensive search in the api wasnt very useful.
A colleague however found out that doing a
seleniumServer.boot(); would make the user-extension file to work.
Great isn't it ...........
Labels:
Java,
Javascipt,
selenium,
selenium rc,
selenium-server,
test,
user-extensions
Subscribe to:
Posts (Atom)