<- Blog

Testing Flipkart’s Android app using Maestro

Ronak Kadhi April 17, 2023

If you have been using Maestro in the past, you must already know how easy it is to test your app. To maintain and enhance this experience, we continually evaluate numerous apps internally with Maestro. This testing process allows us to pinpoint unique user journeys (also known as flows), which in turn helps us refine Maestro’s usability and user-friendliness. One such app is Flipkart.

About Flipkart

Flipkart is India’s biggest e-commerce platform, with more than 160 million visits per month & the first Indian app to cross 50 million downloads. Flipkart has more than 80 million products listed on its platform. Along with this massive product catalog, they run multiple offers & serve more than 20,000 orders daily. Flipkart has a relentless mobile-first approach.

What are we Testing?

In today’s blog, we will test Flipkart’s cart functionality. The cart functionality has many concurrent services which help the team manage the ever-changing product catalog. Testing the cart functionality will ensure that everything is up to date while giving a seamless user experience.

Add to cart

This flow will help you keep a check on products that are recently updated. Maestro also lets you perform actions like swiping left & selecting product variants (here size). Here is how the flow would look like

  • Search for an item
  • Select an item
  • View gallery
  • Add item
                       #Flow for adding an Item to the cart

appId: com.flipkart.android
---
- launchApp

# search for shoes
- tapOn: "Search for products"
- inputText: "shoes"
- tapOn: "shoes men"

# find sneakers
- scrollUntilVisible:
    element: ".*Sneakers.*"
- tapOn: ".*Sneakers.*"

# swipe gallery
- repeat:
    times: 3
    commands:
      - swipe:
          direction: LEFT
- tapOn: ".*Add to cart.*"

# choose size
- tapOn: "3"

- tapOn: "Continue"

Checkout the video here

Remove from cart

Once you have added a product to the cart, you can also use Maestro to remove items from the cart. Here is the flow

  • View cart
  • Remove item
  • Ensure the item is removed (Using Maestro’s assertion)
                     #Flow to remove an Item from the cart

appId: com.flipkart.android
---
- launchApp

# Open cart and removes cart item
- tapOn: "Cart"
- tapOn: "Remove"
- assertVisible: "Remove Item "
- tapOn: "Remove"

# Check if cart is empty
- assertVisible: "Missing Cart items?"

Check items in the cart.

The flow in Maestro will help you test the cart’s expected number of items. In this example, we are checking if the cart has 1 item. This flow requires an extra script to identify the number of items in the cart & revert with a value. It can show an error if it doesn’t return the desired value. Check out below for the code snippet in the code block.

  • View cart
  • Run Javascript to extract no. of items in the cart
  • The extracted value is matched with the desired result
             // Extracts the number of items from the copied text

function extractNumber(text) {
  const regex = /(\d+)/;
  const match = text.match(regex);
  var numberOfItems = -1;

  if (match !== null) {
    numberOfItems = match[0];
  }
  return Number(numberOfItems);
}

output.cartItemsNumber = extractNumber(maestro.copiedText);
                 #Flow to check the no. of items in the cart

appId: com.flipkart.android
---
- launchApp

# Open cart and find number of items
- tapOn: "Cart"
- scrollUntilVisible:
    element: "Price Details.*"
- copyTextFrom:
    text: .*item.*

# extract cart items number
- runScript: "extractCartItems.js"
- evalScript: ${ if (output.cartItemsNumber !== 1) throw new Error('Unexpected number of cart items'); }

Summary

We conclude how to use Maestro to test Flipkart using Maestro. I hope this gets you started on your testing journey. The aim for us at Mobile.dev is to create a platform that will enable developers to create consistent apps which delight their customers & stay away from a 1-star rating.

Testing Flipkart was part of our new project called “Roast my app,” where we asked our Twitter community to send us their app for testing so we could give them feedback & test their app in Public.

Join our slack community for more updates & support.

We're entering a new era of software development. Advancements in AI and tooling have unlocked unprecedented speed, shifting the bottleneck from development velocity to quality control. This is why we built — a modern testing platform that ensures your team can move quickly while maintaining a high standard of quality.

Learn more ->