Need to use Regular Expressions in our UFT API Tests
Category:
Question ID: 110069
2
0

I need to use some regular expressions in my API tests. I’m using UFT 15.0.2. I can’t seem to figure out how to do it, and the help documentation doesn’t really have much info on it.

It seems to indicate at this page that you can use REGEX in API tests, but it doesn’t really explain how.

How do you implement using REGEX in API tests??

Marked as spam
Posted by (Questions: 387, Answers: 66)
Asked on February 24, 2021 10:03 am
89 views
Answers (1)
2
Private answer

I was researching this too and found that Micro Focus recently published a KM article about this.

The article says that "Regex requires declaration at the top of the script:"

using System.Text.RegularExpressions;

And gives the following examples:

namespace Script
{
using System;
...
using System.Text.RegularExpressions;

[Serializable()]
public class TestUserCode : TestEntities
{
...

Then they give some sample code:

//Define variables
string sText;
bool bRxMchFnd; //true/false

sText = "abcd";

this.Context.UserLogger.Info(" String: '" + sText + "'");

//- Pattern found
var RxMatch = Regex.Match(sText, "bc");
bRxMchFnd = RxMatch.Success; //True
this.Context.UserLogger.Info(" Match 'bc': " + bRxMchFnd);

//- Pattern NOT found
RxMatch = Regex.Match(sText, "xxx");
bRxMchFnd = RxMatch.Success; //False
this.Context.UserLogger.Info(" Match 'xxx': " + bRxMchFnd);

which gives the following output:

String: 'abcd'
Match 'bc': True
Match 'xxx': False

Marked as spam
Posted by (Questions: 17, Answers: 807)
Answered on February 24, 2021 10:16 am
0
That's great. This will be really helpful! Thanks!
( at February 24, 2021 10:21 am)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top