Skip to content

Scenarios

Purpose

Note: As of Rapise 8.0, it is recommended to use Test Cases and Modules / Page Objects for creating scenarios and maintaining reusable building blocks, respectively.

Scenarios serve as reusable building blocks that can be incorporated into your test scripts. They provide a way to structure and organize your tests, making them more modular and maintainable. Scenarios can be included in both fully automated test scripts and predominantly manual test scripts.

Another valuable application of scenarios is in Web Service test recording. When you record script steps for a Web Service test and click on Create Script, the recorded JavaScript steps are appended to the Test() function. At this point, you can wrap them into separate scenarios using the method described in this chapter.

Creating Scenarios

For example, consider the following Rapise test, recorded from our sample library information web application:

function Test()
{
    //Click on Log In
    SeS('Log_In').DoClick();        
    //Set Text librarian in Username:
    SeS('Username_').DoSetText("librarian");
    //Set Text librarian in Password:
    SeS('Password_').DoSetText("librarian");
    //Click on ctl00$MainContent$LoginUser$LoginButton
    SeS('ctl00$MainContent$LoginUser$Logi').DoClick();
    //Click on Book Management
    SeS('Book_Management').DoClick();
    //Click on (Create new book)
    SeS('_Create_new_book__').DoClick();
    //Set Name:
    SeS('Name_').DoSetText(g_book_name);
    //Select Author:
    SeS('Author_').DoSelect(g_book_author);
    //Select Genre:
    SeS('Genre_').DoSelect(g_book_genre);
    //Click on ctl00$MainContent$btnSubmit
    SeS('ctl00$MainContent$btnSubmit').DoClick();
    //Click on Log Out
    SeS('Log_Out').DoClick();
}

To break up this monolithic test into individual functions (scenarios), highlight the desired section (for example, the Login steps):

scenarios_1

Then right-click on the section and choose Extract User Scenario:

scenarios_2

In the dialog box that appears, give the scenario a name (e.g., 'Login'):

scenarios_3

This will extract the highlighted section into its own scenario.

The Main.js file will be updated as follows:

function Test()
{
    //Call scenario Login
    Login();

    //Click on Book Management
    SeS('Book_Management').DoClick();
    //Click on (Create new book)
    SeS('_Create_new_book__').DoClick();
    //Set Name:
    SeS('Name_').DoSetText(g_book_name);
    //Select Author:
    SeS('Author_').DoSelect(g_book_author);
    //Select Genre:
    SeS('Genre_').DoSelect(g_book_genre);
    //Click on ctl00$MainContent$btnSubmit
    SeS('ctl00$MainContent$btnSubmit').DoClick();
    //Click on Log Out
    SeS('Log_Out').DoClick();
}

The User.js file will contain the following:

/** @scenario Login */
function Login()
{
    //Click on Log In
    SeS('Log_In').DoClick();        
    //Set Text librarian in Username:
    SeS('Username_').DoSetText("librarian");
    //Set Text librarian in Password:
    SeS('Password_').DoSetText("librarian");
    //Click on ctl00$MainContent$LoginUser$LoginButton
    SeS('ctl00$MainContent$LoginUser$Logi').DoClick();
}

Usage in Automated Tests

When you create a new test in Rapise, it includes a Main.js file for the main test code and a User.js file for user-defined functions (scenarios). For example, in the following test:

function Test()
{
    Login();
    CreateBook(g_book_name, g_book_author, g_book_genre);
    Logout();
}

The test function calls three scenarios that comprise the main test. The scenarios themselves are JavaScript functions:

/** @scenario Login */
function Login()
{
    //Click on Log In
    SeS('Log_In').DoClick();        
    //Set Text librarian in Username:
    SeS('Username_').DoSetText("librarian");
    //Set Text librarian in Password:
    SeS('Password_').DoSetText("librarian");
    //Click on ctl00$MainContent$LoginUser$LoginButton
    SeS('ctl00$MainContent$LoginUser$Logi').DoClick();
}

/** @scenario Logout */
function Logout()
{
    //Click on Log Out
    SeS('Log_Out').DoClick();
}

/** @scenario CreateBook */
function CreateBook(name, author, genre)
{
    //Click on Book Management
    SeS('Book_Management').DoClick();
    //Click on (Create new book)
    SeS('_Create_new_book__').DoClick();
    //Set Name:
    SeS('Name_').DoSetText(name);
    //Select Author:
    SeS('Author_').DoSelect(author);
    //Select Genre:
    SeS('Genre_').DoSelect(genre);
    //Click on ctl00$MainContent$btnSubmit
    SeS('ctl00$MainContent$btnSubmit').DoClick();

    //Verify that the Book is added to the grid
    //We need to xpath query the grid to see if any
    //added rows match the item added
    var tr = FindRowByName(name);
    Tester.Assert('Book was added successfully [TS:5]', tr.length != 0);
}

In the Object Tree, you will see these user functions/scenarios displayed:

object_tree_user_functions

You can then drag and drop them into the test script editor to include in the main test script.

Usage in Manual Tests

When you create a new test in Rapise, it includes a Main.js file for the main test code and a User.js file for user-defined functions (scenarios). For example, you may have the following scenario defined in the User.js file:

/** @scenario Login */
function Login()
{
    //Click on Log In
    SeS('Log_In').DoClick();        
    //Set Text librarian in Username:
    SeS('Username_').DoSetText("librarian");
    //Set Text librarian in Password:
    SeS('Password_').DoSetText("librarian");
    //Click on ctl00$MainContent$LoginUser$LoginButton
    SeS('ctl00$MainContent$LoginUser$Logi').DoClick();
}

You can now include it in a manual test step by simply prefixing the test step description with an "@" symbol to denote that it is a scenario:

@Login();

Then, when the manual test is executed, that step will be passed to the scripting engine for automated execution.

Example

If you open the CreateNewBook sample (located at C:\\Users\\Public\\Documents\\Rapise\\Samples\\CreateNewBook), you will see a test that has multiple scenarios.

See Also