Adding test objects in the object map should be the primary choice for an automation framework if you are using RFT. I worked on a project with automating a windows based application and this was a perfect example for that method. Since windows based applications have less changes in their objects that type of approach works.
There are cases however in my opinion that using the find method is more advantageous. In web applications for example, the web elements are more prone to frequent changes in their properties like the id or name. Last blog I lightly touched on the subject of recognizing Test Objects with RFT using the find method. In this post I will try to cover different types of objects with different actions using the RFT interfaces package. The Test Object Inspector (TOI) in RFT will also be used to extract the object properties. The TOI is very useful when you have to quickly peek at the object properties. It becomes handy during scripting as well as troubleshooting and maintaining your automation scripts.
The web test application used is the practice form in toolsqa. Note that any attribute can be used on the given object provided it has a value. In this case, the attributes used have been highlighted in red.
Link
TestObject link = find(atDescendant(".class", "Html.TextNode", ".text", "Link Test"))[0]; ((GuiTestObject) link).click();
Text Box
Property[] textBoxProp ={atProperty(".class","Html.INPUT.text") ,atProperty(".name","firstname") ,atProperty(".tag","INPUT") ,atProperty(".type","text") }; TestObject textBox = find(atDescendant(textBoxProp))[0]; ((TextGuiTestObject) textBox).setText("Philip");
Radio Button
Property[] radioButtonProp = {atProperty(".class","Html.INPUT.radio") ,atProperty(".id","sex-0") ,atProperty(".name","sex") ,atProperty(".value","Male") }; TestObject radiobutton = find(atDescendant(radioButtonProp))[0]; ((ToggleTestObject) radiobutton).setState(SELECTED);
Check Box
Property[] checkBoxProp = {atProperty(".class","Html.INPUT.checkbox") ,atProperty(".id","profession-1") ,atProperty(".name","profession") ,atProperty(".value","Automation Tester") }; TestObject checkbox = find(atDescendant(checkBoxProp))[0]; ((ToggleTestObject) checkbox).setState(SELECTED);
Drop Down
Property[] dropDownProp = {atProperty(".class","Html.SELECT") ,atProperty(".id","continents") ,atProperty(".name","continents") ,atProperty(".value","Asia") }; TestObject dropdown = find(atDescendant(dropDownProp))[0]; ((SelectGuiSubitemTestObject) dropdown).select("Australia");
List
Property[] listProp = {atProperty(".class","Html.SELECT") ,atProperty(".id","selenium_commands") ,atProperty(".name","selenium_commands") ,atProperty(".type","select-multiple") }; TestObject list = find(atDescendant(listProp))[0]; ((SelectGuiSubitemTestObject) list).select("Switch Commands"); ((SelectGuiSubitemTestObject) list).select("WebElement Commands");
Button
Property[] buttonProp = {atProperty(".class","Html.BUTTON") ,atProperty(".id","submit") ,atProperty(".name","submit") ,atProperty(".value","Button") }; TestObject button = find(atDescendant(buttonProp))[0]; ((GuiTestObject) button).click();
Text Label
Property[] textLabelProp = {atProperty(".class","Html.SELECT") ,atProperty(".className","abc") ,atProperty(".id","NextedText") ,atProperty(".tag","Asia") }; TestObject textlabel = find(atDescendant(textLabelProp))[0]; String Text = ((TextGuiTestObject) textlabel).getText(); logInfo(Text);