When you start using Twist you will find that the twist team have baked selenium into twist.
You will also find that the version of selenium that has been integrated has some quirks.
Here is a simple guide for using any Selenium version with Twist.
You can also use this guide to help you implement other drivers like WebDriver.
Step 1
Add the selenium-java-client-driver.jar and the selenium-server.jar of your preferred selenium release (I'm going to be using my old friend selenium.0.9.2) to the Twist project class path, make sure these jars are loaded first in the class path order.
Step 2
You need to create a factory class that will create the Selenium instance for your test suite.
For example, let’s create "SeleniumFactory.java" in the Twist source folder.
import java.io.FileInputStream; import java.util.Properties;
import org.apache.tools.ant.types.Commandline;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.server.cli.RemoteControlLauncher;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class SeleniumFactory { private SeleniumServer server; private Selenium selenium; }
public void start() {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(getClass().getClassLoader().getResource("twist.properties").getFile()));
}
String[] serverOptions = Commandline.translateCommandline((String) properties.get("selenium.server.options"));
RemoteControlConfiguration serverConfiguration = RemoteControlLauncher.parseLauncherOptions(serverOptions);
String browserLauncher = (String) properties.get("selenium.browserLauncher");
String browserURL = (String) properties.get("selenium.browserURL");
server = new SeleniumServer(serverConfiguration);
server.start();
selenium = new DefaultSelenium("localhost", serverConfiguration.getPort(), browserLauncher, browserURL);
selenium.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
public void stop() {
try {
if (selenium != null) {
selenium.stop();
}
} finally {
if (server != null) {
server.stop();
}
}
}
public Selenium geSelenium() {
return selenium;
}
Step 3
We now need to remove any bean definitions with id="seleniumFactory" and id="selenium" from the applicationContext-suite.xml file.
You will have to manually edit, the "applicationContext-suite.xml" of the twist project, and add the following bean definitions.
Step 4
The workflows will now have to depend on the Selenium interface.
For example,
public NewWorkflow(Selenium selenium) {
this.selenium = selenium;
}
With the above changes, your scenarios will be now use the selenium server and driver jars included in “step a”.
Note:
The selenium options are not the same between releases. The beta-2 release of Selenium RC contains some significant changes you should be aware of. You will need to account for these and change these values in "twist.properties" as required.
For example:
selenium 0.9.2 config : selenium.browserLauncher = *firefox
selenium 1.o Beta 2 config : selenium.browserLauncher = *firefoxproxy
selenium 0.9.2 config : selenium.server.options = -port 4545 -avoidProxy
selenium 1.o Beta 2 config : selenium.server.options = -port 4545 -avoidProxy -honor-system-proxy -singleWindow
For a full list of the changes take a look at http://clearspace.openqa.org/community/selenium/blog/2009/01/13/selenium-rc-beta-2-goodies-and-gotchas
LeadingAgile’s Top 10 Field Notes of 2024
-
[image: LeadingAgile’s Top 10 Field Notes of 2024]
[image: Discover How to Unlock the Benefits of Agility] [image: Discover
How to Unlock the Benefits of ...
14 hours ago
No comments:
Post a Comment