Extracting details to log

4 posts, 0 answers
  1. Ben
    Ben avatar
    2 posts
    Member since:
    Jul 2012

    Posted 18 Apr 2013 Link to this post

    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();
    }
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 23 Apr 2013 Link to this post

    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
  3. Ben
    Ben avatar
    2 posts
    Member since:
    Jul 2012

    Posted 23 Apr 2013 Link to this post

    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()
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 25 Apr 2013 Link to this post

    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
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!