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

Extracting value from web test

4 Answers 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nicky
Top achievements
Rank 1
Nicky asked on 29 Nov 2016, 04:01 AM

I am a newbie to Test , I just couldn’t find the answer directly from the help documents!

Question: I would like to extract a particular value from the I am testing and write it to a text file.

I tried

And in coded test:
public void MyFirstCodeTest_CodedStep()
        {
            string myData = GetExtractedValue(seconds);
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\source.txt");
            file.WriteLine("Expected Result: "+ myData);
            file.Close();
}
But it doesn’t help!

Can you suggest a please?

Please email the answer to minu@hot.co.nz

Thanks!

4 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 29 Nov 2016, 09:16 AM
Hi Nicky,

What is exactly not working in your code? The extraction of the variable or the writing into the file?

Please let me know so I can help you with the code.

Thank you!

Regards,
Boyan Boev
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nicky
Top achievements
Rank 1
answered on 29 Nov 2016, 08:02 PM

Hi Boyan,

My test steps are:

Click 'SearchButtonLink'

Extract 'TextContent' on 'TestDiv' into DataBingVariable $(TestDiv)

             DataBindVariableName: seconds

In my Code Behind File I got:

        public IList<AutomationStepResult> stepResults { get; set; }
        public override void OnAfterTestCompleted(TestResult result)
        {

            string resultMessage = Convert.ToString(result.Message);
            string myData = GetExtractedValue('seconds');
            System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\source.txt");

            file.WriteLine(resultMessage);
            file.WriteLine("Expected Result: "+ myData);
            file.Close();
        }
   There is a compiler error at the line for  GetExtractedValue('seconds')

error: Too many characters in character literal. 

Basically, I cannot get the value of 'seconds' in the code!

Thank you!

0
Nicky
Top achievements
Rank 1
answered on 30 Nov 2016, 02:16 AM

Hi Boyan,

The issue is resolved when I changed

string myData = GetExtractedValue(seconds);

with:

object myData = GetExtractedValue(“seconds”);

 

Thanks anyways :)

0
Boyan Boev
Telerik team
answered on 30 Nov 2016, 08:24 AM
Hi Nicky,

You can use string myData = GetExtractedValue("seconds").ToString(); with the ToString method it should also work.

Hope that helps.

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