Skip to content

pritesh1991/AppiumDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Appium Mobile Test Automation Framework

Java Appium TestNG Gradle License: MIT

A robust and scalable mobile test automation framework built with Appium, Java, and TestNG for testing Android and iOS mobile applications. This framework implements the Page Object Model (POM) design pattern and supports parallel test execution.

πŸ“‹ Table of Contents

✨ Features

  • πŸš€ Cross-Platform Support: Test both Android and iOS applications
  • πŸ—οΈ Page Object Model: Clean and maintainable test code structure
  • πŸ”„ Thread-Safe Execution: Support for parallel test execution
  • 🎯 Appium Server Management: Automatic Appium server start/stop
  • πŸ“± Multi-Device Support: Run tests on emulators, simulators, and real devices
  • πŸ§ͺ TestNG Integration: Powerful test framework with annotations and reporting
  • πŸ“Š Test Reporting: Built-in reporting capabilities with TestNG
  • πŸ”§ Flexible Configuration: Easy platform and device configuration
  • 🎨 Clean Architecture: Separation of concerns with page objects and test classes

πŸ›οΈ Architecture

This framework follows a layered architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Test Layer             β”‚  ← FirstTest.java
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚      Page Layer             β”‚  ← WelcomePage.java
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Page Objects Layer        β”‚  ← WelcomePageObject.java
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚     Base Test Layer         β”‚  ← BaseTest.java
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Driver Factory Layer      β”‚  ← DriverFactory.java
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Design Patterns

  • Page Object Model (POM): Separates page elements from test logic
  • Factory Pattern: Driver creation and management
  • ThreadLocal Pattern: Thread-safe driver instances for parallel execution

πŸ“¦ Prerequisites

Before you begin, ensure you have the following installed:

  • Java Development Kit (JDK): Version 17 or higher

  • Gradle: Version 8.2 or higher (included via Gradle Wrapper)

    • Verify installation: ./gradlew --version
  • Node.js and npm: For Appium installation

  • Appium: Version 2.x recommended

    npm install -g appium
    • Verify installation: appium --version
  • Android SDK (for Android testing):

  • Xcode (for iOS testing - macOS only):

  • Appium Drivers:

    appium driver install uiautomator2  # For Android
    appium driver install xcuitest       # For iOS

πŸš€ Installation

  1. Clone the repository:

    git clone https://github.com/pritesh1991/AppiumDemo.git
    cd AppiumDemo
  2. Verify Gradle installation:

    ./gradlew --version
  3. Download dependencies:

    ./gradlew build --no-daemon -x test
  4. Set up your mobile app:

    • Place your Android APK file in the app/ directory
    • Place your iOS app file in the app/ directory
    • Update the app paths in DriverFactory.java if needed

πŸ“ Project Structure

AppiumDemo/
β”œβ”€β”€ app/                          # Mobile application files
β”‚   β”œβ”€β”€ gojek.apk                 # Sample Android app
β”‚   β”œβ”€β”€ coffee-timer.app          # Sample iOS app
β”‚   └── sample.apk
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   └── java/
β”‚   β”‚       β”œβ”€β”€ appium/
β”‚   β”‚       β”‚   └── driver/
β”‚   β”‚       β”‚       └── DriverFactory.java      # Driver initialization
β”‚   β”‚       β”œβ”€β”€ pages/
β”‚   β”‚       β”‚   └── WelcomePage.java            # Page actions
β”‚   β”‚       β”œβ”€β”€ pageobjects/
β”‚   β”‚       β”‚   └── WelcomePageObject.java      # Page elements
β”‚   β”‚       └── BaseTest.java                   # Base test setup
β”‚   └── test/
β”‚       └── java/
β”‚           └── FirstTest.java                  # Test cases
β”œβ”€β”€ build.gradle                  # Gradle build configuration
β”œβ”€β”€ settings.gradle               # Gradle settings
β”œβ”€β”€ gradlew                       # Gradle wrapper script (Unix)
β”œβ”€β”€ gradlew.bat                   # Gradle wrapper script (Windows)
└── README.md                     # This file

βš™οΈ Configuration

Platform Configuration

Edit src/main/java/appium/driver/DriverFactory.java to configure the platform:

String platform = "android";  // Change to "ios" for iOS testing

Android Configuration

Update the following in DriverFactory.java:

options.setAutomationName("UiAutomator2")
       .setPlatformName("Android")
       .setApp(getAndroidPath())
       .setUdid("emulator-5554");  // Your device/emulator ID

Find your device ID:

adb devices

iOS Configuration

Update the following in DriverFactory.java:

options.setApp(getiOSPath())
       .setAutomationName("XCUITest")
       .setPlatformName("iOS")
       .setDeviceName("iPhone 14")  // Your device/simulator
       .setPlatformVersion("16.0");  // Your iOS version

Find available simulators:

xcrun simctl list devices

Appium Server Configuration

The framework automatically starts Appium server on a free port. To use a custom Appium installation path, update:

.withAppiumJS(new File("/path/to/appium"))

πŸ“– Usage

Writing Tests

  1. Create a Page Object (define elements):

    public class LoginPageObject {
        @AndroidFindBy(id = "username_field")
        public WebElement usernameField;
        
        @AndroidFindBy(id = "password_field")
        public WebElement passwordField;
    }
  2. Create a Page Class (define actions):

    public class LoginPage {
        LoginPageObject loginPageObject;
        
        public LoginPage(AppiumDriver driver) {
            loginPageObject = new LoginPageObject();
            PageFactory.initElements(new AppiumFieldDecorator(driver), 
                                    this.loginPageObject);
        }
        
        public void login(String username, String password) {
            loginPageObject.usernameField.sendKeys(username);
            loginPageObject.passwordField.sendKeys(password);
        }
    }
  3. Create a Test Class:

    public class LoginTest extends BaseTest {
        @Test
        public void testLogin() {
            LoginPage loginPage = new LoginPage(threadLocalDriver.get());
            loginPage.login("user@example.com", "password123");
        }
    }

πŸ§ͺ Running Tests

Run All Tests

./gradlew test

Run Specific Test Class

./gradlew test --tests FirstTest

Run with Custom JVM Arguments

./gradlew test -Dplatform=android -Ddevice=emulator-5554

Build Without Tests

./gradlew build -x test

Clean and Build

./gradlew clean build

πŸ“Š Test Reports

TestNG generates test reports after execution:

  • Location: build/reports/tests/test/index.html
  • Open in browser: Double-click the file or use:
    open build/reports/tests/test/index.html  # macOS
    xdg-open build/reports/tests/test/index.html  # Linux
    start build/reports/tests/test/index.html  # Windows

🎯 Best Practices

  1. Keep Tests Independent: Each test should be able to run independently
  2. Use Meaningful Names: Test and method names should clearly describe what they test
  3. Follow Page Object Model: Keep element locators separate from test logic
  4. Avoid Hard Waits: Use explicit waits instead of Thread.sleep()
  5. Clean Up Resources: Always close drivers and stop Appium server
  6. Use Data Providers: For data-driven testing with TestNG
  7. Handle Exceptions: Implement proper error handling and logging
  8. Version Control: Don't commit sensitive data or large binary files

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/your-feature-name
  3. Make your changes
  4. Run tests to ensure nothing breaks:
    ./gradlew test
  5. Commit your changes:
    git commit -m "Add: your feature description"
  6. Push to your fork:
    git push origin feature/your-feature-name
  7. Open a Pull Request

Coding Standards

  • Follow Java naming conventions
  • Add JavaDoc comments for public methods
  • Write unit tests for new features
  • Keep methods small and focused
  • Use meaningful variable names

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

Common Issues

Issue: "Appium server not found"

  • Solution: Ensure Appium is installed globally: npm install -g appium
  • Verify installation path and update withAppiumJS() in DriverFactory

Issue: "Device not found"

  • Solution: Check device/emulator is running: adb devices (Android) or xcrun simctl list (iOS)

Issue: "App not found"

  • Solution: Verify the app path in getAndroidPath() or getiOSPath() methods

Issue: "Build fails with dependency errors"

  • Solution: Clear Gradle cache: ./gradlew clean build --refresh-dependencies

Getting Help

Useful Resources

🌟 Keywords

Mobile Testing, Appium, Java, TestNG, Android Testing, iOS Testing, Test Automation, Page Object Model, Gradle, Selenium, Mobile App Testing, UI Testing, Automated Testing, Test Framework, Cross-Platform Testing, CI/CD, Quality Assurance, Software Testing


Made with ❀️ for the mobile testing community

Star ⭐ this repository if you find it helpful!

About

A robust and scalable mobile test automation framework built with Appium, Java, and TestNG for testing Android and iOS mobile applications. This framework implements the Page Object Model (POM) design pattern and supports parallel test execution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages