Automate Windows File Upload in Rational Functional Tester

When automating tests in web applications, almost always there are test cases where you’ll need to upload or download a file. This can be done very easily in RFT since its object recognition technology can handle window based applications. This tool is perfect if the AUT utilizes both web and non-web applications interchangeably.

The application we’ll use again is the sample practice from toolsqa.  We will be focusing only on the Profile Picture field shown below.
ProfilePicture

Now before we can start, we need to know the path to a file that we will upload to the dialog window once it opens. In this case I created a sample dummy picture file located in “C:\ProfilePicture.png”.

If we’re lucky, there are times that the text box for the upload file is enabled and we can go ahead and send the path to the input box directly with below command.

TestObject link = find(atDescendant(".class", "Html.INPUT.file", ".id", "photo"))[0];
 ((TextGuiTestObject) link).setText("C:\\ProfilePicture.png");

But sometimes we’re not so lucky and the text box is grayed out like the one in our picture above and cannot be typed into. In this case we’ll need to access the dialog window by clicking the Browse button first then accessing its File Name text box. So how do we do this in RFT?

First, lets extract the browse button object properties in Test Object Inspector.
Browse


Property[] browseButtonProp = {atProperty(".class","Html.INPUT.file")
,atProperty(".className","input-file")
,atProperty(".id","photo")
,atProperty(".name","photo")
};
TestObject browseButton = find(atDescendant(browseButtonProp))[0];
((GuiTestObject) browseButton).click();

When clicked, a windows based dialog box will prompt.  Now we’ll need to get the object properties for the File name input box and the Open button highlighted below in red.

DialogWindow

Properties for File Name text input box:
filenameprop

Use find method to store its property in TestObject filename. Then use setProperty to change its “.text” value to the file path.


TestObject filename = find(atDescendant(".class","Html.DialogEdit"))[0];
filename.setProperty(".text", "C:\\ProfilePicture.png");

Properties for Open button.

okbuttonprop


TestObject openButton = find(atDescendant(".class","Html.DialogButton", ".text", "&Open"))[0];
((GuiTestObject) openButton).click();

When the actions above have been executed successfully, we can then check if the path is entered corrected in the Profile Picture text box.

ProfilePicture_After

Now you’re all set!