Bumble Tech
Published in

Bumble Tech

Photo by Jeremy Bishop on Unsplash

Automating Android Jetpack Compose using Appium

But first, what is Jetpack Compose?

Is, there any alternative in Appium?

// Test rules and transitive dependencies:androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")// Needed for createComposeRule, but not createAndroidComposeRule:debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")

Using Appium to automate Compose

driver.setSetting(“driver”, “compose”);
driver.setSetting(“driver”, “espresso”);
espressoBuildConfig: ‘{“additionalAndroidTestDependencies”: [“androidx.lifecycle:lifecycle-extensions:<version>”, “androidx.activity:activity:<version>”, “androidx.fragment:fragment:<version>”]}’

The Complete Example

require 'appium_lib'

def android_compose_caps()
{
platformName: 'Android',
deviceName: 'emulator-5556',
app: 'compose_playground.apk',
automationName: 'espresso',
newCommandTimeout: 0,
skipUnlock: true,
fullReset: false,
forceEspressoRebuild: true,
showGradleLog: true,
espressoBuildConfig: '{"additionalAndroidTestDependencies": ["androidx.lifecycle:lifecycle-extensions:2.2.0", "androidx.activity:activity:1.3.1", "androidx.fragment:fragment:1.2.0"]}'
}
end

@driver = Appium::Driver.new({ caps: android_compose_caps }, false)
@driver.start_driver

# click on the button with text 'Clickable Component'.
# This will later load a Compose screen with a clickable button
non_compose_button
= @driver.find_element(xpath: "//*[@text='Clickable Component']")
non_compose_button.click

# Change the drive context to 'compose' because now we are on a Compose screen
@driver.update_settings({'driver' => 'compose'})

# We can find Compose button using it's text with XPATH!
button
= @driver.find_element(xpath: "//*[@text='Click to see dialog']")

# we could also find the button using content-description as below
# button =
@driver.find_element(accessibility_id: "desc")

fail
("Text mismatch") unless button.text == 'Click to see dialog'

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store