Use an Extracted Value in Code

1 Answer 85 Views
Coded Steps
Adrian
Top achievements
Rank 2
Iron
Iron
Iron
Adrian asked on 02 Jun 2023, 04:44 AM

Hi,

 

I have extracted a value as a test step called 'TruckIDWithQuotes' that I have obtained from an element titled 'TruckDetailsElement'.  The value extracted has quotes "" around it as part of the extracted value, i.e. "abcd".

I want to use this extracted value without the quotes.  How can I create another extracted value without the quotes, 'TruckIdWithoutQuotes', i.e. abcd which I then want to use in a coded step.

I'm assuming I need to use a coded step to "reformat" the extracted value so it doesn't have the quotes?

Can someone please assist.

Thanks

Adrian

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivaylo
Telerik team
answered on 02 Jun 2023, 11:02 AM

Hello Adrian,

I would suggest using the following method to try trimming the quotes from your extracted variable:

Replace("\"", "")

 


So if you add the following line in a coded step:

Log.WriteLine(GetExtractedValue("ExtrVarName").ToString().Replace("\"", ""));
And replace the ExtrVarName with the name of your extracted value you should get it output in the log without the quotes.

If you would like to set the new stripped value as extracted variable please follow this article on how to proceed. I am also adding an example below:

string noQuotes = GetExtractedValue("ExtrVarName").ToString().Replace("\"", ""));
SetExtractedValue("ExtractedValue", noQuotes);


Hope this helps.

Please note that this question is not directly connected to Test Studio but rather more of a programming question. 

 

Regards,
Ivaylo
Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Adrian
Top achievements
Rank 2
Iron
Iron
Iron
commented on 05 Jun 2023, 04:40 AM

Excellent, worked as expected, thankyou.
Ivaylo
Telerik team
commented on 05 Jun 2023, 08:17 AM

You are most welcome, I am glad I was able to help!
Tags
Coded Steps
Asked by
Adrian
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Ivaylo
Telerik team
Share this question
or