This is a migrated thread and some comments may be shown as answers.

REGEX extraction and URL manipulation

4 Answers 113 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 11 Apr 2017, 07:00 PM

Hello,

New to using this tool so this may be a bit complex.  Currently I am trying to do some URL manipulation in order to get an access token so that I can then use the token to login a specific admin account.  

The situation is that I go to a URL to get a access token which is returned as a JSON object.  {"token":"00000000-0000-0000-0000-000000000000"}  Is there a way that I can use regex as part of the extraction to take just the info between the second set of quotes?  And then also take that extracted data and add that on to another data driven URL?

4 Answers, 1 is accepted

Sort by
0
Accepted
Aaron
Top achievements
Rank 1
answered on 11 Apr 2017, 08:10 PM

One easy-ish way of doing it in a coded step:

            // If you're using an extract step to get this text, instead of the = "{blah blah blah}" I have, you could use GetExtractedValue(nameOfYourVariable).ToString()
           string token = "{\"token\":\"00000000-0000-0000-0000-000000000000\"}";
            // Same thing as above, I'm not sure where you're getting this URL from, so you would just grab the value and set it to a variable in code.

            string url = "https://some.url/";
            // We create an array of strings, with each index of the array representing some value before/after a quotation mark (").
            string[] explode = token.Split('"');
            // With the example text you gave me above, if there was nothing else in the text, 3 should be the right index, but you could just play around with it until you got the text you needed.
            string guid = explode[3];

            // Combine those two strings together to build the URL you would navigate to, and call it in code.
            ActiveBrowser.NavigateTo(url + guid); 

 

Alternatively instead of the ActiveBrowser.NavigateTo(url+guid) you could use SetExtractedValue("navigateUrl", url + guid), and then use an actual Navigate To step after the coded step, and data bind the navigateUrl extracted value.

0
Aaron
Top achievements
Rank 1
answered on 11 Apr 2017, 08:11 PM
In the example I just posted, it would navigate to the url: https://some.url/00000000-0000-0000-0000-000000000000
0
Richard
Top achievements
Rank 1
answered on 12 Apr 2017, 12:39 PM
Thanks Aaron, the way that you mentioned is probably an easier way of doing this then the path that I was starting to head down.
0
Elena
Telerik team
answered on 12 Apr 2017, 01:35 PM
Hello,

@Aaron: Thank you for interfering into the forum posts and providing solutions to other customers! I really appreciate it! 

@Richard: I am glad to hear you found the proposed solution useful. Please do not hesitate to contact us again in case of any further queries! 

Regards,
Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Richard
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Elena
Telerik team
Share this question
or