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

Extracting details to log

3 Answers 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ben
Top achievements
Rank 1
Ben asked on 18 Apr 2013, 01:18 PM
Hi,

I am performing a test which logs in to a site and extracts (or ideally will compare) certain field values to a log file/excel.

I have got it working for a basic test (one extracted value):

System.IO.StreamWriter file = new System.IO.StreamWriter("C:/mylog.txt");
String a = Convert.ToString(GetExtractedValue("fieldVal"));//This could go on forever...
 
{
    //file.WriteLine(ToString(fieldVal));
    file.WriteLine("Test log entry Values Returned: " + a + " "); //...As would this
    file.NewLine();
    file.Close();
}


The problem lies with the amount of values I will be extracting. Is there no way to use the DataBindVariableName, rather than having to GetExtractedValue from each of them? I won't be changing any values, just logging or comparing them.

For example:

System.IO.StreamWriter file = new System.IO.StreamWriter("C:/mylog.txt");
//String a = Convert.ToString(GetExtractedValue("fieldVal"));//Now redundant
  
{
    //file.WriteLine(ToString(fieldVal));
    file.WriteLine("Test log entry Values Returned: " + fieldVal + " "); //...This would likely be some sort of Loop
    file.NewLine();
    file.Close();
}

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 23 Apr 2013, 01:12 PM
Hi Ben,

The only way to achieve that is to use directly GetExtractedValue method in file.WriteLine:

System.IO.StreamWriter file = new System.IO.StreamWriter("C:/mylog.txt");

file.WriteLine("Test log entry Values Returned: " + GetExtractedValue
("fieldVal").ToString() + " ");

file.Close();

Here is a video demonstration.

Let me know if you need further assistance.
 

Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ben
Top achievements
Rank 1
answered on 23 Apr 2013, 01:27 PM
Thank you Royan, that is pretty much what I was looking for.

I still wonder if there is a more efficient way of cycling through all extracted values to repeat this line. Test Studio seems to pull the name of the element from the site.

For example, is there a method to do this:

For each (extractedValue)

{
file.WriteLine(GetExtractedValue(extractedValue).ToString() + Environment.NewLine);
}
file.close()
0
Boyan Boev
Telerik team
answered on 25 Apr 2013, 11:26 AM
Hello Ben,

Unfortunately Test Studio doesn't create a collection which contains all extracted value. 

A possible approach is to create your own collection and add the element after every extraction:

List<string> myList = new List<string>();
SetExtractedValue("extractedValue", "data");
myList.Add(GetExtractedValue("extractedValue").ToString());

Hope this helps.

Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Ben
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Ben
Top achievements
Rank 1
Share this question
or