How to slect items from list without coded step? I wish to make it Data Driven too.

4 posts, 1 answers
  1. Dipali
    Dipali avatar
    16 posts
    Member since:
    Mar 2012

    Posted 18 Apr 2012 Link to this post

    Hi Telerik Team,

    Scenario to automate:

    User creates few objects in application under test. The names of these objects could be anything which user specifies.

    On some different page of the application I am having a HTML list box of type SELECT. This list gets populated with the object names which  user have created previously. Here I want to select the multiple options from the list. I will be specifying the options to select as a comma separated list in the Excel column.

    I have done it using a coded step. I would like to avoid the coded step. So I would like to know, if there is a way I can do it without coded step?

    Code for the current coded step:

    // Read the options from input Xls file and make a list from comma separted values
    List<string> optionsToSelect = Data["ListOptions"].ToString().Split(new char[]{','},
        StringSplitOptions.RemoveEmptyEntries).ToList<string>();
    var lstBoxTestOptionsSelection = Pages.Page1.FrameFrame00.lstBoxAvailableOptions;
    // Select the given options from the listbox
    foreach(string strOption in optionsToSelect)
    {
        foreach(HtmlOption option in lstBoxTestOptionsSelection.Options)
        {
            if(strOption.Equals(option.Text))
            {
                // Get the index of the option from listbox
                Log.WriteLine(option.Text); 
                var indexToSelect = lstBoxTestOptionsSelection.Options.IndexOf(option);
                Log.WriteLine("Index: " + indexToSelect);
                // Select the option from listbox
                lstBoxTestOptionsSelection.SelectByIndex(indexToSelect);
                // There is another list to which I need to add the selected items so clicking on Add button.
                // Click on Add button to the other list box where we are kepping the selected items
                Pages.Page1.FrameFrame00.BtnAddRSDiv.Click();
                break;
            }
        }
        lstBoxTestOptionsSelection = Pages.Page1.FrameFrame00.lstAvailableRSSelect;
    }

  2. Answer
    Cody
    Admin
    Cody avatar
    3354 posts

    Posted 23 Apr 2012 Link to this post

    Hello Dipali,

    I apologize for the delay responding back to you.

    I think this can be done using a data driven sub-test and not require any code. Take these steps:
    1) Create a new test that simply selects one item from the drop down and clicks the Add button
    2) Modify the Select test step to use "Select by text" instead of "Select by index"
    3) Make this test a data driven test. You might be able to use your existing CSV file or create a new Excel file with the right data.
    4) Use this new test as a sub-test that a parent test calls via our Test-as-step feature.

    Now what will happen is when this subtest gets control, it will run N number of times (once for each row of data) before returning control to the parent test. The net effect will be that all the items you have listed in your source drop down will be selected one at a time and then Added to the target.

    If you are still confused by the above let me know and I'll try to clarify anything that I left unclear.

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Dipali
    Dipali avatar
    16 posts
    Member since:
    Mar 2012

    Posted 26 Apr 2012 Link to this post

    Hi Cody,

    Thanks for the solution. the issue got solved.
  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 26 Apr 2012 Link to this post

    Hi Dipali,

    That's good to know. Thank you for the update!

    Kind regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top