DEV Community

Cover image for Mobile Test Automation Framework in Java: Structure, BDD, Parallel
Mayvin Ramasawmy
Mayvin Ramasawmy

Posted on

Mobile Test Automation Framework in Java: Structure, BDD, Parallel

A mobile test automation framework that passes sequentially and collapses under parallel execution isn't flaky. It's single-threaded by construction โ€” one driver instance, screen objects holding element proxies bound to that driver, every thread targeting the same device and the same automation port.

That's an architectural problem, not a matter of tuning waits.

I spent the last few months building one in Java and writing up each step. Nine parts, one codebase, starting from an empty directory:

  • ๐Ÿ—๏ธ The architecture principles behind every later decision โ€” SRP, OCP, DIP, and what "robust" actually means

  • ๐Ÿ“ฆ Maven multi-module layout โ€” and when a single module is the better call

  • ๐Ÿš— DriverManager owning the Appium session, BasePage wiring PageFactory

  • ๐Ÿฅ’ Cucumber and Spring โ€” feature files, step definitions, CucumberSpringConfiguration

  • ๐Ÿ“ฑ One screen object class driving both Android and iOS

  • โš™๏ธ Spring profiles for platform, device, environment and test phase

  • ๐Ÿงต ThreadLocal drivers, @ScenarioScope beans, a device pool with port isolation

One mechanism worth knowing if you're going cross-platform: AppiumFieldDecorator reads the annotations on each field and selects by driver type at runtime. Declare @AndroidFindBy and @iOSXCUITFindBy on the same field, and an AndroidDriver session reads the first and ignores the second โ€” an IOSDriver session does the reverse. You keep one screen object class and one set of step definitions, and switch platforms through configuration alone.

Every hands-on part ships with a complete, runnable code workspace.

๐Ÿ‘‰ Read the full guide here: https://www.mobile-automation.io/build-a-mobile-test-automation-framework/

Top comments (0)