This page is maintained for older versions of Rapise only. The latest documentation can be found at: https://rapisedoc.inflectra.com
Using JavaScript

This section will demonstrate how you can use Rapise to inspect the objects in a web page and Learn them for testing using the JavaScript test script language instead of the Rapise Visual Language (RVL) that was illustrated in the main Web Testing Tutorial.

This is useful in cases where you have more complex applications to test and you want to be able to use the power of a full programming language such as JavaScript to iterate over data, perform calculations and use if�then�else branches to follow different steps during the test.

Learning an Object Using the Web Spy

In the main Test ribbon of Rapise, expand the dropdown list for the �Spy� tool and make sure that �Web Object� is selected:

clip0029

Now, click on the main �Spy� tool icon and Rapise will start the Web Spy:

clip0030

 
Go back to the web page and login to the library information system with the same login/password (librarian/librarian) and click on the �Book Management� menu item so that the list of books is displayed:
 

clip0031

 
Now back in the Web Spy, click on the �Get Snapshot� option to refresh the Web Spy and display the HTML elements (called the DOM tree) that make up this page:
 

clip0032

 

Once it has loaded the DOM tree, you can expand/collapse the elements to see how the web page is constructed. This is useful when testing an application since many of the HTML elements on a page may be used for layout purposes and will not be visible in the browser. In the example page, we have expanded some of the nodes to display the main section of the page and the table that contains the list of  books.

 

In addition, you can use the Track (Ctrl+T) tool to select and item in the web page and then have it be highlighted in the DOM tree. For example if we want to find the cell that contains the book title �Amsterdam�, simply click CTRL+T on the keyboard, move the mouse over the cell in the webpage, wait until the red highlighting rectangle appears and then click CTRL+T again. Rapise will now highlight that item in the DOM Tree automatically:

 

clip0033

 

You can see all of the properties of this HTML element displayed on the right, specifically:

·The tagName is displayed as �TD� (always upper case)

·The innerHTML of the element is displayed (Amsterdam)

·The CSS and XPath for locating this element is displayed

 

If you want to use this object in a Rapise test script, you can simply click the Learn button and the HTML element will be added to the Recording Activity Dialog:

 

clip0034

 

Click Finish and the object will have been added to your test�s Object Tree:

clip0035

 

 

You can now expand this object and drag a test function to your test script. For example if you wanted to get the textual value of the cell in your test, drag the �GetInnerText� function into your test script:

 

clip0036

 

Learning an Object from XPATH

In addition to letting Rapise automatically learn the object from the Web Spy, you can manually enter in XPATH or CSS queries to find matching elements on the page and then learn those for use in your test.

 
For example, suppose we want to dynamically find the row that has the cell containing Amsterdam and then click on its Edit hyperlink.

 

Open up the Web Spy as before:

 

clip0037

 

In the Locators section of the Web Spy, enter in the following to locate the table:

 

//table[@id='MainContent_grdBooks']

 

Now click on the Test XPath button to display the matching results:

 

clip0038

 

clip0039

 

Now that we have matched the table, we need to add dynamic XPath to find any row that has the cell containing �Amsterdam� and find the edit link. You can expand the table and see the rows and cells visually and that will help us create the XPATH:

 

//table[@id='MainContent_grdBooks']//tr/td[text()='Amsterdam']/../td[5]/a

 

This XPath consists of the following elements:

1.Finds the table with the specified ID

2.Find any row inside that table that contains a cell with the text �Amsterdam�

3.For any matching cell, get its parent row and inside the fifth cell, get any hyperlink

In this case that will correctly locate the Edit link for the book �Amsterdam�. Now that we have the correct item identified, click on the �Learn� button to the right of the �Test XPath� button. That will now learn a new object that corresponds to the �Edit Amsterdam� object:

clip0040

Click Finish and the object will have been added to the Object Tree of the current test:

clip0041

 

To click on this object, simply drag the �DoClick� function for the new object from the Object Tree into the test script. This will cause the book details page for Amsterdam to be display during test playback:

clip0042

Since clicking on the Edit link will take you to a different page than where the �Create New Book� link is available, in the example we have added a second instance of the:

SeS('Book_Management').DoClick();

Command, so that Rapise goes back to the main book list page before executing the Create New Book step. If we did not do this, the test would have failed.

Now the line:

SeS('Amsterdam').GetInnerText();

by itself does not do anything, it just gets the text.

So to make the test more useful, we can use the global Tester object to add a step to verify this value. Drag the �AssertEqual� function from the Tester object to your test script just above the SeS(�Amsterdam�) line:

clip0043

Now we need to just consolidate these two lines into the actual test. Using the script editor, change the two lines from:

 Tester.AssertEqual('', null, null);

 SeS('Amsterdam').GetInnerText();

To

 Tester.AssertEqual('The values match', 'Amsterdam', SeS('Amsterdam').GetInnerText());

Now click Play to playback the new test:

clip0044

The test should now pass successfully.