Just like you have utilities that you share within your various WET tests, you may want to have certain WET tests itself which you need to be made sharable. Such WET tests are called Library Tests or Reusable Tests. Be clear with the distinction of the following two terms:
- Library Utility - These are generic utilities which assist testing. For example, you may have a utility to concatenate two strings. Or a utility which gets the current version of your Application Under test.
- Library Test (aka Reusable tests) - These are full fledged WET tests that can be called by other WET tests. For example - a WET test that logs into the system and confirms that the user is indeed login. You may have to login to the application as a part of many other tests. In such a case you can make the login test as a 'Reusable Test' which can be called by other WET Tests.
Making a WET test into a re-usable library test
As of version 0.9.8, you cannot create a Reusable Test directly using the WET UI. You have to modify the test definition file by hand to do this.
Recollect that a WET Test case is denoted by the test.defs file. First of all look at the the sample test definitions file (which can be found at ${WET_install_directory}\etc\test.defs.template).
Under the [Common] header you will see the following snippet of commented out code:
-
- In case the test doesn't have transactions but only
- Has one single script to run, that will be defined here.
#script.path = ../scripts/test.qws
The script.path is the path of a qws script that will be run if this wet test is called from another script. Let us see how to use this to create a Reusable Test.
If you typically create Test definitions by directly editing by hand (that is, you dont use the Wet UI to create test definitions), you can safely skip the following section and go directly to the section titled "Convert a regular WET Test Case (aka test definition) into a Reusable test".
Let's use the example of making a login page as a "reusable script"
Use the WET UI to generate a regular WET Test
First of all, use the WET UI to create the required test. The test case file(aka test definition) created by the WET UI may look something like:
[Common]
name = login
description = This script opens a new browser, navigates to the example server and then logs in
repository.path = ./repository/ostore.xml
results.path = ./results/
obj.timeout = 10
iterations = *[Precondition1]
name = FirstPrecondition
description = Give a brief description about this precondition and why it is important[Transaction1]
name = login
description = Use this script to login
path = ./scripts/login.rb[Teardown1]
name = FirstTeardown
description = Give a brief description about this teardown
Convert a regular WET Test Case (aka test definition) into a Reusable test
The above script generated by the WET UI is a regular WET test. For a test to be used as a 'reusable test', there are a couple of changes to be made.
- Add the following line as the last entry under the [Common] header
script.path = ./login.rb
(Rememeber that login.rb is the ruby script that is responsible for doing the login action. WET UI creates this script as a part of the Transaction1)
- Remove all the preconditions, transactions and teardowns of this test
That is, just remove every line starting off from [Precondition1]
- That's it. Your login test is now a reusable script
After all editing, the test definition file for the login test should look as follows:
[Common]
name = login
description = This script opens a new browser, navigates to the example server and then logs in
repository.path = ./repository/ostore.xml
results.path = ./results/
obj.timeout = 10
iterations = *
script.path = ./login.rb
Invoking Reusable Tests from other tests
Now that we have created reusable tests, invoking them is very easy. You simply need to say:
call_test(wet_test_path)
where, wet_test_path is the path where your library test resides. For example, if the path to the login test in the previous section was c:\wet_tests\login\test.defs, then from any other test, you can call the login action by using the command
call_test("c:/wet_tests/login/test.defs")
There is also a second variant of calling scripts. Here you can also pass an array of test parameters as the second argument to the call_test command. In the called script, these parameters needs to be processed. See the article about Parameterizing Tests
call_test(wet_test_path, [parameter_array])
