Back to QA Automation

Module 5: Mobile Testing Automation

Master mobile test automation for iOS and Android with modern tools and cloud platforms

📱 Mobile Testing Fundamentals

Mobile testing is like testing a car in different weather conditions - you need to check how your app works on different devices, screen sizes, and operating systems.

Types of Mobile Testing

Native App Testing

Apps built for specific platforms (Swift/Kotlin)

Hybrid App Testing

Web apps wrapped in native container (Ionic, Cordova)

Cross-Platform Testing

React Native, Flutter apps

Mobile Web Testing

Websites accessed via mobile browsers

Key Challenges

  • • Device fragmentation (1000s of device models)
  • • Different OS versions
  • • Various screen sizes and resolutions
  • • Network conditions (3G, 4G, 5G, WiFi)
  • • Battery and performance constraints
  • • Touch gestures and interactions

🤖 Appium Setup & Configuration

Appium is like a universal remote control for mobile apps - it works with iOS, Android, and even Windows apps!

Installation

# Install Appium

npm install -g appium

# Install drivers

appium driver install uiautomator2 # Android

appium driver install xcuitest # iOS

# Start Appium server

appium

# Install client library

npm install webdriverio @wdio/cli

Android Setup

// wdio.conf.js - Android configuration

exports.config = {

capabilities: [{

platformName: 'Android',

platformVersion: '13',

deviceName: 'Android Emulator',

app: './app/android/app-debug.apk',

automationName: 'UiAutomator2',

appPackage: 'com.example.app',

appActivity: '.MainActivity'

}]

}

iOS Setup

// wdio.conf.js - iOS configuration

exports.config = {

capabilities: [{

platformName: 'iOS',

platformVersion: '16.0',

deviceName: 'iPhone 14',

app: './app/ios/MyApp.app',

automationName: 'XCUITest',

bundleId: 'com.example.app'

}]

}

🎯 Mobile Locator Strategies

// Accessibility ID (Best practice)

await $('~login-button').click();

// XPath (Android)

await $('//android.widget.Button[@text="Login"]').click();

// iOS Predicate

await $('-ios predicate string:name => "Login"').click();

// Class name

await $('android.widget.EditText').setValue('test@email.com');

// Resource ID (Android)

await $('android=new UiSelector().resourceId("com.app:id/username")');

// iOS Class Chain

await $('-ios class chain:**/XCUIElementTypeButton[`name => "Login"`]');

👆 Mobile Gestures & Interactions

Mobile apps use touch gestures - tap, swipe, pinch, long press. Let's automate them all!

// Tap

await $('~button').click();

// Long press

await $('~element').touchAction([

{ action: 'press', x: 100, y: 200 },

{ action: 'wait', ms: 1000 },

{ action: 'release' }

]);

// Swipe down (scroll)

await driver.touchAction([

{ action: 'press', x: 200, y: 800 },

{ action: 'wait', ms: 200 },

{ action: 'moveTo', x: 200, y: 200 },

{ action: 'release' }

]);

// Pinch zoom

await driver.execute('mobile: pinch', {

scale: 2.0,

velocity: 1.0

});

// Drag and drop

const source = await $('~source-element');

const target = await $('~target-element');

await source.dragAndDrop(target);

⚛️ Detox for React Native Apps

Detox is specifically built for React Native - faster and more reliable than Appium for RN apps.

# Install Detox

npm install detox --save-dev

detox init

// e2e/firstTest.e2e.js

describe('Login Flow', () => {

beforeAll(async () => {

await device.launchApp();

});

it('should login successfully', async () => {

// Type into fields

await element(by.id('email-input'))

.typeText('test@email.com');

await element(by.id('password-input'))

.typeText('password123');

// Tap button

await element(by.id('login-button')).tap();

// Verify navigation

await expect(element(by.text('Welcome')))

.toBeVisible();

});

});

# Run tests

detox test --configuration ios.sim.debug

🌐 Mobile Web Testing

Test websites on mobile browsers - Chrome, Safari, Firefox mobile.

// Mobile Chrome

capabilities: {

platformName: 'Android',

browserName: 'Chrome',

deviceName: 'Android Emulator'

}

// Mobile Safari

capabilities: {

platformName: 'iOS',

browserName: 'Safari',

deviceName: 'iPhone 14'

}

// Test mobile website

describe('Mobile Web', () => {

it('should work on mobile', async () => {

await browser.url('https://example.com');

await $('button').click();

await expect($('h1')).toHaveText('Welcome');

});

});

☁️ Device Farms & Cloud Testing

Test on real devices without buying them! Cloud platforms provide access to 1000s of devices.

Popular Platforms

BrowserStack

3000+ real devices, live testing, automation

Sauce Labs

Real devices, emulators, CI/CD integration

AWS Device Farm

Amazon's device testing service

LambdaTest

3000+ browsers and devices

BrowserStack Integration

// wdio.conf.js

exports.config = {

user: process.env.BROWSERSTACK_USERNAME,

key: process.env.BROWSERSTACK_ACCESS_KEY,

hostname: 'hub.browserstack.com',

capabilities: [{

device: 'Samsung Galaxy S23',

os_version: '13.0',

app: 'bs://your-app-id',

'browserstack.debug': true,

'browserstack.networkLogs': true

}]

}

🔄 Cross-Platform Test Strategy

Write tests once, run on both iOS and Android - the dream of every QA engineer!

// helpers/selectors.js

const isIOS = driver.isIOS;

const selectors = {

loginButton: isIOS

? '~login-button'

: 'android=new UiSelector().resourceId("login-button")',

emailInput: isIOS

? '-ios predicate string:name => "email"'

: '//android.widget.EditText[@resource-id="email"]'

};

// Use in tests

await $(selectors.emailInput).setValue('test@email.com');

await $(selectors.loginButton).click();

🚀 Complete Mobile App Test Suite

Build a comprehensive test suite for a shopping app with login, browse, cart, and checkout.

// test/specs/shopping.e2e.js

describe('Shopping App E2E', () => {

it('complete purchase flow', async () => {

// 1. Login

await $('~email-input').setValue('test@email.com');

await $('~password-input').setValue('password123');

await $('~login-button').click();

// 2. Browse products

await expect($('~products-list')).toBeDisplayed();

// 3. Add to cart

await $('~product-1').click();

await $('~add-to-cart-button').click();

await driver.back();

// 4. Go to cart

await $('~cart-icon').click();

await expect($('~cart-item')).toBeDisplayed();

// 5. Checkout

await $('~checkout-button').click();

await $('~confirm-order-button').click();

// 6. Verify success

await expect($('~order-success')).toBeDisplayed();

});

});

🎯 Module Summary

You've mastered mobile test automation:

  • ✓ Mobile testing fundamentals
  • ✓ Appium setup for iOS and Android
  • ✓ Mobile locator strategies
  • ✓ Mobile gestures and interactions
  • ✓ Detox for React Native apps
  • ✓ Mobile web testing
  • ✓ Cloud testing platforms
  • ✓ Cross-platform test strategy
  • ✓ Complete mobile app test suite

Next: CI/CD Integration & Test Management in Module 6!