Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to parameterize a path URL (not a form)

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited November 2005 in FAQ
using a datasource
The following are the steps to make a direct request to a url, and parameterize that URL with values from a datasource. Note, these steps assume you have already added a datasource to your project.

1) Create a path that leads up to the point where you would like to make a direct request to a parameterized URL
2) In the path you have created, select the last (final) node
3) In the right-hand panel, click the Actions tab
4) Check the Pre-Traversal checkbox
5) Under the Actions tab, for the Language option, select JavaScript
6) For Implementation, select the Text radio button
7) Enter the following code in the text box:
CODE
//data source name = actual data source name
var dsn = "datasourcename";
//column name = actual column name
var col = "columnname";

function getDataSourceValue(node, methodToolContext) {
   var myvalue = methodToolContext.getValue(dsn, col);
   var pathContext = methodToolContext.getParentContext();
   pathContext.put("myvalue", myvalue);
}

function addDataSources(context) {
 return dsn
}
8) In the code above, change the value of dsn to the actual name of the data source you want to use
9) In the code above, change the value of col to the actual name of the column you want to use

This configuration tells WebKing to grab data from dsn in column col and store it under the name myvalue to be used later in the path. This action takes place before each time this node in the path is visited.

10) Right-click the last node in the path
11) Choose Add Javascript Test
12) In the dialog pop-up, click New
13) In the text space provided, enter the following code:
CODEcontext = navigator.getContext();
var myvalue = context.get("myvalue");
// use the actual address you want to request with this node
document.location.href =
    "www.parasoft.com/page.jsp?var=" + myvalue;
14) Edit the www.parasoft.com/page.jsp?var= part to be the URL you are interested in requesting
15) Click OK for the remaining dialogs

This adds a JavaScript test which will make a request to the given URL with the datasource value stored in myvalue appended to the end.

Your path is now configured to use a data source to make a direct request to a URL, with a parameterized value from your data source.

Now that you are done, you should test that the path is working correctly by:

1) Right-click the last node (the JavaScript test)
2) Choose Test Path
3) Ensure that WebKing does not report any unexpected errors