Writing an Appium Test in Kotlin

March 30, 2026 · 10 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual examination made easygoing through data skill insights.
Differentiating capabilities:
  • Extensive end-to-end mechanization of QA procedure
  • Comparative analysis of app performance against peers
  • Continuous monitoring of app execution using synthetic information for higher availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Low-priced Real Device Testing for Emerging Teams
cloudtest go
Low-priced Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized nomadic tryout execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based examination

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Writing Appium Test in KotlinWriting Appium Test in Kotlin

Writing an Appium Test in Kotlin

Published on
April 26, 2020
Updated on
Published on
August 25, 2021
Updated on
 by 
ILYA DREYTSERILYA DREYTSER
ILYA DREYTSER

Kotlin is a modern programming speech that concenter on conciseness, clarity, and code safety. Google officially adopted Kotlin by adding support into Android Studio in 2017 and since then has declare it as the preferred language for Android developers at Google I/O 2019. Perhaps your Android app team has incrementally added Kotlin code to your project or get elected to start new Android projects in Kotlin displace frontward. Having the app code and UI automation code in the same language helps engineering and QA squad level set on the critical user journeys being tested. I ’ d like to share the basics of get started with in Kotlin. I ’ ll be habituate the Google News Android app as the target for this example and examination on a real Google Pixel 3 XL from the.

Kotlin is fully compatible with Java so we can fortunately leverage the Appium Java client and JUnit libraries in addition to writing our code in the IntelliJ IDE. IntelliJ has a complimentary community version telephone IntelliJ IDEA CE, which can be downloaded from theirwebsiteor via your package handler.

Getting started

In IntelliJ IDE, navigate toFile & gt; New Project. Select Gradle and under Extra Libraries and Frameworks select Kotlin/JVM.

Kotlin JVM

In the Project file scene on the left, open thebuild.gradlefile and add the following dependencies:

testCompile radical: & # x27; junit & # x27;, gens: & # x27; junit & # x27;, version: & # x27; 4.13 & # x27;
compile group: & # x27; io.appium & # x27;, gens: & # x27; java-client & # x27;, version: & # x27; 7.3.0 & # x27;

We will add the Appium examination in thesrc/test/kotlinproject directory.

Kotlin file structure

Right chatter theKotlinsubdirectory and selectNew & gt; Kotlin File/Class. Create three new family:

  • ProjectCapabilities
  • TestBase
  • GoogleNewsAndroidTest
New Kotlin File Class

We will structure the project in these three course to make the organization clear. TheProjectCapabilitiesclass will regress the Desired Capabilities,TestBasewill be a base class for our test for scaffold the test setup and teardown, and finally theGoogleNewsAndroidTestclass will inherit from ourTestBase, use the Desired Capabilities, and contain our test logic.

1. ProjectCapabilities Class

Let ’ s get started with the ProjectCapabilities class. This grade will have a method to return the Desired Capabilities.

significance org.openqa.selenium.remote.DesiredCapabilities

class ProjectCapabilities {
companion object {
fun AndroidBaseCapabilities (): DesiredCapabilities {
val cap = DesiredCapabilities ()
caps.setCapability (& quot; autoAcceptAlerts & quot;, true)
caps.setCapability (& quot; platformName & quot;, & quot; Android & quot;)
caps.setCapability (& quot; automationName & quot;, & quot; UiAutomator2 & quot;)
caps.setCapability (& quot; deviceName & quot;, & quot; 8ABY0H6YG & quot;)
caps.setCapability (& quot; udid & quot;, & quot; 8ABY0H6YG & quot;)
caps.setCapability (& quot; appPackage & quot;, & quot; com.google.android.apps.magazines & quot;)
caps.setCapability (& quot; appActivity & quot;, & quot; com.google.apps.dots.android.app.activity.CurrentsStartActivity & quot;)
return caps
       }
   }
}

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Check out:

Functions and Methods in Kotlin are declared with the “ fun ” keyword. You can likewise bespeak the function return type with a colon postdate by the type. We can make this a static category method by declaring it in a “ companion object. ” You can create read-only variables with “ val ” and variable that can be reassigned with “ var ”.

In this case I am targeting a real Pixel 3 XL device in the HeadSpin platform. From the HeadSpin Web UI you can get the minimum Desired Capabilities for the device by chatter on the upright dots menu and take Automation Configuration.

For the appPackage and appActivity I am limit the associated values for the Google News Android app.

Execute automated Android app testing on real devices worldwide to build high-performing Android apps..

2. TestBase Class

Next, let ’ s work on our TestBase grade. By nonpayment, classes in Kotlin are implicitly final and can ’ t be inherited. To get a class inheritable, we ’ ll mark it with the “ exposed ” keyword. In this form we will make property variables for the: driver, capability, HeadSpin API Token, and WebDriver URL. We ’ ll provide visibility modifiers to our properties, in this case:

  • Protected: Only visible in the class or subclasses
  • Private: Only visible in the class

We ’ ll also label our Desired Capabilities variable as “ exposed ” so it can be overridden from our GoogleNewsAndroidTest grade which inherits from the TestBase class.

Check out:

In addition, you can indicate whether a varying can be null. The ability to declare this upfront is a outstanding lineament of the Kotlin language because it protects against unexpected NullPointerExceptions from our code. In this instance we can bespeak that the driver and caps can be null with “? ” after the type and set them to null. Kotlin also back string interpolation by using the “ $ ” fibre to interpolate a variable or “ $ {} ” to interpolate an verbalism. We ’ ll use this convenient language characteristic to pass our HeadSpin API Token to our WebDriver URL string.

Our TestBase will also feature two JUnit annotations: @ Before for our setup function and @ After for our teardown to execute a driver quit. Our setup function will be straightforward and it will instantiate the driver object. In our teardown role we ’ ll check to see if the driver object is not null and if so, resign our session. Otherwise, we will throw an Exception. Kotlin cater a convenience operator for control for a null condition with “?: ”. This is called the Elvis Operator because if you turn your head sideways the question mark character looks like a swoosh of hair and the colon look like eyes.

rockstar

Do you see the resemblance now? Haha either way, the source code for the class can be constitute below and let ’ s carry on.

import io.appium.java_client.MobileElement
importee io.appium.java_client.android.AndroidDriver
import org.junit.After
import org.junit.Before
importation org.openqa.selenium.remote.DesiredCapabilities
import java.lang.Exception
import java.net.URL

open stratum TestBase {
protected var driver: AndroidDriver & lt; MobileElement & gt;? = null
protect exposed var detonator: DesiredCapabilities? = cypher
private val headSpinAPIToken: String = & quot; your-api-token-here & quot;
private val webDriverURL: URL = URL (& quot; https: //appium-dev.headspin.io/v0/ $ headSpinAPIToken/wd/hub & quot;)


   @Before
fun setUp () {
this.driver = AndroidDriver (webDriverURL, cap)
   }

   @After
fun tearDown () {
this.driver? .quit ()?: throw Exception (& quot; Driver instance was unable to quit. & quot;)
   }

}

Also check:

3. GoogleNewsAndroidTest Class

Our last category, GoogleNewsAndroidTest will have our test logic. Here we have one test role footnote with the JUnit Test notation. Our test will be simple and straight, we will tap on the Headlines tab button and then scroll down from the list of tidings articles. Since we will be do driver action we ’ ll need to first ensure the driver is not void. Kotlin provides a way to perform an operation only if the value is not void using the “? ” (the safe call operator) together with “ let. ”

import io.appium.java_client.MobileBy
importee org.junit.Test
import org.openqa.selenium.interactions.Interaction
importation org.openqa.selenium.interactions.PointerInput
import org.openqa.selenium.interactions.Sequence
significance org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.support.ui.ExpectedConditions
significance org.openqa.selenium.support.ui.WebDriverWait
importation java.time.Duration

class GoogleNewsAndroidTest: TestBase () {
override var caps: DesiredCapabilities? = ProjectCapabilities.AndroidBaseCapabilities ()
private val headlinesTabButton: String = & quot; com.google.android.apps.magazines: id/tab_headlines & quot;

   @Test
fun headlinesScrollTest () {

// Set an denotative wait of 10 seconds
val wait = WebDriverWait (driver? .let {it}, 10)

// Tap on the Headlines tab button
wait.until (ExpectedConditions.presenceOfElementLocated (MobileBy.id (headlinesTabButton))) .click ()

// Scroll Down
val finger: PointerInput = PointerInput (PointerInput.Kind.TOUCH, & quot; finger & quot;)
val moveToStart: Interaction = finger.createPointerMove (Duration.ZERO, PointerInput.Origin.viewport (), 726, 2452)
val pressDown: Interaction = finger.createPointerDown (PointerInput.MouseButton.LEFT.asArg ());
val moveToEnd: Interaction = finger.createPointerMove (Duration.ofMillis (1000), PointerInput.Origin.viewport (), 726, 660)
val pressUp: Interaction = finger.createPointerUp (PointerInput.MouseButton.LEFT.asArg ())

val swipe = Sequence (finger, 0)
swipe.addAction (moveToStart)
swipe.addAction (pressDown)
swipe.addAction (moveToEnd)
swipe.addAction (pressUp)

driver? .let {it.perform (arrayListOf (swipe))}

   }
}

Don ’ t Rely on iOS Emulators & amp; Android Simulators..

Conclusion

Our work hither is done! We can now execute our test and vigil it in action.

Test execution using Kotlin

Congratulations you now feature a taste of what it ’ s like to indite an Appium test in Kotlin! If this article has helped farther your knowledge feel complimentary to Like or Share it. You can download the total project rootage codificationhere.

FAQs

1. Is Kotlin expend for Android app ontogenesis?

Ans: Yes. Kotlin supports the growth of Android apps. Many covering already use Kotlin, such as Basecamp and Pinterest.

2. What are the important features of Kotlin?

Ans: 

  • Kotlin is easy to learn as its syntax is alike to Java
  • It is a functional language and is based on Java practical machine (JVM)
  • It is an easy language that makes code readable and apprehensible

3. How can testers inspect elements on the iOS apps?

Ans:With the help of an Appium inspector, a GUI-based creature, testers can place ingredient on iOS apps. This GUI-based instrument is similar to that of selenium IDE.

4. Which IDEs support Kotlin?

Ans:Kotlin supports all major Java IDEs, include IntelliJ IDEA, Android Studio, and Eclipse.

Author & # x27; s Profile

ILYA DREYTSER

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a active and results-driven Content Marketing Specialist with 8+ days of experience in crafting engaging narrative and marketing collateral across diverse industriousness. She excels in collaborating with cross-functional teams to germinate innovative content strategy and deliver compelling, authentic, and impactful content that resonates with target audiences and enhances marque authenticity.

LinkedIn

Writing an Appium Test in Kotlin

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for forward-looking users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence hard-nosed guidebook for forward-looking user (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gain a competitive edge
faster development cycles
Boost developer/QA productiveness with faster development round
automated buil-over-build regression testing
Automate build-over-build regression prove for ordered results
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, picture, and content quality of experience (QoE) effortlessly
The trusted alternative for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior quiz capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for reproducible results
gain better visibility into functional & performance issues
Gain better visibility into functional and execution issues
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, picture, and contented quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a militant edge
faster development cycles
Boost developer/QA productiveness with faster evolution cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain best visibility into functional and execution issues
reduce mean time
Reduce mean time to identify/resolve during examination, QA, and production
evaluate audio, video & qoe
Evaluate sound, video, and contented calibre of experience (QoE) effortlessly
The trusted selection for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free