|
Yes, it’s possible
to migrate.
The first step
when starting the migration is to change how you obtain your instance of
Selenium. When using Selenium RC, this is done like so:
Java Code:
Selenium selenium =
new DefaultSelenium(
"localhost", 4444, "*firefox",
"http://www.yoursite.com");
selenium.start();
This should be
replaced like so:
Java Code:
WebDriver driver =
new FirefoxDriver();
Selenium selenium
= new WebDriverBackedSelenium(driver, "http://www.yoursite.com");
Next Steps
Once your tests
execute without errors, the next stage is to migrate the actual test code to
use the WebDriver APIs. Depending on how well abstracted your code is, this
might be a short process or a long one. In either case, the approach is the
same and can be summed up simply: modify code to use the new API when you
come to edit it.
If you need to
extract the underlying WebDriver implementation from the Selenium instance,
you can simply cast it to WrapsDriver
Java Code:
WebDriver driver =
((WrapsDriver) selenium).getWrappedDriver();
This allows you to
continue passing the Selenium instance around as normal, but to unwrap the
WebDriver instance as required.
At some point, you’re
codebase will mostly be using the newer APIs. At this point, you can flip the
relationship, using WebDriver throughout and instantiating a Selenium
instance on demand:
Java Code:
Selenium selenium
= new WebDriverBackedSelenium(driver, baseUrl);
|