Forum Discussion

jhcovington's avatar
jhcovington
New Contributor
13 years ago

User Variables within Regular Expressions?

I am attempting to create a new data selector item that will capture a value returned in a http response. The page returns a list of users, including one that was created on an earlier page in the test. Later in the test, the unique ID assigned by the database to the new user will be required. So my regular expression pattern used to match the new item needs to include variable information unique to that user (e.g. last name, first name, ssn, etc.). Is there a  way to embed a user variable within the regular expression pattern?



Here is a snippet of the html response that I will parse:



<tr id='336'>

<td><pre style='margin-botton: 0px">Smith</pre></td>

<td><pre style='margin-botton: 0px">John</pre></td>

</tr>

<tr id='337'>

<td><pre style='margin-botton: 0px">Jones</pre></td>

<td><pre style='margin-botton: 0px">Robert</pre></td>

</tr>



So, assuming that user 336 was created earlier by supplying user variables with @LastName=Smith and @FirstName=John, how do I ensure that I get @UserID=336 for later use in the test script?

3 Replies

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Hi James,


    As far as I know, currently, variables cannot be used in data selector regular expressions.

    BTW, is it possible to use the test values (John, Smith) in the regular expression? In your case, the expression is similar to the following one:


    Expression:

    <tr id="([0-9]{1,})">\r\n<td><pre style='margin-botton: 0px">Smith</pre></td>\r\n<td><pre style='margin-botton: 0px">John</pre></td>


    Subexpression: $1

  • That would only work for one set of data, and I'm looking for a solution that would work for N different virtual users.
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    I see. Unfortunately, currently, LoadComplete does not support variables in data selectors' expressions.


    A possible workaround is to use some specific last names for these virtual users, for instance, Smith1, Smith2, Smith3,.. SmithN. In this case, perhaps, you will be able to create a regular expression that will work for such "strange" last names and ignore users with "human" last names.


    I don't know your application and the data you use; this is just a quick idea. :-)