Skipping Iterations

4 posts, 1 answers
  1. Aswin
    Aswin avatar
    18 posts
    Member since:
    Feb 2013

    Posted 23 May 2013 Link to this post

    Hi... I've a scenario of simple form filling of two text fields and submitting. I'm data driving the test via an Excel Sheet.

    Here is a sample of my Excel data.

    1 Fruit Apple
    2 Fruit Orange
    Object Chair
    4 Object Desk

    It is obvious that the sheet have some repeated entries in a column. Since my form remembers the last iteration values used, I don't want Test Studio to erase the text field and type the same again. It is consuming more time.

    Is there any way to create a check/verify step (Either GUI or coded), such as Test Studio should skip the cell value if it is same as previous. (No skipping the whole iteration, just leaving out the cell value). Help me out in this, I'm ready to explain more, Thanks !

    Note: I'm working on Silverlight platform.
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 24 May 2013 Link to this post

    Hi Aswin,

    Unfortunately this is not possible via the Test Studio UI. In order to create a logical statement against the contents of a cell in your data before/during the iteration of a data driven test, you need to use code to read the excel file and compare the values of the current and previous iteration and then skip the next iteration based on the outcome.

    Here are a few code samples that would help you in achieving this:
    Non-iterative data driving 
    Skip a certain iteration 
    Write into a data source
     
    You will have to combine the approaches shown in these articles and adapt it for your usecase. I'm sure you can find a lot of additional information/code samples on the Internet.

    Regards,
    Plamen
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Aswin
    Aswin avatar
    18 posts
    Member since:
    Feb 2013

    Posted 27 May 2013 Link to this post

    Hi Plamen,

    I don't want to skip the iteration. Just the values, so that I thought I can avoid deleting some value and then typing the same values again in a field.

    Is that possible in code? Can you get me any samples, Thanks in advance.

  4. Answer
    Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 27 May 2013 Link to this post

    Hi Aswin,

    Yes, it is possible to do that using code. The articles I pointed you to are for different scenarios, but you should be able to adapt them to suit your needs.

    For example, let's take the first article "Non-iterative data driving". This article is about how to take different sequential row from the data source on each test execution and execute only that row without going through all iteration. However if you take a closer look, you'll notice that it also demonstrates how to get and set a value in an XML file and you can easily accomplish your scenario by taking only this information from the context of the article.

    Here are the steps:
    1. Create an XML file as seen in the article:
    <?xml version="1.0" encoding="utf-8"?>
    <IterationValue>
      <iteration>null</iteration>
    </IterationValue>
    I have attached the xml file to this ticket(IterationValue.zip).

    2. Add project references and using statements to System.Xml and System.Xml.Linq

    3. Implement the LoadValue and SaveValue methods in the code behind:
    // Add your test methods here...
    public void SaveValue(string iterationText)
    {
        string path = @"C:\IterationValue.xml";
        XElement e = new XElement("IterationValue");
        e.Add(new XElement("iteration", iterationText));
        e.Save(path);
    }
     
     
    public string LoadValue()
    {
        string path = @"C:\IterationValue.xml";
        XElement e = XElement.Load(path);
        string iterationText = e.Element("iteration").Value;
        return iterationText;
    }

    4. Compare the text used in the previous iteration to the text from the current iteration. You can take the value for the previous iteration from the XML file and the value for the current iteration from the data source.
    Here's a sample code:
    [CodedStep(@"Enter text 'Telerik' in 'GbqfqText'")]
    public void WebTest_CodedStep()
    {
        string currentIteration = Data["Col1"].ToString();           
        string previousIteration = LoadValue();
         
        //Check whether text for the current iteration is the same as the text for the previous iteration
        if (currentIteration != previousIteration)
        {
            //Enter the text from the current iteration
            Actions.SetText(Pages.Google.GbqfqText, currentIteration);
        }
        else
        {
            //Enter empty string
            Actions.SetText(Pages.Google.GbqfqText, String.Empty);
        }
    }
    Using the code above, if the value for the current iteration is the same as the previous iteration, it will enter an empty string in the Google search field.

    At the end of the test(as a very last step), create a coded step that will set the value of the current iteration in the xml file, replacing the previous value. This value will be used on the next test iteration.     
    [CodedStep(@"New Coded Step")]
    public void WebTest_CodedStep1()
    {
        string previousIteration = Data["Col1"].ToString();
        SaveValue(previousIteration);
    }
     
    See this video demonstrating the execution. The sample project is also attached. I am sure that there are many different ways to accomplish your scenario, but it's up to you to research and decide which one is the best for you. 

    Let me know if you need further assistance on this.

    Regards,
    Plamen
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top