Problems when validating a drop down list

Ranorex Studio, Spy, Recorder, and Driver.
MarkW
Posts: 6
Joined: Tue Feb 09, 2016 6:03 pm

Problems when validating a drop down list

Post by MarkW » Tue Feb 09, 2016 6:09 pm

Hello,

I'm trying to validate the two items in a drop down list. So I enabled hotkeys, recorded selecting the drop down list and then used the hotkeys to validate the second and third items in the drop down list. Once I stopped recording I had the following items:

Mouse Click (drop down list)
Validate AttributeEqual
Mose Click (drop down list)
Validate AttributeEqual

However, when I come to play it back, it opens the drop down list but then it closes it again before it starts the validation. As a result, the validation process hangs trying to find the values. It is only when I manually select the drop down list myself that the validation takes place.

Any ideas why I need the manual intervention in order to do the validation?

Many thanks in advance.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Problems when validating a drop down list

Post by odklizec » Wed Feb 10, 2016 11:10 am

Hi,

It would be very useful to see your recording. Are you sure there is no other mouse/keyboard action after the first mouse click, which opens the list?

BTW, what's your Ranorex version and what technology is used for the ListBox (HTML, Java, QT, etc.)?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

MarkW
Posts: 6
Joined: Tue Feb 09, 2016 6:03 pm

Re: Problems when validating a drop down list

Post by MarkW » Wed Feb 10, 2016 11:25 am

Hello,

The recording steps are as follows at the point in time (not sure how to copy the full recording in):

Mouse - Click - ComboItem
Mouse - Click - ComboBoxButton (selecting the down arrow on the drop down list)
Validate - AttributeEqual - Text - TextItem1
Mouse - Click - ComboItem
Mouse - Click - ComboBoxButton (selecting the down arrow on the drop down list)
Validate - AttributeEqual - Text - TextItem2

However, it seems to hang when it reaches the first validate as the drop down list isn't open so it can't find it.

When I manually click the drop down list down arrow again it is able to run through and complete both validations.

MarkW
Posts: 6
Joined: Tue Feb 09, 2016 6:03 pm

Re: Problems when validating a drop down list

Post by MarkW » Wed Feb 10, 2016 12:20 pm

Hello,

I think I've solved it. There are two actions which are opening and then closing the drop down list, so not sure why the recorder has picked it up like that:

Mouse - Click - ComboItem
Mouse - Click - ComboBoxButton (selecting the down arrow on the drop down list)
Validate - AttributeEqual - Text - TextItem1
Mouse - Click - ComboItem
Mouse - Click - ComboBoxButton (selecting the down arrow on the drop down list)
Validate - AttributeEqual - Text - TextItem2

So what I've found is if I remove most of the clicks, it works:

Mouse - Click - ComboBoxButton (selecting the down arrow on the drop down list)
Validate - AttributeEqual - Text - TextItem1
Validate - AttributeEqual - Text - TextItem2

So this one doesn't hang and validates everything correctly.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Problems when validating a drop down list

Post by odklizec » Wed Feb 10, 2016 12:32 pm

Nice to hear you found it! I was just about to suggest to remove all these redundant clicks ;)

Recorder is a great help, but after each record session (which should be very short, max 5 steps in one round) it's very reasonable to review the recorded steps and do some cleanup.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

MarkW
Posts: 6
Joined: Tue Feb 09, 2016 6:03 pm

Re: Problems when validating a drop down list

Post by MarkW » Wed Feb 10, 2016 5:13 pm

Along the same lines, is there any way to have an item selected from a combo box where it is chosen by a variable? I've tried searching the forum but can't seem to find an answer along the lines of what I need.

At the moment I have the first action as a mouse click on the ComboBoxButton which opens the drop down list. The second action is then to select a specific value in the drop down list, again using a Mouse Click action. However, the selected value in the Repository Item column cannot be set to a variable.

Therefore, is there another way I can get a variable value selected from the drop down list instead of being dictated by a mouse click on a location?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Problems when validating a drop down list

Post by krstcs » Wed Feb 10, 2016 5:38 pm

Mark,

Can you explain why you can't set the XPath for the list item to be variablized? I do it all the time.


For example, if I have a list of values (either drop-down or regular list), the XPath for any given item with a value = $myValue would be:

//listitem[@text=$myValue]

Just bind the variable in the module to a data value and it works wonderfully. It is updated for each new value of the variable $myValue, when you use data-driven testing.

You can also use the variable in regex XPaths like so:

//listitem[@text~'.*' + $myValue + '.*']

This will get the FIRST listitem element whose text CONTAINS the value stored in $myValue.

NOTE: Ranorex ALWAYS stops at the FIRST element that matches the XPath given. Make sure your XPaths are accurate and specific. Unless you are always wanting the first element (say in a table or list), you may get unexpected results if you aren't specific enough.
Shortcuts usually aren't...

MarkW
Posts: 6
Joined: Tue Feb 09, 2016 6:03 pm

Re: Problems when validating a drop down list

Post by MarkW » Fri Feb 12, 2016 3:03 pm

That did help thank you. I'm very new to the tool and so I'm trying to pick things up as I go along.

But I have been able to add the parameter into the value using the xPath and that's done exactly what I need.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Problems when validating a drop down list

Post by krstcs » Fri Feb 12, 2016 4:41 pm

Excellent!!

Ranorex (and RanoreXPath) is very powerful. You will find that it will handle just about anything you throw at it.

I would suggest that you look into learning C#. It will add a huge amount of value to your tests if you get into non-trivial situations where standard Ranorex actions just won't do what you need.

Also, in-depth knowledge and thorough understanding of both XPath and Regular Expressions (regex) are possibly the most important things to have when using Ranorex. You can do things with RanoreXPath and regex together with variables that would normally take a custom code module.

Keep your modules as small as possible, I try to keep mine to ONE ATOMIC action. For instance, if you need to click an OK button in your test, make a module called 'Click_OKButton', and ONLY click the OK button in that module. If you need to enter a password, make a module called 'Enter_Password' and only include actions that would be taken by a user to enter the password (click the field, hit alt-a, hit del to clear it if needed, enter the data, validate the data is entered). This will allow you to drop the modules into the test cases as needed and to know exactly what the module does and what data it might need (Enter_Password needs the variable Password to be bound, for instance).

Keep asking questions and experiment. Make a new solution that is just for testing out approaches so you can 'mess around' with stuff without causing issues in your main solution.

Finally, if you aren't already, you should be using a versioning system such as SVN or git (I use git). You are developing a piece of software, so you need to treat it as such.
Shortcuts usually aren't...