Introduction

A script test suite created with XLT Script Developer is a perfect starting point for all the other great things you can do with the XLT Framework. The example below describes how to run the tests as JUnit tests from within an Java IDE.

From there it’s a waltz to do cross-browser testing or integrate the tests into a continuous integration process. Running the same test suite as a load and performance test or data-driven test is also possible. You can even export the test cases to Java code to add more advanced functionality like handling conditions, execution branches and random factors. For this you can choose from multiple APIs like WebDriver or HtmlUnit – which is great if you’re already familiar with one of those.

You see, XLT is a powerful tool. For almost all of those approaches the Script Developer is a good starting point. So let’s take the test suite we created in the Script Developer Quick-Start and do some more great stuff with it.

We are using Eclipse IDE in this example. If you prefer another Java IDE some of the steps below might differ but the principles are the same.

1. Create a New Test Suite Directory

If you just use the XLT Script Developer and nothing else then one simple folder is enough to hold the script test suite – as seen in the Getting Started With Script Developer example above. However, if you want to do more with the XLT Framework it requires test suite directory structure as shown below. Note that it can’t be changed:

bc(java).

|—config
| |—data
|—lib
|—scripts
|—src

You don’t need to create the mandatory directory structure and configuration files on your own. XLT ships with an empty test suite project, which can be used as a template for your own projects. This template project is located in <xlt>/samples/testsuite-template. Simply copy the complete testsuite-template directory to a location of your choice and rename it, for example c:\test-suites\testsuite-MySite. This directory is referred to as <testsuite> throughout the next sections.

It is recommended to store your test suite in a directory that is not a subdirectory of your XLT installation. This facilitates updating to newer XLT versions because it reduces the risk of overwriting your test cases during an update.

2. Move Scripts to New Test Suite

If you already created one or more test cases as described in the Getting Started With Script Developer section above then now is the time to move them to a new home. You should copy them into the <testsuite-MySite>/scripts folder. When using Script Developer for the next time don’t forget to also switch to the new scripts directory there by clicking the folder icon and then ‘Import’. Then select the new location and click OK.

Import Test Suite

3. Generate wrapper classes

To be able to run the script test cases in Eclipse it is necessary to let Script Developer generate JUnit wrapper classes. This is just a wrapper around the original script. The tests still can be edited in Script Developer.

Open the Script Developer settings dialog by clicking ‘XLT Script Developer’:

Open Script Developer Settings

Tick the checkbox Generate JUnit wrapper classes for test cases and confirm by clicking OK:

Generate JUnit Wrapper Classes

The automatically created wrapper classes can be found in the <testsuite>/src folder.

4. Import Project into Eclipse

Now import your project into Eclipse and change the displayed project name testsuite_template to testsuite-MySite via Eclipse’s refactoring functionality.

  1. Open Eclipse
  2. Click File | Import in main menu
  3. Select Import existing project into workspace from the list (can be found in folder General) and click Next
  4. In the next dialog window click button Browse and select your <testsuite> directory
  5. Click button Finish. Your test suite should now be imported as an Eclipse project. With errors, though. We’ll fix this in a minute.

Import project into Eclipse

Change the displayed project name by following the steps below.

  1. Right-click on the project name and select Refactor | Rename from context menu
  2. Provide a new name for the test suite project and confirm by clicking OK.

Rename Test Suite Project

5. Add XLT Libraries to the Test Suite

To get rid of the displayed build errors for our new test suite we have to add the XLT libraries to the project. Like so:

  1. Right-click on the project name and select Properties
  2. In the properties dialog select Java Build Path on the left side
  3. Select the Libraries tab and click button Add External JARs…
  4. In the JAR selection dialog browse to the XLT installation directory. Got to <xlt>/lib sub-directory and and select all files in there (e.g. press Ctrl+A).
  5. Confirm by clicking OK in both of the opened dialogs

Add XLT Libraries to Test Suite

6. Run the Test

Now you’re finally ready to run the tests! The generated wrapper for the script test case is a JUnit test. You can benefit from all the nice JUnit-supporting features build into Eclipse when running your XLT test suite.

To run one of the test cases use the Eclipse Package Explorer to browse to <testsuite-MySite>/src/(default package). There you will find a JUnit wrapper classes for each of your test cases created in Script Developer.

  1. Right-click on one of the test case classes
  2. Select Run As… | JUnit Test from context menu
  3. See result of the test in the JUnit tab

Run XLT test in Eclipse

JUnit Test Result

How To Move On

Cross-browser testing or integrating the tests into a continuous integration process? Running a load and performance test or data-driven tests?

Find more information on all of those topics in the How-To section and the User Manual!