Hello,
I have a testcase where I need to validate, that the given value is in between given boundaries. Like there is a pop up with a price. This price has to be let's say in between 10-1000$. How do I validate this? I tried to set the value in Ranorex to "10-1000" but "573" is not "10-1000".
The field only allows numeric values. So the validation on this value is possible. It's not a simple textfield. Actually the Javaobject is Called QSpinner.
Thanks and greetings,
Björn
Validate that Value in a Field is in range of two boundaries
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Hi Björn,
At first, it would be very useful if you would post a Ranorex snapshot (not screenshot) of the problematic element.
At second, I think you will simply have to write some code to validate that the number is within a certain range. RegEx could be an option too, so then you may not need to use code at all. Just Validate action with AttributeRegEx parameter.
As for the code for checking a number is within a range, I would suggest to examine this post:
https://stackoverflow.com/questions/318 ... in-a-range
At first, it would be very useful if you would post a Ranorex snapshot (not screenshot) of the problematic element.
At second, I think you will simply have to write some code to validate that the number is within a certain range. RegEx could be an option too, so then you may not need to use code at all. Just Validate action with AttributeRegEx parameter.
As for the code for checking a number is within a range, I would suggest to examine this post:
https://stackoverflow.com/questions/318 ... in-a-range
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Hi,
thanks for the quick reply. I made a Snapshot from the Object Spy. It is 1.4MB and too big to upload here.
But for your suggestion with the Regex Validation. It would look something like "[@Value>=10 and @Value<=1000]". I will test this. If it won't work I'll use a Code Module for this Validation. The code module shouldn't be too hard.
Thanks,
Björn
thanks for the quick reply. I made a Snapshot from the Object Spy. It is 1.4MB and too big to upload here.
But for your suggestion with the Regex Validation. It would look something like "[@Value>=10 and @Value<=1000]". I will test this. If it won't work I'll use a Code Module for this Validation. The code module shouldn't be too hard.
Thanks,
Björn
Re: Validate that Value in a Field is in range of two boundaries
Hi,
You can always upload the snapshot using onedrive, google drive or similar service and here post a link
The regex you are looking for should be something like this:
You can always upload the snapshot using onedrive, google drive or similar service and here post a link
The regex you are looking for should be something like this:
Code: Select all
^([1-9][0-9]{1,2}|1000)$
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Hi,
sorry for the late reply. I tested around with regex but the actual range in the element would be more like 100,000-50,000,000 and doing this with regex is a pain. 10-1000 was a sample for simple understanding.
So I thing doing it with a code module is better since the regex would simply be unreadable for everyone else.
I got just one problem and my element is recognised as a container and I don't know how to get the value of it in the code module. Because the container does not have a method for "getValue" or something like this.
I uploaded the Snapshot on my googledrive: https://drive.google.com/open?id=1Oq_KV ... rfRaLnA8Be
Greetings
Björn
sorry for the late reply. I tested around with regex but the actual range in the element would be more like 100,000-50,000,000 and doing this with regex is a pain. 10-1000 was a sample for simple understanding.
So I thing doing it with a code module is better since the regex would simply be unreadable for everyone else.
I got just one problem and my element is recognised as a container and I don't know how to get the value of it in the code module. Because the container does not have a method for "getValue" or something like this.
I uploaded the Snapshot on my googledrive: https://drive.google.com/open?id=1Oq_KV ... rfRaLnA8Be
Greetings
Björn
Re: Validate that Value in a Field is in range of two boundaries
Hi,
I agree that validating such wide numeric ranges would be quite painful with regex Doing it code would be easier then.
As for extracting the number from given container, GetValue action should work just fine? You don't even have to use it in code. Simply add the GetValue action to recording of your choice, point it to given repo element and store the obtained value in new recording variable. The number you are looking for seems to be stored in Value attribute: Then simply add new UserCode action, in which you can validate if the number is in expected range. Of course, you will first need to convert the recording variable (the one holding the obtained number) to integer/long, because recording variables are always strings! For this you should use Parse or TryParse method.
I agree that validating such wide numeric ranges would be quite painful with regex Doing it code would be easier then.
As for extracting the number from given container, GetValue action should work just fine? You don't even have to use it in code. Simply add the GetValue action to recording of your choice, point it to given repo element and store the obtained value in new recording variable. The number you are looking for seems to be stored in Value attribute: Then simply add new UserCode action, in which you can validate if the number is in expected range. Of course, you will first need to convert the recording variable (the one holding the obtained number) to integer/long, because recording variables are always strings! For this you should use Parse or TryParse method.
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Hi,
Okay I will try this. So I get the Value in a new variable and use this variable in my code?
greetings
Okay I will try this. So I get the Value in a new variable and use this variable in my code?
greetings
Re: Validate that Value in a Field is in range of two boundaries
Yep. The variable obtained in recording module (via GetValue) action should be accessible in the UserCode of the same recording.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Actually to add user code to the recording module I have to add it in my User Code Collection first, to add it later in the recording.
so within this Collection I now added a new Method for validation, but I don't see a way to add this variable.
so within this Collection I now added a new Method for validation, but I don't see a way to add this variable.
Re: Validate that Value in a Field is in range of two boundaries
So create a method with string parameter, in which you can pass the recording module variable. Then simply assign recording variable to parameter of your method.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Thu Jul 27, 2017 11:04 am
Re: Validate that Value in a Field is in range of two boundaries
Ohh I feel so stupid right now. Thank you very much. I got it.
What I did is, I created the step first in the recording and added the parameter afterwards, that was giving me an error obviously.
edit: The big problem with this was, that the window I use is temporary and because of that, the attributes are not recognised while the object is not open. I had to set everything up while the window is actually open.
anyways I got it now, thanks!
What I did is, I created the step first in the recording and added the parameter afterwards, that was giving me an error obviously.
edit: The big problem with this was, that the window I use is temporary and because of that, the attributes are not recognised while the object is not open. I had to set everything up while the window is actually open.
anyways I got it now, thanks!