Using WebDriver API


#1

Hello,

I exported a test case from Script Developer to XLT Scripting API and wanted to expand the created Java code in IntelliJ with a WebDriver API command. This should be possible according to https://lab.xceptance.de/releases/xlt/latest/user-manual/04-framework.html#toc-webdriver-api.

I just wanted to open a url using WebDriver API with ‘driver.get(url)’. It didn’t work.

How can I use WebDriver commands in Java code exported from Script Developer? Is it necessary to import special libraries, is there another syntax, …? Is there any documentation regarding this topic?

Regards
Christine


#2

Hi Christine,

Code exported from Script Developer uses either the Scripting API or the Action API which you can choose from in the export dialog. Typically, you would choose the Scripting API as this is the closest representation of your XML scripts in Java.

XLT’s Scripting API provides the same commands as Script Developer and even more. In case you want to do some more sophisticated stuff that is not covered by any of the provided commands, you can use the underlying WebDriver API at any time by calling getWebDriver() to get the wrapped WebDriver instance in your code.

Unfortunately, you did not give any more details about what did not work in your test. So, let me guide you through this step by step.

  1. Please make sure that you have configured the classpath of your Java project in IntelliJ to include the libraries shipped with XLT. A short explanation on how to do so can be found here.
  2. Please check if your code compiles without any errors.
  3. Make sure that the constructor of your test class uses our DefaultWebDriverFactory to retrieve the WebDriver instance used in the super() statement.
import com.xceptance.xlt.engine.util.DefaultWebDriverFactory;

...
public class TBrowse extends AbstractWebDriverScriptTestCase {
  public TBrowse() {
    super(DefaultWebDriverFactory.getWebDriver(), "http://example.org");
  }
}

Starting with XLT 4.10.0, the explicit call to our DefaultWebDriverFactory won’t be necessary anymore but for now it is.

Now, lets cover the configuration part.
4. Copy the config folder of the template testsuite shipped with XLT <XLT_INSTALLATION>/samples/testsuite-template to your Java project.
5. Open the properties file project.properties inside the config folder of your testsuite and add the following:

# Configure XLT to use Chrome
xlt.webDriver = chrome
xlt.webDriver.chrome.pathToBrowser = <PATH_TO_CHROME>
xlt.webDriver.chrome.pathToDriverServer = <PATH_TO_CHROMEDRIVER>

# Configure XLT to use Firefox
xlt.webDriver = firefox
xlt.webDriver.firefox.pathToBrowser = <PATH_TO_FIREFOX>
xlt.webDriver.firefox.pathToDriverServer = <PATH_TO_GECKODRIVER>

The driver servers can be found here for Chrome and here for Firefox. Please note that you don’t have to configure the paths to your browsers and/or driver servers if their installations are on your PATH.

A “documentation” of the properties above can be found in the file default.properties.

Thanks,
Hartmut


#3

Thank you for your very fast reply, it is really great to have answers so fast.

Now I was able to use some selenium commands. The key hint was using DefaultWebDriverFactory.

Regards
Christine