Drop Down list verifications

18 posts, 1 answers
  1. Corina
    Corina avatar
    17 posts
    Member since:
    Feb 2013

    Posted 16 Sep 2013 Link to this post

    Hello,

    Having a custom Kendo drop down list, I was wondering if the following things can be checked (and how):
    1. The number of elements in it
    2. Check if the elements are in a pre-established order (for example, if they are sorted alphabetically)
    3. Check the position of an element in the list (for example, having the values "first", "second", "third", check that the value "second" is always on position 2 in the list)
    4. Would it be possible to get a video example of how to check that for one click, the drop down list is expanded and on another click it is collapsed? (on a standard Kendo drop down control)

    Thank you,
    Corina


  2. Answer
    Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 18 Sep 2013 Link to this post

    Hello Corina,
    I hope your evaluation is going well.

    Now, because Test Studio employs translators for Telerik-Manufactured widgets - automation tasks will be made easier for these widgets. Unfortunately currently we don't have translators for all of the Kendo widgets and specifically we don't have a translator for the Kendo DropDownList. You will need to resort to a coded solution in order to achieve the automation you're looking for.

    Here's the breakdown:

    1. The number of elements in it - you will need to locate the list that contains the items from the DropDownList. Then you can add it into your project and you're ready to invoke all sorts of coded verifications for it. Here's how to do it:

    This example shows you how to get all the items in code:
    http://screencast.com/t/HQglQiQATUQA

    From there you're free to implement whatever verifications you want. If you need to fail a step from code - just throw any exception. Additionally any bit of information that is part of your project can be access in code (eg a datasource, extracted variables etc).

    4. Would it be possible to get a video example of how to check that for one click, the drop down list is expanded and on another click it is collapsed? (on a standard Kendo drop down control)

    This is doable without any code: while the dropdown is open: use Freeze Mode and add a VerifyIsVisible verification on any item inside the dropdownlist. If on playback this step passes --> the dropdown is open. And you can also add a VerifyIsNotVisible in the same way to verify that the dropdown is then closed.

    We encourage you to go ahead and log a Translator for the Kendo DropDownList control as a Feedback item here:
    http://feedback.telerik.com/Project/117

    I hope this helps.

    Regards,
    Stoich
    Telerik
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. Corina
    Corina avatar
    17 posts
    Member since:
    Feb 2013

    Posted 18 Sep 2013 Link to this post

    Hello,

    Thank you for your detailed answer, that pretty much covers my questions.

    Regards,
    Corina
  4. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 06 Dec 2017 Link to this post

    I am able to get the DropDownList items based on the demonstration but please help me how to click on desired item from the DropDownList either ByValue or ByText or ByIndex.

     

    Thank you

  5. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    971 posts

    Posted 11 Dec 2017 Link to this post

    Hi Deepa,

    Thank you for reaching us out. 

    Could you please provide a sample test to double check what the recorded element is and how to proceed. Thank you in advance! 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  6. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 17 Dec 2017 in reply to Elena Tsvetkova Link to this post

    Hi Elena,

    My apologies for the delayed response. I am talking about the example given by stoich and based on that example i have replicated the scenario by locating the list that contains the items from the drop down list. I have added it to my project and identified the no.of items in the drop down and wrote each item with its index into the log but now i would like to know how can i click on a desired item from the dropdown list either ByValue, ByText or ByIndex.

    https://demos.telerik.com/kendo-ui/dropdownlist/remotedatasource

    Coded Step:

    [CodedStep(@"New Coded Step")]
    public void Handling_Dropdown_List_with_Coded_Step_CodedStep()
    {
        HtmlControl items = Pages.RemoteDataBindingDemo.Products; //Get the list of items
         
        //Write the number into the log
        Log.WriteLine("Number of items in drop down is: " + items.ChildNodes.Count.ToString());
         
        //Write each item with its index into the log
        int counter=0;
        foreach(Element e in items.ChildNodes){
            Log.WriteLine("Item "+counter.ToString()+" :"+e.TextContent);
        counter++;
        }
    }

     

    Thank you,

  7. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    971 posts

    Posted 20 Dec 2017 Link to this post

    Hello Deepa,

    Thank you for getting back to me and sharing additional details. 

    Please find a sample code how to search an item in a table and click on a particular one. I hope this will be helpful to you to accomplish your current task to click on an item from the list. 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  8. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 22 Dec 2017 in reply to Elena Tsvetkova Link to this post

    Hi Elena,

    I modified my code based on provided sample code

    [CodedStep(@"New Coded Step")]
    public void Handling_Dropdown_List_with_Coded_Step_CodedStep()
    {
        string search = "Aniseed Syrup";
         
        HtmlControl items = Pages.RemoteDataBindingDemo.Products; //Get the list of items
         
        //Write the number into the log
        Log.WriteLine("Number of items in drop down is: " + items.ChildNodes.Count.ToString());
         
        //Write each item with its index into the log
        int counter=0;
        foreach(Element e in items.ChildNodes){
            Log.WriteLine("Item "+counter.ToString()+" :"+e.TextContent);
            if(e.TextContent.Equals(search)){
                Log.WriteLine("Droplist Element Found: "+e.TextContent);
                e.Click();             
            }
        counter++;
        }
     }

     

    It gives me an error saying that

    error CS1061: 'ArtOfTest.WebAii.ObjectModel.Element' does not contain a definition for 'Click' and no extension method 'Click' accepting a first argument of type 'ArtOfTest.WebAii.ObjectModel.Element' could be found (are you missing a using directive or an assembly reference?).

    Can you please help me out here.

    Thank you

  9. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 27 Dec 2017 Link to this post

    Hello Deepa,

    The problem comes from the "e" definition in the "foreach" statement. If you check here, you will notice that the Element class does not contain Click() method. Once you are dealing with list items it is better to change "Element e" to "HtmlListItem e" in the "foreach" statement.

    The same is valid for the "items" definition. When you know the type of the element it is better to use it directly when defining it. Instead of "HtmlControl items " it will be better to use "HtmlUnorderedList items ".

    You may find more information on the html control elements here.

    I hope these directions are helpful.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  10. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 27 Dec 2017 in reply to Nikolay Petrov Link to this post

    Hi Nikolay,

    I tried the changes and it resulted in 2 errors:

    error CS0266: Cannot implicitly convert type 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl' to 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlUnorderedList'. An explicit conversion exists (are you missing a cast?)

    error CS0030: Cannot convert type 'ArtOfTest.WebAii.ObjectModel.Element' to 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlListItem'

     

    Changes made:

    [CodedStep(@"New Coded Step")]
    public void Handling_Dropdown_List_with_Coded_Step_CodedStep()
    {
        string search = "Aniseed Syrup";
         
        HtmlUnorderedList items = Pages.RemoteDataBindingDemo.Products; //Get the list of items
         
        //Write the number into the log
        Log.WriteLine("Number of items in drop down is: " + items.ChildNodes.Count.ToString());
         
        //Write each item with its index into the log
        int counter=0;
        foreach(HtmlListItem e in items.ChildNodes){
            Log.WriteLine("Item "+counter.ToString()+" :"+e.TextContent);
            if(e.TextContent.Equals(search)){
                Log.WriteLine("Droplist Element Found: "+e.TextContent);
                e.Click();             
            }
        counter++;
        }
     }
  11. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 29 Dec 2017 Link to this post

    Hello Deepa,

    The problem this time come from "items" element properties in the foreach condition. It supposed to be items.Items instead of  item.ChildNodes. You could find more on HtmlUnorderedList class properties in this doc page.

    Please, refer to this sample code that is working on our demo page:

    string search = "Aniseed Syrup";
     
    //Get the list of items
    HtmlUnorderedList items = Find.ById<HtmlUnorderedList>("products_listbox");
     
    //Write the number into the log
    Log.WriteLine("Number of items in drop down is: " + items.Items.Count().ToString());
     
    //Write each item with its index into the log
    int counter = 0;
    foreach (HtmlListItem e in items.Items)
    {
        Log.WriteLine("Item " + counter.ToString() + " :" + e.TextContent);
         
        if (e.TextContent.Equals(search))
        {
            Log.WriteLine("Droplist Element Found: " + e.TextContent);
            e.Click();
        }
        counter++;
    }

    I hope this clarification helps.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  12. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 29 Dec 2017 in reply to Nikolay Petrov Link to this post

    I should have used items.Items instead of item.ChildNodes.

    Thank you so much for your help nikolay.

  13. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 02 Jan Link to this post

    Hi Nikolay,

    How to handle in case of select statement ? I included few more properties of the select statement in the screenshot.

    I tried to apply the same code to it but it resulted with an exception saying that "Fail' : 14. New Coded Step
    ------------------------------------------------------------
    Failure Information:
    ~~~~~~~~~~~~~~~
    Exception thrown executing coded step: 'New Coded Step'.
    InnerException:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at TestProject1.Handling_Dropdown_with_Coded_Step.Handling_Dropdown_with_Coded_Step_CodedStep()"

    [CodedStep(@"New Coded Step")]
    public void Handling_Dropdown_with_Coded_Step_CodedStep()
    {
        string s = "Mr.";
         
        // Get the list of items
        HtmlUnorderedList items = Find.ById<HtmlUnorderedList>("TitleItems");
         
        //Write the number of items into the log
        Log.WriteLine("Number of items in drop down is: " + items.Items.Count().ToString());
         
        //Write each item with its index into the log
        int counter=0;
        foreach(HtmlListItem e in items.Items){
            Log.WriteLine("Item "+ counter.ToString() +" :" + e.TextContent);
            if(e.TextContent.Equals(s)){
                Log.WriteLine("Droplist Element Found: "+ e.TextContent);
                e.Click();
            }
        counter++;
        }
    }
  14. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 02 Jan Link to this post

    Hi Deepa,

    This element seems to be regular Html select element. You could use HtmlSelect element framework wrapper to find it. Once you introduce a proper find expression and locate this element you could work with its methods and properties. More information on this element you could find here.

    The current exception message indicates that the element is not found according the introduced find logic. More on find expression construction you could find here and here.

    I hope this pointers are helpful.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  15. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 03 Jan in reply to Nikolay Petrov Link to this post

    Hi Nikolay,

    Thanks for pointing me to the right direction. I tried with the below code and it throwed me an exception.

    [CodedStep(@"New Coded Step")]
    public void TC_CUST_PAT_DMGRPHS_018_CodedStep1()
    {
        HtmlSelect dd = ActiveBrowser.Find.ByAttributes<HtmlSelect>("id=focusProcess");
        dd.SelectByIndex(2);
    }

     

    - 'Fail' : 14. New Coded Step
    ------------------------------------------------------------
    Failure Information:
    ~~~~~~~~~~~~~~~
    Exception thrown executing coded step: 'New Coded Step'.
    InnerException:
    ArtOfTest.WebAii.Exceptions.FindException: Find Details:
    - FindParam used: [Find logic: Use 'AttributesOnly' where (id=focusProcess) ]
    - Start Element: null

     ---> System.ArgumentNullException: Start reference element can't be null. Please make sure the DOM is loaded by either calling NavigateTo() to a page or add browser RefreshDomTree() call prior to the code which needs the DOM.
    Parameter name: Reference
       at ArtOfTest.WebAii.Core.Identification.ValidateReferenceElement(Element reference)
       at ArtOfTest.WebAii.Core.Identification.FindElement(FindParam param, Element reference, Boolean ignoreTestRegionTags, String& searchLog)
       at ArtOfTest.WebAii.Core.Find.ByParam(FindParam param, Element reference)
       --- End of inner exception stack trace ---
       at ArtOfTest.WebAii.Core.Find.ByParam(FindParam param, Element reference)
       at ArtOfTest.WebAii.Core.Find.ByParam(FindParam param)
       at ArtOfTest.WebAii.Core.Find.ByAttributes(String[] nameValuePairs)
       at ArtOfTest.WebAii.Core.Find.ByAttributes[TControl](String[] nameValuePairs)
       at TestProject1.TC_CUST_PAT_DMGRPHS_018.TC_CUST_PAT_DMGRPHS_018_CodedStep1()

  16. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 08 Jan Link to this post

    Hi Deepa,

    Thank you for the additional information provided.

    From the screen-shot it seems that the select element appears after clicking a button of the application. Due to very fast execution of the test the element could not be loaded at the time this coded steps is executed. This is the indication of the exception you have in the log.
    I suggest to use an execution delay (System.Threading.Thread.Sleep(10000)) and ActiveBrowser.RefreshDomTree() before to search for and interact with the select element.

    I hope this will resolve the problem.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  17. Deepa
    Deepa avatar
    9 posts
    Member since:
    Feb 2015

    Posted 09 Jan in reply to Nikolay Petrov Link to this post

     Hi Nikolay,

    Thanks for the walk through. It executed fine this time but the dropdown wasn't opened and dropdown item was not selected but it shows the coded step as passed.

    [CodedStep(@"New Coded Step")]
    public void TC_CUST_PAT_DMGRPHS_018_CodedStep1()
    {
        HtmlSelect dd = ActiveBrowser.Find.ByAttributes<HtmlSelect>("id=focusProcess");
        System.Threading.Thread.Sleep(30000);
        ActiveBrowser.RefreshDomTree();
        dd.SelectByIndex(2);
    }

     

     

  18. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 10 Jan Link to this post

    Hello Deepa,

    The correct order of the code lines in the coded step should be:

    // add execution delay 
    System.Threading.Thread.Sleep(30000);
    // refresh the DOM
    ActiveBrowser.RefreshDomTree();
    // locate the select element
    HtmlSelect dd = ActiveBrowser.Find.ById<HtmlSelect>("id=focusProcess");
    // print its ID in the log to verify that it was found properly
    Log.WriteLine(dd.ID.ToString());
    // select by index
    dd.SelectByIndex(2);

    Try to use different Select method from the HtmlSelect class if the SelectByIndex() can not select properly the necessary value.

    I hope this clarification helps.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top