
Nowadays Automation has grown so much, that even working in an environment of just ‘Manual Testing‘, it’s really important to ensure and improve the testing process to include a percentage of ‘Automation‘.
It’s important to mention that there’s impossible to cover 100 % of Automated Test Cases because automation has its limits like the abilities and knowledge about coding in a language programming of the Testers, the most used are Java, Python, and JavaScript, which not all actual Testers have.
Another important key is that not all the types of testing are able to automate like look and feel test.
So to keep it simple, if you want to automate a test you have to take the following points at least to start automating:
1. There are Regression Test Cases that you need to run always before a release.
2. There are flows that are just too large but also repetitive.
3. The scope of the Company is implement Continuous Integration (CI).
There are a lot of automation tools for different platforms like Android, IOS, and Web, but also for different scopes like Selenium, Mocha, Jazmine and Espresso.
Let’s start with Mobile (Android & IOS) using Selenium and TestNG with Java.
Create a Maven Project in Eclipse
For the next example, we’ll be using Eclipse as IDE and Maven of libraries management.
1. Create a Maven Project, it’ll look something like this.

2. In Folder “src/main/java“, create the packages “example.enviroment“, “example.pages” “example.test.base” and “example.pages.base“. This packages will contain our code.

3. Now let’s create the class “Setup” for the package “example.environment“, the class “BasePage” for the package “example.pages.base” and the class “BaseTest” for the package “example.test.base”.

4. It’s necessary to add de dependencies to the “pom.xml” file.

5. In Setup class we create de AppiumDriver that will interact with the device and our test.

- udid = The ID of the device.
- device_Name = Generic name of the device usually just “My Phone”.
- appPackage = Is the name of the application’s package.
- appActivity = Is the name of the main activity (First Page) that the app loads when the app it’s launch.
- noReset = It’s an extra capability to avoid the information of the app got wiped out each time we run a test.
6. Let’s use ADB to obtain the previous capabilities.

To be able to see the device we must enable de “Developer Mode” and the “USB DEBUGGER”.

“com.huawei.android.FMRadio“: is the “appPackage” of the app.
“com.huawei.android.FMRadio.FMRadioMainActivity“: is the “appActivity” of the app.
Create our First Test using TestNg
1. In class “BaseTest” we are going to call our driver (Setup class) each time a test is executed that’s why it is going to be called in BaseTest is going to be base for all the tests. With the tag @BeforeMethod, we assure that the Setup class and its method are always called before our tests. Also with the tag @AfterMethod we are going to set the close of the objects open, each time a test finishes. The tag @Parameters is going to help us to send the values from the xml file of TestNG.

2. Now let’s run Appium to inspect the elements of our app.

The port can be changed if it’s occupied or we want to run tests in parallel (I recommend separate the ports at least 10 units to avoid conflicts).

3. Let’s click “Start inspection Session“.

4. Insert the next capabilities, click the button “Start Session“, and then we’ll see the app main activity, in this example the “Radio app“.


5. This main activity it’s going to be the “Principal Page“.

POM is a framework to organize the elements of an application in a way that it’s easier to understand and to maintain via “Pages”, in each page (Class) it’s defined the elements of only that page, in this example, we are only going to have two pages, the “Principal Page” and the “Radio Channels Page“.
6. Let’s inspect and get the locators of the elements of “Principal Page“.

The ID locator is a unique locator that avoids having issues like duplicate elements if it is available de ID locator is much better to use it always.
The XPath locator depends on the DOM of the app source, so it’s not recommended to use it because it can change and also affects the performance because it has to go through all the DOM to find an element.
There are other locators like “name“, “class” and “text“, this locator it’s better to use them as a complement of each other because it’s possible that two or more elements have the same name, class, and text.
In this example:
The previous buttons ID is: “com.huawei.android.FMRadio:id/iv_prev“.

com.huawei.android.FMRadio:id/iv_next“.


7. Now let’s create our methods in the class “PrincipalPage“, create a package called “example.pages.java” and the class “PrincipalPage“.


- This class extends BasePage that will have the methods used by all the pages.
- In the Class’s Constructor it’s defined the “driver” that we create in Setup.
- PageFactory.initElements: Initialize the elements of the page, this is the main function of Page Factory, at the moment it’s instantiated the class PrincipalPage all the elements of the page are initialized.
- The structure to create these page elements are by the tag @FindBy and the type of locator to use like id, XPath, class, name etcetera; and the value of the locator.
Finally, it only needs the name of the element in our case a WebElement.

In these examples the actions of each element are just clicks, this “Click” method/action is defined by Selenium as other many actions like sendKeys, clear, getText, getLocation, and many others.
The failedMethod and staticWait are not declared on this page because it comes from BasePage.
8. Let’s define the actions in BasePage.

9. Let’s create the last package where our Test Suites will be called as package “example.test.java” and class “FirstTest“.

10. The main test script resides in FirstTest.

11. Finally, let’s create the “PossitiveTests.xml” that TestNG will use to execute the tests and also is where the input parameters are defined.

The class name is composed: package_name.class_name.
The methods include name is composed : method_name_of_FirstTest_class
12. Lets just run it!

If there’s a problem finding this option be sure to have installed TestNG on the IDE, for more information about the installation of TestNG refers to https://testng.org/doc/download.html.

Links of interest:
Speed up Android Testing with TestProject Agent
Upload a File With HTML5
The Agile Team Approach
What Scrum Master Certification to Choose?
These are some recommended books to learn more:
Any help is welcome to help us keeping this effort alive! PayPal Account BTC (Bech32): bc1qx6f8nczr5ram6d57svlnsfmk5mhu6lsr9q7mxw BTC: 1DDcWbphm1bKMvWruotNKLSM8ypVaHg5Nv ETH: 0x58D137fb142D946bCD815f0ded0fa3b3fE5AB3BF

Angélica Viridiana Rebolloza
Computing Engineer specialized in Automation, working with different tools for Mobile and Web, using languages, tools, and platforms like JAVA, VBScript, JavaScript, C#, Appium, Protractor, UFT (QTP), Selenium, WinAppDriver, Jenkins among others.
Viridiana also has been working using practices like TDD & BDD under Cascade and Agile approaches.
Some certifications include: ISTQB Foundations Certification, SeU Selenium Certified, ITIL Foundations Certification.
I can not finish the example because I can not see the code of the class BaseTest.Java, could you please send it to me?
Hello Luis, I’ve just added the code of BaseTest.java to the entry, it’s at the beginning of the entry, please feel free to contact me again if you have some more issues.