Introduction to Automation testing:
Testing is an essential part of a software development process. While testing intermediate versions of products/projects being developed, testing team needs to execute a number of test cases. In addition, prior to release every new version, it is mandatory that the version passed through a set of “regression” and “smoke” tests. Most of all such tests are standard for every new version of product/project, and therefore can be automated in order to save human resources and time for executing them.
Benefits of using automated testing are the following:
- Reduction of tests’ time execution and human resources required
- Complete control over the tests’ results (“actual results” vs “expected results”)
- Possibility to quickly change test’s preconditions and input data, and re-run the tests dynamically with multiple sets of data
Automation workflow for the application can be presented as follows:
- First of all it is required to identify tasks that an application has to accomplish.
- Second, a set of necessary input data has to be created.
- Third, expected results have to be defined in order one can judge that an application (a requested feature) works correspondingly.
- Fourth, Executes a test.
- Finally, Compares expected results with actual results, and decides whether the test has been passed successfully.
The goal of this framework is to create a flexible and extendable automated testing framework, which should expand test coverage for as many solutions as possible. Framework must have input and output channels and library of methods to work with UI.
- Selenium Webdriver. Selenium is a suite of tools for cross-platform automated testing of web applications. It runs on many browsers and operating systems and can be controlled by many programming languages and testing frameworks. Selenium WebDriver is a functional automation tool to automate the applications. It makes direct calls to the browser using each native support for automation.
- Eclipse IDE. Eclipse is an integrated development environment (IDE) used in computer programming, and is the most widely used Java IDE. It contains a base workspace and an extensible plug-in system for customizing the environment. Eclipse is written mostly in Java and its primary use is for developing Java applications.
- TestNG. Is a testing framework inspired from JUnit and NUnit. It has extended new functionalities, which made it more powerful and easier than the other testing frameworks. It supports ReportNG (simple HTML reporting plug-in) and XLST (Graphical / Pictorial reports) plug-ins to customize or extend the default TestNG reporting style. TestNG also provides ability to implement ‘IReporter’ an interface which can be implemented to generate a Customized TestNG report by users. It has ‘generateReport()’ method which will be invoked after all the suite has completed its execution and gives the report into the specified output directory.
- Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.
- AutoIT Tool used to handle Windows popups for Document Uploads and Downloads.
- Apache POI to perform operations with excel like read, write and update the excel sheet
- Webdriver is a driver that contains programming interface for controlling all kinds of possible actions in browser.
- Selenium TakesScreenshot to take screenshot in case of error.
- Log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License.
- JDBC. Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is part of the Java Standard Edition platform, from Oracle Corporation.
File Formats Used in the Framework:
- Properties file – framework uses properties file (Objects.properties) to store and retrieve the UI elements of an application or a website and data set file paths. It contains id of the elements, name, XPath or CSS selector etc. We use properties file (Param.properties) to store and retrieve basic configuration information as UR, user credential and others.
- Excel files – Excel files are used to pass multiple sets of data to the application and retrieve statistics.
- Xml file – Is used to execute the test scripts. Based on the package or classes or Tests mentioned in the xml file scripts will be executed.
The following figure explains physical structure of files required for Test Automation Framework
The main goal was to write tests in a readable manner where each step is one single line of code that clearly describes what it does, and at the same time hides all actions that need to be done by Webdriver “under the hood” in our Page Object classes. By this we make it really easy to read and understand what our test does for every team member – from developers to product managers and even sales people. There are some concepts I would like to highlight:
- UI Map / Object Repository
UIMap is a concept for defining, storing, and serving UI elements of an application or a website. The UIMap properties file contains a set of ‘key-value’ pairs, where key is an alias of the UI element, and a value is the locator. Fragment of the Objects.properties file:
#Hyperlink Locators link_messages=(//a[contains(@href, '#')])
- Data Set / Test Data
Data set stores the data files, Script reads test data from external data sources and executes test based on it. Data sets increases test coverage by performing testing with various inputs and reduce the number of overall test scripts needed to implement all the test cases.
Example of the Data set for one of the test cases:
- Test Automation Scripts
A test is considered as a single action or a sequence of actions, that defines whether a specific feature meets functional requirements. It has multiple test files / packages / class files which will be executed based on the configurations defined in testng.xml.
- Reports / Executed Results
Test report/results is a document which contains summary of test activities. After execution is completed, it is very important to communicate the test results and findings to the project manager along with the screenshots for failed tests and with that decisions can be made for the release.
- TestNG xml file
In order to create a test suite and run separate test cases, we need framework which drives the automation. Here testng.xml can be called as “driver” which drives several test cases automated using selenium code. Advantage of using TestNG with Selenium is of running multiple test cases from multiple classes using xml configuration file:
- Architecture highlights:
- Tests should be also run on CI (Jenkins in our case).
- Integration with libraries via Maven (software project management and comprehension tool, which manages all dependencies and different flows for building a project.)
Key steps to create a brand new Test Case:
- Add new test case to the test suite <TestSuite.xml>, for example:
<test name="Suite Validate Dictionary"> <classes> <class name="com.solution.testSuite.ManageDictionary.SuiteManageDictValid" > </class> </classes> ...
- Add new test case to the list of current test suite test cases (must have totally the same name as a future java test class name):
- Create new tab (current xls file) with the same name and add some test data:
- Copy and paste existing java test case.
- Delete previous methods, but keep configurational parts (@AfterMethod, @DataProvider, @AfterTest, @BeforeTest and all main test part until login method)
- Create new methods and run the test case:
- To perform any UI actions – just specify helpers, select class to handle object (ExtJS, Iframe, etc.), select particular method and set parameters:
- Complete the test and run it