Forum Discussion

william_roe's avatar
william_roe
Super Contributor
11 years ago

Selecting Item(s) in Dynamic, Multi-select lists in Data-Driven Test

How do you create a data-driven test which checks item(s) in a list using a value and not a mapped object? I created a data-driven test with multiple if statements which clicked on the mapped object only to discover the items in the list are dynamic so this approach will not work.



  • Hi Keith,

     


    You can use the FindChildByXPath method. Here is the sample that obtains the check-box element based on the value specified in the Description column:


    var grid=//...obtain the grid object:

    var obj = grid.FindChildByXPath("//td[text()='Administrator Access']/parent::node()//input", false);


     


    To learn more about XPath expressions, I suggest that you refer to this tutorial.


     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Keith,

     


    Could you please clarify your request by providing some samples?


    Each list control should have the wText property that you can use to check the content of the list. Do you want to perform some other actions?


     

  • If the table is dynamic, you will need to check it's content first to ensure the value the user has entered into the data sheet is valid.



    I have numerous such checks in my tests.



    My number one rule with automated tests is that they should NEVER crash. We run un-attended overnight in most cases so it has to keep going no matter what.



    So I tend to have more code around validation (as all my tests are keyword AND data driven by the user) and error handling as I do around actually manipulating objects on screen a lot of the time.
  • william_roe's avatar
    william_roe
    Super Contributor
    Here is the screen and markup capture. I need to be able to find the row in the grid that matches the Privelage (i.e. 'a' or 'Administrator Access') and set the 'value' of the input to 'C' or 'U'. The multi-select control is a DevExpress control and I'm assuming this will check the item in the list.













  • Yep.



    You have all the info you need there.



    You would need to iterate through it looking for a match with the user selected value in your data driver.



    Then select it if you find it or log out an error if you don't.



    Not familiar with that specific control so I wouldn't like to guess on details. But I can see enough info in the parts you've captured to know it's do-able.



    (Also don't know what language you're scripting in!)



    In pseudo-language though, something like:







    Initialise "found" flag



    Loop



    > Check the current selection vs the one you want

    > If they match .... select that one and set a flag to "found"



    Until (match found) or (out of options)



    If (no match) Then



    > log error



    End If





    Something like that.







  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Keith, 

     


    Unfortunately, we don't see the images you attached. Can you attach them to your post instead of uploading them to a different server?


     

  • william_roe's avatar
    william_roe
    Super Contributor
    Here are the attached files for those who are unable to view.
  • I meant to add (won't let me edit again) ...



    As well as looping through, you could also take the top level object and find the child with the text matching the desired option and find your way to the checkbox that way.



    Without seeing how the object(s) report themselves in TC, it's hard to say.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Keith,

     


    You can use the FindChildByXPath method. Here is the sample that obtains the check-box element based on the value specified in the Description column:


    var grid=//...obtain the grid object:

    var obj = grid.FindChildByXPath("//td[text()='Administrator Access']/parent::node()//input", false);


     


    To learn more about XPath expressions, I suggest that you refer to this tutorial.