Automation is the technology to reduce human intervention in daily life tasks. It can be performed on a very simple task to a very complex one. During software testing, we might need to do a repetitive task that is important and needs to be done on a regular basis. To ease the task of testing the same feature manually at a regular interval, automation testing was introduced.
Test automation can automate some monotonous yet essential assignments in a formalized testing measure effectively set up, or perform extra testing that would be hard to do physically. Test automation is important for constant delivery and persistent testing of the delivered product.
Automation can be done on a graphical user interface i.e. known as UI automation or can be done on the APIs that handle the logic of the feature that is delivered. While performing UI Automation, one of the major use cases that is encountered is when a file needs to be uploaded to the UI or downloaded from the UI. As this is one of the major use cases in any feature, the testing around it can’t be ignored.
Document upload & PDF to CSV Converter is a frequent activity we perform on the web nowadays. Automating it prompts a pop-up which is too difficult for Selenium to automate. To deal with such scenarios generally, third party tools are used such as:
1. Using Send Keys
Send Keys is one of the most commonly used functions of the selenium framework for sending the absolute file paths to the browser file dialogue and locating the web elements, either by ‘id’ or ‘name.’ To make sure this approach works, the following guidelines must be fulfilled:
- The file textbox properties must be “Enabled” & “Visible”
- The file’s path must be the absolute path
- Not to perform a “Click” action to launch the file dialog as the control moves to the dialog box and the selenium driver doesn’t have control over the dialogue box.
It is a freeware programming language for Microsoft Windows. In its earliest release, it was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs but has since grown to include enhancements in both programming language design and overall functionality.
AutoIt is typically used to produce utility software for Microsoft Windows and to automate routine tasks, such as systems management, monitoring, maintenance, or software installation. It is also used to simulate user interaction, whereby an application is "driven" (via automated form entry, keypresses, mouse clicks, and so on) to do things by an AutoIt script.
Few of the methods below are used for file upload by AutoIT:
- ControlFocus(" title "," text ",controlID ) //Sets input focus to a given control on a window.
- ControlSetText(" title "," text ",controlID ," File path which needs to upload " ) // Sets text of a control.
- ControlClick(" title "," text ",controlID ) //Sends a mouse click command to a given control.
It is an open-source GUI based test automation tool. It is mainly used for interacting with elements of web pages and handling windows based popups. Sikuli uses the technique of “Image Recognition” and “Control GUI” to interact with elements of web pages and windows popups. In Sikuli, all the web elements are taken as images and stored inside the project.
- Screen class in Sikuli:
Screen class is the base class for all the methods provided by Sikuli. Screen class contains predefined methods for all the commonly performed operations on screen elements such as click, double-click, providing input to a text box, hover, etc.
- Pattern class in Sikuli:
Pattern class is used to associate the image file with additional attributes to uniquely identify the element. It takes the path of the image as a parameter.
Pattern p = new Pattern("Path of image");
WinAppDriver stands for Windows Application Driver and it is a service to support Selenium-like UI Test Automation on Microsoft Windows-based applications. WinAppDriver supports testing Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32) apps on Windows 10 PCs.
Prerequisites to setup WinAppDriver:
- Windows 10 Machine
- Enable Debug Mode in Windows10 machine
- Add Selenium dependencies to the project
- Add Java-Client dependencies
- WinAppDriver server should be running on the machine
- Any one of the elements inspecting tools like inspect.exe, WinAppDriver Recorder or Appium Desktop, etc.
It is the most convenient and popular automation framework for desktop applications. Winium is a Selenium Remote WebDriver implementation for automated testing of Windows applications, based on WinForms and WPF platforms. With the Winium tool, there is no need to use a screenshot of the objects; use Selenium based locators like name, id and class. Winium helps to automate faster and deliver on time.
Prerequisites of Winium:
- Install Microsoft .NET Framework 4.5.1
- Create Maven Project and add following dependencies in pom.xml file
6. Jacob API to Handle File Upload
It’s a native API technique that gives full control to write Java code that can manage any GUI Window.
Prerequisites of Jacob API:
- Selenium Webdriver project or add a TestNG project in Eclipse.
- Download the Jacob library package, it comes as a zip file. Unzip the <jacob-1.18.zip> (or <jacob-1.19.zip> whichever is available) file. You’ll find the following files under the <jacob-1.18> folder.
- Add the <jacob.jar> as an external jar into your Eclipse project while copy/paste the <jacob-1.18-x86.dll> to your project. It’ll get the DLL file added to it.
7. Using Robot Class
By using Robot Class, one can take control of the keyboard & mouse. Once the control is established, the operations can be automated depending on the sequence of steps to follow, i.e. the press and hold the mouse button, release the mouse button, copy some file, paste the file location and so on. All these operations have their own set of functions as follows:
Important thing to note is that Robot class is not a part of Selenium, rather comes with Java. Steps involved in using Robot class are:
Step 1- Copy the file location in the system clipboard.
Step 2- Click on the upload button and use CTR+V and ENTER.
While using Robot class each key needs to be pressed and released respectively.
Methods used in Robot Class:
- robot.keyPress(KeyEvent.VK_CONTROL); to press the ‘control’ key on the keyboard
- robot.keyPress(KeyEvent.VK_V); to press the ‘V’ key on the keyboard (it will automatically Press (ctrl+v) on the keyboard)
- robot.keyPress(KeyEvent.VK_CONTROL); to release the ‘control’ key on the keyboard
- robot.keyPress(KeyEvent.VK_V); to press the ‘V’ key in the keyboard (it will Release (ctrl+v) on the keyboard & paste the file in the desired location)
- robot.keyPress(KeyEvent.VK_ENTER) && robot.keyRelease(KeyEvent.VK_ENTER); Press and Release the ‘Enter’ button (in the popup window, if you press ‘Enter,’ it will trigger ‘Open’ button in the window).