Automation Testing - iOS XCUITest with Cucumberish

Mobile Development Mar 31, 2022

Halodoc provides digital health solutions to millions of users, and our main goal is to deliver a product of good quality. To achieve it for iOS devices we use UI automation tests to make sure Regression tests are running successfully.

In Halodoc we use “iOS XCUITest - Cucumberish” i.e. BDD Framework in Xcode.

What is Cucumberish?

Cucumberish is the test automation framework that drives execution of the tests specified in feature files and written in Gherkin language.The framework integrates well with newest versions of Xcode and the implementation of the tests can be written in both Objective-C or Swift.

  • Gherkin feature files can be executed from Xcode, and Cucumberish can be imported to UI Test targets with CocoaPods or Carthage.
  • Cucumberish is not limited to UI.
  • Cucumberish is capable of creating human-readable Xcode reports.

Comparing Cucumberish with other iOS test automation Frameworks:

Based on our experienced using some of the other IOS test automation frameworks (as outlined below), here are our findings,

  • XCTest is the best for unit tests.
  • XCUITest is the best for UI testing.
  • KIF and Earlgrey are the best for API testing.
  • Testing BDD with cucumberish is the best.

Cucumberish can be combined with our preferred frameworks and tools, so it is not limited to UITest; we can also use Cucumberish to implement API and Unit+UI Testing.

Benefits Of Cucumberish:

Cucumberish is a cocoa-pod library that runs Cucumber tests in Xcode

  • Provides a comprehensive file parser that enables engineers to use tagging and data tables within BDD Feature files.
  • Executes as fast as a typical XCUnit / XCUITest.
  • Engineers can leverage XCUITest with no servers injected into their applications.
  • You can run all tests using one XCUITest target, then select a subset of tests to run using multiple XCSchemes.
  • Highlights assertion failures on the actual line of the feature file itself.
  • The best part is that you can use Swift (or even Objective-C) to implement it.Installation via cocoa-pods.

How to set up:

1. Install Cucumberish via Cocoa-pods

Pod Install.

2. Setting up an initialiser class for Cucumberish and how test execution starts

3. Setup a launcher class that executes the Cucumberish Initializer function when classes are loaded into memory.

4.  Creating folder with feature files and create a reference link of the folder into your Xcode project

5.  Writing step definitions using the Given, When, Then Objective-C global methods. These methods register the steps in order to evaluate the scenario steps during test execution.

6. Running the scheme from xcode.

7. Now run the Test using “ Cmd+U ”.

How does it work:

  • When "Cucumberish.executeFeatures" is executed, an XCTestCase Class for every ".feature" file in the specified directory is created.
  • Each scenario in the feature file will be parsed and converted into a test function of the corresponding XCTestCase.
  • Each scenario step will call the corresponding step definition (along with the one defined previously).

What happens when scenarios fail:

  • When scenarios fail, Cucumberish highlights the failed step as an error on the feature file.

FrameWork Structure in Halodoc:

For test case development, at Halodoc we follow the "DRY" principle. "Don't repeat yourself" (DRY) is a principle of software development aimed at reducing repetition of software patterns by substituting abstractions or using data normalisation to reduce redundancy.

When the DRY principle is successfully applied, the modification of any single element of a system does not necessitate the change of other logically unrelated elements. Furthermore, logically related elements change predictably and uniformly, so they are kept in sync

Halodoc's Commons architecture used by iOS app:

Implementation of HDAutomationCommons pod:

HDAutomationCommons Folder Structure:

This pod serves as a library for Automation on two levels. The first is a module API and the second is Common Utilities for UITests.

Module Api:

This part has API services implemented, which is used in several parts of our app module for example:

  • To accept/Reject Tele-consultation.
  • To cancel/Complete/Confirm/Reschedule the booked appointment.
  • To Enter OTP while logging in  and many more such scenarios are used as per business point.

CommonUtils :

These Swift class files keep the Swift class files of different UI module helpers that help in maintaining reusability of codes in most scenarios such as:

  • Login through application.
  • Accepting permission and setting location for the application.
  • Logout from the application and many more such scenarios.

Benefits of using Automationlibrary:

  • We can significantly reduce our resource consumption by reusing our common functions like LocationHandling(), Login(), and Logout().
  • By using HDAutomationCommon(), we avoid duplicating code and object details.
  • Eliminate code duplication of generic methods such as click(), scroll(), swipe(), attachScreenshot(), etc. which are used throughout the framework.
  • As a result of our framework's use of the "DRY" principle, we have been able to decrease the lines of codes and increase reusability.

Conclusion:

Based on our experience of using Cucumberish for ios Test automation, and adoption BDD process, we have significantly benefited in terms of improving our test automation activities through human-readable, scalable and reusable code. In our opinion, we feel that Cucumberish is a must use feature in enhancing over test automation activities for the IOS platform.

Join us

Scalability, reliability, and maintainability are the three pillars that govern what we build at Halodoc Tech. We are actively looking for engineers at all levels and if solving hard problems with challenging requirements is your forte, please reach out to us with your resumé at careers.india@halodoc.com.

About Halodoc

Halodoc is the number 1 all around Healthcare application in Indonesia. Our mission is to simplify and bring quality healthcare across Indonesia, from Sabang to Merauke. We connect 20,000+ doctors with patients in need through our Tele-consultation service. We partner with 4000+ pharmacies in 100+ cities to bring medicine to your doorstep. We've also partnered with Indonesia's largest lab provider to provide lab home services, and to top it off we have recently launched a premium appointment service that partners with 500+ hospitals that allow patients to book a doctor appointment inside our application. We are extremely fortunate to be trusted by our investors, such as the Bill & Melinda Gates Foundation, Singtel, UOB Ventures, Allianz, GoJek, Astra, Temasek and many more. We recently closed our Series C round and In total have raised around USD$180 million for our mission. Our team works tirelessly to make sure that we create the best healthcare solution personalised for all of our patient's needs, and are continuously on a path to simplify healthcare for Indonesia.