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.
- Features
- Architecture
- Prerequisites
- Installation
- Project Structure
- Configuration
- Usage
- Running Tests
- Best Practices
- Contributing
- License
- Support
- π 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
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
βββββββββββββββββββββββββββββββ
- 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
Before you begin, ensure you have the following installed:
-
Java Development Kit (JDK): Version 17 or higher
- Download JDK
- Verify installation:
java -version
-
Gradle: Version 8.2 or higher (included via Gradle Wrapper)
- Verify installation:
./gradlew --version
- Verify installation:
-
Node.js and npm: For Appium installation
- Download Node.js
- Verify installation:
node --version && npm --version
-
Appium: Version 2.x recommended
npm install -g appium
- Verify installation:
appium --version
- Verify installation:
-
Android SDK (for Android testing):
- Download Android Studio
- Set
ANDROID_HOMEenvironment variable - Install platform tools and emulator
-
Xcode (for iOS testing - macOS only):
- Download from Mac App Store
- Install Xcode Command Line Tools:
xcode-select --install
-
Appium Drivers:
appium driver install uiautomator2 # For Android appium driver install xcuitest # For iOS
-
Clone the repository:
git clone https://github.com/pritesh1991/AppiumDemo.git cd AppiumDemo -
Verify Gradle installation:
./gradlew --version
-
Download dependencies:
./gradlew build --no-daemon -x test -
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.javaif needed
- Place your Android APK file in the
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
Edit src/main/java/appium/driver/DriverFactory.java to configure the platform:
String platform = "android"; // Change to "ios" for iOS testingUpdate the following in DriverFactory.java:
options.setAutomationName("UiAutomator2")
.setPlatformName("Android")
.setApp(getAndroidPath())
.setUdid("emulator-5554"); // Your device/emulator IDFind your device ID:
adb devicesUpdate the following in DriverFactory.java:
options.setApp(getiOSPath())
.setAutomationName("XCUITest")
.setPlatformName("iOS")
.setDeviceName("iPhone 14") // Your device/simulator
.setPlatformVersion("16.0"); // Your iOS versionFind available simulators:
xcrun simctl list devicesThe framework automatically starts Appium server on a free port. To use a custom Appium installation path, update:
.withAppiumJS(new File("/path/to/appium"))-
Create a Page Object (define elements):
public class LoginPageObject { @AndroidFindBy(id = "username_field") public WebElement usernameField; @AndroidFindBy(id = "password_field") public WebElement passwordField; }
-
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); } }
-
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"); } }
./gradlew test./gradlew test --tests FirstTest./gradlew test -Dplatform=android -Ddevice=emulator-5554./gradlew build -x test./gradlew clean buildTestNG 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
- Keep Tests Independent: Each test should be able to run independently
- Use Meaningful Names: Test and method names should clearly describe what they test
- Follow Page Object Model: Keep element locators separate from test logic
- Avoid Hard Waits: Use explicit waits instead of Thread.sleep()
- Clean Up Resources: Always close drivers and stop Appium server
- Use Data Providers: For data-driven testing with TestNG
- Handle Exceptions: Implement proper error handling and logging
- Version Control: Don't commit sensitive data or large binary files
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes
- Run tests to ensure nothing breaks:
./gradlew test - Commit your changes:
git commit -m "Add: your feature description" - Push to your fork:
git push origin feature/your-feature-name
- Open a Pull Request
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
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) orxcrun simctl list(iOS)
Issue: "App not found"
- Solution: Verify the app path in
getAndroidPath()orgetiOSPath()methods
Issue: "Build fails with dependency errors"
- Solution: Clear Gradle cache:
./gradlew clean build --refresh-dependencies
- π§ Email: Contact Repository Owner
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- Appium Documentation
- TestNG Documentation
- Selenium Documentation
- Gradle User Guide
- Page Object Model Best Practices
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!