Forum Discussion

kerriem's avatar
kerriem
Occasional Contributor
2 years ago

Conditional Name Mapping combining a Project Variable & constant?

In my automation script, I have a NameMapping for a dropdown list of options on a webpage (which has identified each item in the list as a button). 

The list is not constant and will change with each environment I want to test on.

I have a Project Variable, let's call it Default_Dept which is set to a department code e.g. ZZZ and the dropdown list contains the list of Department codes with the name of the Department in brackets e.g. ZZZ (My Department Name)

In order to select the correct 'button' (which is the ObjectType it has identified for each item in the list), I was trying to use contentText to identify which item in the list to select.

Ideally i'd like to do a conditional mapping: contentText Equals (Project Variable, Default_Dept) (*) 

(as I don't really care about the Department name itself, i just want it to select the right department code from the list), but I can't find a way to combine a Project Variable with a wildcard 'constant'.

 

If I change the NameMapping to "ZZZ (My Department Name)" it finds the object no problem and selects the correct one, but other than creating another Project Variable that contains the code and name, in exactly that format of "CODE (NAME)" as it appears in the list, and then manually change the Project Variable each time the automation is executed in a new environment, as well as Project.Variables.Default_Dept code, then I can't think of another way around it? 

 

4 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Instead of using project variables for specific departments, etc, you can build your different department lists in Excel sheets and read them from there.  Your test would be designed to run with data from certain columns and not specific values. Then all you would need to do for each environment is rename the tabs so that the one you want to run is TestThisOne (or something better lol) and the test would execute with those values.

     

     

     

     

  • kerriem's avatar
    kerriem
    Occasional Contributor

    Thanks for your reply - i only need to basically know my default department name from the list and don't really care what others are on the list - one test environment may have a list of 5 departments, another could have 15.

    I just need to be able to automate selecting my default department at this stage. 

    My original Project Variable just contained the Department Code e.g. ZZZ, as that's all i need elsewhere on the webpage, but for this particular list, which is selecting the correct department specifically after login, it is showing both the code and the expanded Department name.

     

    For now, I have worked around it by creating another Project Variable Default_DeptFullName and set it to be "ZZZ (My Department Name)", but to me it's not ideal as other than this one place, i never need to know the expanded Department name, so if I could have used a wildcard alongside the Project.Variables.Default_Dept in the name mapping, that would have been ideal! 

     

    It sounds like I can't combine a project variable with a constant though in name mapping - it's either one or the other ?

    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      I tend not to mess with my name mapping. I would do the variable + constant in a new variable like you did.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's an example of using the FindAll method on a list box, to print out each of the item names from the UI Control

     

    function testit()
    {
        // Use with https://demos.devexpress.com/Bootstrap/Editors/ListBox.aspx
    
        var page = NameMapping.Sys.browser.Page("https://demos.devexpress.com/Bootstrap/Editors/ListBox.aspx");
        var listbox = page.Form("form1").Panel(2).Section("content").Panel(0).Panel("Content_ListBoxDefault");
        var items = listbox.FindAll("ObjectType", "Link", 1);
        // List item names
        for (var i = 0; i < items.length; i++) {
            Log.Message(items[i].contentText);
        }
    }

     

    You can adapt this method, to pass in a parameter, to select the appropriate item from your dynamic dropdown list.