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

Extracting a partial element

1 Answer 123 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lynsey
Top achievements
Rank 1
Lynsey asked on 03 Nov 2011, 10:31 AM
I have a test that uploads a document from my desktop and then the web application returns a message to say 'successfully uploaded document with ID of ABC123'.  I want to extract the document ID part of the message only, Is this possible?  I have tried to do this using the quick tasks but can only extract the whole message.

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 03 Nov 2011, 11:42 AM
Hello Lynsey,
    the whole String:
successfully uploaded document with ID of ABC123 is probably contained within a single HTML element (e.g. a paragraph <p>) and this is why you can only use the "Extract" feature to get the entire String.

You can work around this limitation with a relatively simple coded solution.
You can access and set Extracted values in code as seen here:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/code-samples/general/extracted-variables-in-code.aspx

You can use simple C#/VB logic in order to re-work the Extracted variable to only contain the ID. From there you can change the extracted variable value to the re-worked version. Here's an example of how to do this in code (let's say the string was extracted in a variable "idString"):
String myId = this.GetExtractedValue("idString").ToString(); //Get whole extracted string
 
int n = myId.IndexOf("ID of ")+6; //Get the index of the start of the actual ID.
//The whole string is "successfully uploaded document with ID of ABC123" but we
//we need the content after "ID of". We get the start index of this string and add 6 to it
//because the string itself contains 6 characters
 
myId = myId.Substring(n); //Remove the contet we don't need
this.SetExtractedValue("idString",myId); //Set the new value to the extracted variable
  
Log.WriteLine(this.GetExtractedValue("idString").ToString()); //Write the ID to the Log file

Let me know how it goes.

All the best,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Lynsey
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or