Why, and How to automate software testing?

Why automated testing?

In today's era, we want everything in our smart device, whether its banking, shopping, food areas. We want to save our time as much as we can just by one touch in our smart devices. For this, we use lots of smart apps to make our daily life more comfortable.

But how much you aware that is your apps are ingenious. An app can behave smartly when it is tested smartly. So what do you think about testing that just to verify from a user endpoint, UI testing, Functionality testing? I don't think that's enough only to make it smart. So what we can do more in this. We can take one forward step for automated mobile testing.

Companies are now moving toward Agile and DevOps, increasing the importance of automation than ever before. And functional automation testing assures the best accuracy and quick run, avoiding all human errors. There are many mobile automation tools in the market, like Appium, Calabash, MoneyTalk, Robotium, Selendroid, UIAutomator, UIAutomation.

How to automate testing?

Automation Testing – A One-Stop Solution to a "Bug-Free" Application

Appium is the cross-platform solution for mobile test automation. Appium is an open-source, cross-platform mobile test automation tool to automate the testing for native, hybrid and mobile web applications. Appium has the ability to deal with all sorts of applications. Let's understand the different types of applications such as Native Applications, Web Applications and Hybrid Applications.

Appium Architecture

Appium is an HTTP server written in node.js which creates and handles multiple WebDriver sessions for different platforms like iOS and Android. Appium starts a "test case" on the device that spawns a server and listens for proxied commands from the main Appium server. It is almost same as Selenium server which perceives HTTP requests from Selenium client libraries, and it handles those requests in different ways depending upon the platforms. Each vendor like iOS and Android have a different way and mechanism to run a test case on the device so Appium kind of hacks into it and run this test case after listening commands from Appium server.

Appium supports both iOS and Android Applications

Appium comes with support for Android, iOS on real devices as well as simulators and emulators. At the core, Appium is an HTTP server written in node.js.For automating iOS and Android mobile application testing, Appium uses Apple Instrumentation library or Google UI Automator to stabilize the connection between Mac OS and iOS or Windows/Linux and Android. Instruments and UI Automator libraries provide application performance, memory analysis, and testing tools for dynamically tracking and profiling iOS and Android codes, respectively.

Appium uses XCTest framework, which is developed by apple in Swift or Objective-C Language.

More information about this instrument and UI Automator can be found at

iOS - Apple Developer Tools
Android - Android UI Automator

Pre-requisites

Here are the pre-requisites for using Appium

1.NodeJS installed globally in the system. https://nodejs.org/en/download/
2.JAVA(JDK) installed in the system.
3.Andriod(SDK) installed in the system.
4.Set JAVA_HOME & ANDROID_HOME paths correctly in the system.
5.Chrome browser installed
6.Text Editor/IDE (Optional) installed Sublime/Visual Studio Code/Brackets, XCode (when installing on MAC)

Appium test codes can be written in any framework or language like Ruby on Rails, C# and Java, TypeScript without having to modify the apps for automation purposes.

[In our discussion we will code with TypeScript language. TypeScript language latest and new trend in automation testing. Now question raised that why we are using TypeScript language rather than other languages.

Introduction of TypeScript

Traditionally, most Java programmers hate JavaScript. TypeScript changes all that. You'll love TypeScript if you enjoy programming Java.That's because TypeScript adds a little syntactic sugar to JavaScript.

TypeScript is an open-source programming language developed and maintained by Microsoft. With TypeScript you can reap both the benefits of an object-oriented as well as functional programming paradigms. It adds optional static typing to your JavaScript code i.e. now variables & methods would be recognized at compile/transpile time just as any compiler of oops language.

Basically, TypeScript adds a few concepts to JavaScript

1.classes
2.private attributes
3.closures (with fat arrow syntax and intuitive variable scope)
4.decorators (roughly comparable to Java's annotations)
5.getters and setters
6.None of these concepts are new to JavaScript. They are emulated using functions. But that's the catch, JavaScript uses a single idea - functions - to implement a variety of different concepts. TypeScript uses dedicated keywords. This makes TypeScript code a pleasant read. As a side effect, Java programmers feel at home in TypeScript country in no time. You don't lose anything by embracing TypeScript.

TypeScript’s main benefits

1.Class and Module Support
2.Static Type-checking
3.ES6 Feature Support
4.Clear Library API Definition
5.Build-in Support for JavaScript Packaging
6.Syntax Similarity to Our Backend Languages (Java, Scala)
7.Superset of JavaScript

How to run application in Appium(Desktop)

1.Firstly install the Appium desktop tool.
2.Start the Appium server.
3.Go to the Appium and create new session and then set capabilities.
4.After setting the capabilities start the session.

  "platformName": "Android",
  "automationName": "UiAutomator2",
  "deviceName": "Android Emulator",
  "platformVersion": "8.1.0",
  "app": "<path of apk>"
5.Then get the accessibility id
6.Set the capabilities in visual studio
const iosCaps = {
    platformName: 'iOS',
    automationName: 'XCUITest',
    deviceName: process.env.IOS_DEVICE_NAME || 'iPhone Simulator',
    platformVersion: process.env.IOS_PLATFORM_VERSION || '13.2',
    app: '<path of apk>'
};

const androidCaps = {
    platformName: 'Android',
    automationName: 'UiAutomator2',
    deviceName: process.env.ANDROID_DEVICE_NAME,
    platformVersion: process.env.ANDROID_PLATFORM_VERSION || '8.1.0',
    app: '<path of apk>'
};
7.Create a simple test case to install application and show the current package.

describe('Create Android session', () => {

    it('Create session', async () => {
        const client = await initClient(androidOptions);
        const res = await client.status();
        assert.isObject(res.build);
        const current_package = await client.getCurrentPackage();
        assert.equal(current_package, '<package name>');

        const screenApp = await getScreepApp();
        assert.isObject(screenApp);
    });

});

Use of Mocha Framework in automation testing

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting while mapping uncaught exceptions to the correct test cases.

Steps to install Appium using npm through command prompt

Appium is an open-source test automation framework and the hero of today’s tutorial.

Open the Node.js command prompt from the start menu.

Type the following command in the terminal

npm install -g appium@1.7.2

Successful installation of Appium can be checked by entering the command- Appium in command prompt. If no error message is displayed, it means Appium is successfully installed.

Steps to run Appium server

1.Run the npm Appium by command
npm run appium
2.Run the test case
npm run test

Challenges in Automation Mobile testing

1.Tighter release schedules leave less time to automate
2.Maximizing test automation coverage within an open source framework
3.Test automation stability and reliability are a quality risk
4.Test automation flakiness and quality visibility introduces quality blind spots
5.Test automation tool stack isn’t in sync with organizational capabilities causing testing inefficiencies.

Conclusion

Mobile automation testing is a raising need in the software development field, and we are facing so many challenges around it. So testing automation tools like Webdriver and Appium and Robotium enables teams to make it faster and easier. However, every tool and its implementation also needs experience and a robust strategy.

Do you have an interesting idea?

Let’s Connect