Is it possible to interact with Select2 components using HPE Unified Functional Testing? - hp-uft

I hope this question makes sense.
When recording in HPE UFT in my web application and selecting an option from a dropdown box made using Select2 and then running the test it fails.
It returns the next error:
Cannot identify the object "WebElement" (of class WebElement).
Verify that this object's properties match an object currently displayed in your application.
This is for version 14.03 of the tool running in a Windows machine.
And I have tried different record modes without any luck.
The code that is generated when recording the test is:
Browser("LHO DEV").Page("SITE DEV_4").WebList("WebElement").Click
Browser("LHO DEV").Page("SITE DEV_4").WebTree("select2-single-results").Select "Option Value 9"
Browser("LHO DEV").Page("SITE DEV_4").WebEdit("WebEdit").Set "Value 9"
I understand that this code won't work as Select2 as it behaves in a different way than a regular dropdown/select box.
So, I would really appreciate if anyone can give me a light in the right direction.

Well, I found a solution maybe not the desired one but at least works.
Basically, the method RunScript allows executing Javascript, in this way I was able to access the Select2 element and select the desired values.
Here is the code I used:
Browser("LHO DEV").Page("SITE DEV_4").RunScript("$('#single').select2('open')")
Browser("LHO DEV").Page("SITE DEV_4").RunScript("$('#single_element').val([66]).trigger('change')")
Browser("LHO DEV").Page("SITE DEV_4").RunScript("$('#single_element').select2('close')")
I hope anyone finds this useful in the future.

Related

Selenium RC - Unable to click on a link using XPATH / CSS path / //a[contains(text(),'abc')]

Selenium IDE is able to recognise the ID, Xpath, CSSPath for a link. But, Selenium RC is unable to click on the link using XPath or CSSPath or ID. I have also used "Contains Text()", but of no use. Please find below code that i am currently executing in Eclipse IDE.
selenium.open("https://abc.com");
selenium.type("UserName", "123456");
selenium.click("xpath=//form[#id='loginForm']/table/tbody/tr[7]/td/input");
selenium.click("xpath=//a[#id='_ebg9dd']");
// selenium.click("xpath=//a[contains(text(), 'Request Form')]");
Can someone please suggest any other alternative or correct the code if there is any discrepancy ?
Are you converting it using the IDE? For example, this is an Xpath selector for Java Junit 4 RC:
Seems unusual to have an id on your a-tag but if you wanted to try using 'contains' this is an example of one that works for me when I just tried it..
selenium.click("//div[#class='span5 footer-links']/ul/li/a[contains(text(), 'Submit your page')]");
I also wonder about the fact that you look to be inputting text into a 'username' field and then followed with two 'clicks'. Do you not need to either input something into another field or wait for something after the first click? Just seems like an odd series of events (may not be though, I obviously don't know the specifics of what it is you're doing.
Try this :
selenium.click("link=name_of_link_present_on_page");

Using wildcards in Selenium IDE

I'm somewhat new to automation, and am learning everything auto-didactically, so forgive me if my terminology is a bit off. I've searched hi and low for an answer to this question, and I can't seem to find anything. I presume it's my small vocabulary when it comes to this stuff... anyway...
I'm attempting to write a test that performs all the actions necessary to complete a tutorial by using the recorder. However, for one particular step, the element ID changes. For example, the ID I'm trying to click is this:
//li[#id='message_661119']/div[2]/div[2]/a/img
However, for each new user that is performing the tutorial "quest", the number of the id changes.
Is there anyway to get Selenium to recognize, or use, wildcards? Example:
//li[#id='message_******']/div[2]/div[2]/a/img
Of course, the example above does not work.
Any advice would be immensely helpful. Thank you!!
You can use starts-with() for this:
//li[starts-with(#id, 'message_')]/div[2]/div[2]/a/img
It's one of the examples mentioned in Locating Techniques in Selenium's docs for starts-with().
In Target field of the command in Selenium IDE where you can see message_123123 click on a dropdownlist and choose an option which is related to xpath:idRelative or if this one doesn't work then try another options which do not include that annoying message_123123 so this way you'll identify webpage element by it's location but not id. I solved my issue this way

VB6 intellisense problems

I am writing a simple application that utilizes option(radio) buttons in vb6.
I am attempting to make different buttons and labels appear based on which optionbutton has been selected. I attempted to use an if statement that looks like this:
If (EditOpenTicketRadioButton.value = True) Then
label.visible = true
elseIf(...) then....
and on.
things start acting strange when I begin to type the period after EditOpenTicketRadioButton. the only options that intellisense gives me are Count, Item, LBound, and UBound. I know from internet examples It should be like the above example right? it will not run with that syntax it gives me an error that states: compile Error: Method or data member not found. then it points me to the Load method for my form...
If anyone can help me make sense of this it would be greatly appreciated.
Thanks in advance!
From the (very, very) limited information you gave, I can only assume EditOpenTicketRadioButton is a victim of extremely poor name choice and is actually an array of radio buttons.
If that's the case, you need to figure out which button you mean, and use it like EditOpenTicketRadioButton(0) or whatever.

Abstract testing of GUIs

In general how does one test a various parts of a GUI? What are good practices? (Yes I am being overly general here).
Let take for Notepad's Find dialog box:
Notepad's Find dialog box http://img697.imageshack.us/img697/5483/imgp.png
What are some things that can be tested? How does one know its working correctly? What are edge cases to look out for? Stress tests?
Here.
I doubt any good generalization can be made about this - it always depends on the situation.
When someone asks for tests for GUI I always assume that that mean 'this part of application that is accessible via this GUI'. Otherwise it would mean testing the only the GUI without any logic hooked. Dunno why no one never actually asked for testing if the events are fired when button is pressed or is displayed window acquiring focus.
Anyway back to the question. First of all find out about equivalence classes, boundary conditions other testing techniques. Than try to apply it for given problem. Than try to be creative.
All those should be applied when creating following tests:
1) happy path tests - application acts right when given input is good
2) negative tests - application acts right when given input is bad
3) psychotic user behavior (I saw someone use this term, and I find it to be great) - that one user that has nothing better to do than break your application or is to stupid to actually know how bad and horrible things he is doing with your app.
After all this if all tests are passing and you can't figure out other, than you don't know is it working properly, but you can say that it passed all tests and it seems to be working correctly.
As for given GUI example.
1)
Is the application finding string that is in opened file?
Is the application finding character that is in opened file?
How is it reacting to reaching end of file during search?
Is it finding other appearances of given string/character or just one, when there are many of those appearances ?
Is it handling special search characters like * or ? correctly?
Is it searching in desired direction?
Is it 'Mach case ' option working properly?
When opening find setting some criteria, canceling search and launching it again - are search criteria back to default values? Or are they set as you left them when clicking Cancel?
2)
Is it informing user that no mach was found when trying to search for data that is not in opened file?
Is it reacting properly when trying to search down form end of file?
Is it reacting properly when trying to search up form beginning of file?
How search feature is reacting when no file is loaded? (in MS notepad it can be done, but in other editors you can launch editor without opening a file hence this test)
Can I mark both Up and Downs search direction?
3)
Is it working properly on 4GB file?
Can I load 4 GB string in 'Find What:' field and search for it?
Can I provide as input special characters by providing ASCII codes? (it was done like pressing Alt and number of character... or something like that)
Can I search for empty character (there was something like that in character table).
Can I search for characters like end of line or CarretReturn?
Will it search for characters form different languages? (Chinese, or other non-english alphabet characters)
Can I inject something like ') DROP ALL TABLES; (if that would be web based search).
Will I be able to launch proper event twice by really fast double click on search button? (easier on web apps)
With reasonable test suite you know it seems to work correctly.
I think it is better to separate out functional aspects and the usability aspects for the GUI testing.
Let us say in the above example take the use case of user entering some text and hitting the Find button. From the functional aspect I would say your tests should check whether this user action (event) calls the appropriate event handler methods. These can be automated if your code has good separation between the GUI display code and the
functional part.
Testing of usability aspect would involve checking things like whether the display occurs correctly in multiple platforms. I think this needs to be verified manually. But I think there are some tools that automate this kind of GUI testing as well but I've no experience with them.
It's difficult and error-prone to test finished UIs.
But if you are more interested form the programmer's perspective, please have a read of the paper The Humble Dialog. It presents an architecture for creating UIs whose functionality can be tested in code using standard testing frameworks.

Automated test with Ruby: select an option from drop-down list

I write automated test with Ruby(Selenium framework) and I need to know how can I select an option from drop-down list.
Thanks in advance!
building on floehopper's answer:
selenium.addSelection(locator, value)
or
selenium.select(locator, value)
You almost certainly want "id=my_select_box_id" (with the quotes) for locator, though other CSS selectors will work. value is the literal text value (not the display value) of the option to be selected.
It sounds like you are writing a functional test here. Selecting it probably won't do you much good on its own. You need to submit the form in order to test the controller. :)
It might help people answering to know which testing framework you are using, because there are several to choose from.
If you are using RSpec, check out this screencast.
Hope that helps anyway.
Aside from functional tests, if you're looking for something that acts a bit more like the real app, have a look at WebRat. For non-AJAXed integration tests, it has a very nice DSL for selection your DOMs and taking appropriate actions against them. (link-clicking form-filling etc.).
On the other hand if your App is an external Web App that you just want to do acceptance tests on, you can also check Selenimum or Watir.
Note that WeRat is heavily web framework based where as Selenimum and Watir use the browser to interact with your web app directly (like a real user).
I think you want this command :-
select(selectLocator, optionLocator)
selectLocator identifies the drop down list
optionLocator identifies the option within the list
Easiest way of doing this: select(selectLocator,optionLocator) as suggested above.
selectLocator: name or xpath for dropdown object
optionLocator: name or xpath for dropdown option to be selected
E.g.
#selenium.select "Language", "label=Ruby"

Resources