SlideShare a Scribd company logo
Appium Automation with Kotlin
Appium Automation with Kotlin
© RapidValue Solutions 2
Appium Automation with Kotlin
Pre-requisites:
Following are the pre-requisites to start Appium with Kotlin:
 Install Java SDK 8 and above.
 Install Eclipse or IntelliJ IDEA IDEs.
 Install the Kotlin plugin in IDEs. Here I am using Eclipse as IDE and Kotlin plugin for Eclipse
downloaded from https://marketplace.eclipse.org/content/kotlin-plugin-eclipse
 The latest version of following maven dependencies:
o testing
o selenium-java
o selenium-server
o java-client
o kotlin-test
o kotlin-stdlib-jdk8
o extentreports
Step-by-step Procedure
Step 1: Create a maven project and add the above dependencies in pom.xml of the project.
Step 2: Create a Kotlin class to keep the logic to initiate the driver and start the Appium server. Let’s say the
class name is AutomationBase. We are defining this class as an abstract class. So, it is easy to extend by
other classes. We have implemented startApplication, startAppiumServer, getPort, getNodePath,
getJSPath, getDriverInstance and setDriverInstance methods in the AutomationBase class. Below are
the sample code snippets:
fun startApplication() {
try {
var service: AppiumDriverLocalService = startAppiumServer()
var capabilities = DesiredCapabilities()
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “One Plus”)
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”)
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “10”)
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,
AutomationName.ANDROID_UIAUTOMATOR2)
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true)
capabilities.setCapability(“newCommandTimeout”, 180)
capabilities.setCapability(“udid”, “e6916f40”)
capabilities.setCapability(MobileCapabilityType.APP, “YOUR_APP_PATH”)
capabilities.setCapability(MobileCapabilityType.NO_RESET, true)
if(!service.toString().isEmpty()){
driver = AndroidDriver(service.getUrl(), capabilities)
}
} catch (e: Exception) {
Appium Automation with Kotlin
© RapidValue Solutions 3
e.printStackTrace()
}
}
private fun startAppiumServer(): AppiumDriverLocalService {
var IP_ADDRESS: String = “127.0.0.1”
var bootStrapPort: String
var chromePort: String
var port: Int
if (!File(System.getProperty(“user.dir”) + “LogsAppium_logs”).exists()) {
(File(System.getProperty(“user.dir”) + “Logs”)).mkdir()
(File(System.getProperty(“user.dir”) + “LogsAppium_logs”)).mkdir()
}
port = getPort()
bootStrapPort = Integer.toString(getPort())
chromePort = Integer.toString(getPort())
var service = AppiumDriverLocalService.buildService(
AppiumServiceBuilder().withAppiumJS(File(getJSPath()))
.usingDriverExecutable(File(getNodePath())).withIPAddress(IP_ADDRESS).usingPort(port)
.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER, bootStrapPort)
.withArgument(AndroidServerFlag.CHROME_DRIVER_PORT, chromePort)
.withLogFile(File(System.getProperty(“user.dir”) + “LogsAppium_logsappiumLogs.txt”)))
service.start()
if (service.isRunning()) {
System.out.println(“Server is running…..” + service)
} else {
System.out.println(“Server startup failed…..”)
System.exit(0)
}
return service
}
private fun getPort(): Int {
var port: Int = 0
try {
var socket = ServerSocket(0)
socket.setReuseAddress(true)
port = socket.getLocalPort()
socket.close()
} catch (e: Exception) {
e.printStackTrace()
}
return port
}
private fun getNodePath(): String {
var nodePath: String
var p: Process
var reader: BufferedReader
var command: String
Appium Automation with Kotlin
© RapidValue Solutions 4
var operatingSystem: String = System.getProperty(“os.name”)
if (operatingSystem.contains(“Win”)) {
command = “where” + ” ” + “node”
} else {
command = “which ” + “node”
}
p = Runtime.getRuntime().exec(command)
reader = BufferedReader(InputStreamReader(p.getInputStream()))
nodePath = reader.readLine()
p.waitFor()
p.destroy()
return nodePath
}
fun getJSPath(): String {
var jsPaths: String
lateinit var actualJSPath: String
var command: String
var operatingSystem: String = System.getProperty(“os.name”)
if (operatingSystem.contains(“Win”)) {
command = “where” + ” ” + “appium”
var p: Process = Runtime.getRuntime().exec(command)
var stdInput: BufferedReader = BufferedReader(InputStreamReader(p.getInputStream()))
jsPaths = stdInput.readLine()
actualJSPath = jsPaths.replace(“appium”, “node_modulesappiumbuildlibmain.js”)
p.waitFor()
p.destroy()
} else {
actualJSPath = “//usr//local//lib//node_modules//appium//build//lib//main.js”
}
return actualJSPath
}
fun getDriverInstance(): WebDriver {
return this.driver
}
fun setDriverInstance(driver: WebDriver) {
this.driver = driver
}
startApplication method helps to instantiate driver sessions based on the specified capabilities.
startAppiumServer method helps to start the Appium server and also, create and write server logs to a text
file. getPort method helps to create the dynamic network port that supports the startAppiumServer
method. getNodePath method helps to get the node path and it supports the startAppiumServer method.
getJSPath method helps to get the Appium main.js path and it supports the startAppiumServer method.
Step 3: Create a TestRunner class and it extends AutomationBase class. This class holds TestNG
annotations @Listeners, @BeforeClass, and @AfterSuite. Below are the complete code snippets:
Appium Automation with Kotlin
© RapidValue Solutions 5
@Listeners(AutomationReport::class)
open class TestRunner : AutomationBase() {
@BeforeClass
fun setUp() {
startApplication()
}
@AfterSuite
fun tearDown() {
Thread.sleep(3000)
driver.quit()
}
}
Step 4: Create a sample test class to keep the test cases. Let’s call it SampleTests and it
extends TestRunner class. Following are the sample code snippets:
class SampleTests : TestRunner() {
@Test
fun TC001_testEnterPincode() {
SampleTestsHelper.enterPinCode(driver, “682030”)
}
@Test
fun TC002_testSearchFail() {
Assert.fail()
}
}
Step 5: Create a Kotlin class which should act as a helper class of test class. Let’s call it
SampleTestsHelper and define this SampleTestsHelper as object. So, Kotlin will create an instance
automatically when we invoke the methods of SampleTestsHelper. No need to create a separate instance to
invoke the methods of the helper class. Below are the complete code snippets:
object SampleTestsHelper {
/**
* This method used to enter pin code
*
* @author sanojs
* @since 01-09-2020
*/
fun enterPinCode(driver: WebDriver, valueToSearch: String) {
Appium Automation with Kotlin
© RapidValue Solutions 6
try {
driver.findElement(By.id(“in.dmart:id/et_activity_pincode_pincode”)).sendKeys(pincod)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Step 6: Create a Kotlin class to keep the logic to generate an Automation test execution report in HTML
format. Let’s say the class name as AutomationReport. Here, we are using extentreports library to
generate an HTML report. Also, we are using ITestListener interface to control the executions and results.
Below are the complete code snippets of the AutomationReport class,
class AutomationReport : ITestListener {
public lateinit var sparkReporter: ExtentSparkReporter
public lateinit var extentReport: ExtentReports
public lateinit var extentTest: ExtentTest
/**
* This override method used to create HTML template for the test report
*
* @author sanojs
* @since 01-09-2020
*/
override fun onStart(testContext: ITestContext) {
try {
sparkReporter = ExtentSparkReporter(System.getProperty(“user.dir”) + “/AutomationReport/”)
sparkReporter.config().setDocumentTitle(“Appium Kotlin Automation”)
sparkReporter.config().setReportName(“Automation Execution Report”)
sparkReporter.config().setTheme(com.aventstack.extentreports.reporter.configuration.Theme.DARK)
extentReport = ExtentReports()
extentReport.attachReporter(sparkReporter)
extentReport.setSystemInfo(“Application Name”, “Kotlin Appium Demo”)
extentReport.setSystemInfo(“Platform”, System.getProperty(“os.name”))
extentReport.setSystemInfo(“Environment”, “QA”)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* This override method used to collect current test case name add to the report
*
* @author sanojs
* @since 01-09-2020
*/
override fun onTestStart(result: ITestResult) {
var testName: String = result.getMethod().getMethodName()
extentTest = extentReport.createTest(testName)
Appium Automation with Kotlin
© RapidValue Solutions 7
}
/**
* This override method used to add pass status to the report
*
* @author sanojs
* @since 01-09-2020
*/
override fun onTestSuccess(result: ITestResult) {
var testName: String = result.getMethod().getMethodName()
try {
extentTest.log(
Status.PASS,
MarkupHelper.createLabel(testName + ” Test Case PASSED”, ExtentColor.GREEN)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* This override method used to add fail status to the report
*
* @author sanojs
* @since 01-09-2020
*/
override fun onTestFailure(result: ITestResult) {
var driver: WebDriver
var currentClass = result.getInstance()
var testName: String = result.getMethod().getMethodName()
try {
driver = (currentClass as AutomationBase).getDriverInstance()
var screenshotPath = Utilities().screenshotCapture(driver, result.getName())
extentTest.log(
Status.FAIL,
MarkupHelper.createLabel(testName + ” Test Case FAILED”, ExtentColor.RED)
)
extentTest.log(
Status.FAIL,
MarkupHelper.createLabel(“Reason for Failure: ” + result.getThrowable().toString(),
ExtentColor.RED)
)
extentTest.addScreenCaptureFromPath(screenshotPath)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* This override method used to add skip status to the report
*
* @author sanojs
* @since 01-09-2020
*/
Appium Automation with Kotlin
© RapidValue Solutions 8
override fun onTestSkipped(result: ITestResult) {
var testName: String = result.getMethod().getMethodName()
try {
extentTest.log(
Status.SKIP,
MarkupHelper.createLabel(testName + ” Test Case SKIPPED”, ExtentColor.ORANGE)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* This override method used to store HTML report to the specified path and flush extent report
instance
*
* @author sanojs
* @since 01-09-2020
*/
override fun onFinish(testContext: ITestContext) {
try {
extentReport.flush()
val dateFormat = SimpleDateFormat(“dd-MMM-yyyy_HH-mm-ss”)
val date = Date()
val filePathdate: String = dateFormat.format(date).toString()
var actualReportPath: String = System.getProperty(“user.dir”) + “/AutomationReport/” +
“index.html”
File(actualReportPath).renameTo(
File(
System.getProperty(“user.dir”) + “/AutomationReport/”
+ “Automation_Report_” + filePathdate + “.html”
)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Step 7: Create another class called Utilities to keep common utility functions required for automation. Here,
we just added one utility to capture the screenshot. Below is the code snippet to capture the screenshot,
fun screenshotCapture(driver: WebDriver, fileName: String): String {
var destination: String = “”
try {
var scrFile = (driver as TakesScreenshot).getScreenshotAs(OutputType.FILE)
var dateFormat = SimpleDateFormat(“yyyyMMddHHmmss”)
var cal = Calendar.getInstance()
var path = File(“Failure_Screenshots”).getAbsolutePath()
destination = path + “/” + fileName + dateFormat.format(cal.getTime()) + “.png”
scrFile.copyTo(File(destination))
Appium Automation with Kotlin
© RapidValue Solutions 9
} catch (e: Exception) {
e.printStackTrace()
}
return destination
}
Step 8: Add a testng.xml file into the project structure and map your test classes into the testng.xml to run
the test cases. Once the execution is complete, the HTML report will get generated inside
the AutomationReport folder in the project structure.
Below is the overall project structure of Appium with Kotlin:
NOTE:
 Kotlin Runtime Library will automatically get added to the build path of the project when you create
a Kotlin class under any package.
 Kotlin class extension is .kt
 The semicolon is not mandatory to end the statements in the class.
 While inheriting a class from a parent class you have to declare the parent class as open, using
an open keyword or you can declare the parent class as abstract using abstract. You can’t inherit a
singleton class. So avoid extending the class which is declared as object in Kotlin.
 If you declare a class with an object keyword then no need to create an instance. Kotlin will create
an instance to access the methods or variables of that class.
Appium Automation with Kotlin
© RapidValue Solutions 10
Conclusion
Kotlin is a general-purpose, open-source, statically typed programming language that combines object-
oriented and functional programming features. So, Kotlin is a strong and powerful language that helps the
automation engineers to write their automation script for Appium. This article aims to help the Appium
automation engineers to upskill and write their scripting in a different language such as Kotlin.
By,
Sanoj S, Test Architect, RapidValue
Appium Automation with Kotlin
© RapidValue Solutions 11
About RapidValue
RapidValue is a global leader in digital product engineering solutions including mobility, omni-channel, IoT, AI, RPA
and cloud to enterprises worldwide. RapidValue offers its digital services to the world’s top brands, Fortune 1000
companies and innovative emerging start-ups. With offices in the United States, the United Kingdom, Germany and
India and operations spread across the Middle-East, Europe and Canada, RapidValue delivers enterprise services
and solutions across various industry verticals.
Disclaimer:
This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used, circulated, quoted,
or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are hereby notified that the use,
circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful.
www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com
+1 877.643.1850 contactus@rapidvaluesolutions.com

More Related Content

What's hot

Hands on ansible
Hands on ansibleHands on ansible
Hands on ansible
sumit23kumar
 
Red Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform OverviewRed Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform Overview
James Falkner
 
Understanding container security
Understanding container securityUnderstanding container security
Understanding container security
John Kinsella
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
Linaro
 
Docker multi-stage build
Docker multi-stage buildDocker multi-stage build
Docker multi-stage build
Alexei Ledenev
 
Docker compose
Docker composeDocker compose
Docker compose
Felipe Ruhland
 
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapRHadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
Douglas Bernardini
 
SplunkLive 2011 Beginners Session
SplunkLive 2011 Beginners SessionSplunkLive 2011 Beginners Session
SplunkLive 2011 Beginners SessionSplunk
 
Monitoring infrastructure with prometheus
Monitoring infrastructure with prometheusMonitoring infrastructure with prometheus
Monitoring infrastructure with prometheus
Shahnawaz Saifi
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm Mode
Ajeet Singh Raina
 
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
Camel Desing Patterns Learned Through Blood, Sweat, and TearsCamel Desing Patterns Learned Through Blood, Sweat, and Tears
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
Bilgin Ibryam
 
Introduction openstack horizon
Introduction openstack horizonIntroduction openstack horizon
Introduction openstack horizon
Jim Yeh
 
OpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
OpenStack 개요 및 활용 사례 @ Community Open Camp with MicrosoftOpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
OpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
Ian Choi
 
Effectively using Open Source with conda
Effectively using Open Source with condaEffectively using Open Source with conda
Effectively using Open Source with conda
Travis Oliphant
 
Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...
jeetendra mandal
 
IBM Cloud Object Storage System (powered by Cleversafe) and its Applications
IBM Cloud Object Storage System (powered by Cleversafe) and its ApplicationsIBM Cloud Object Storage System (powered by Cleversafe) and its Applications
IBM Cloud Object Storage System (powered by Cleversafe) and its Applications
Tony Pearson
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
Taeung Song
 
Giới thiệu docker và ứng dụng trong ci-cd
Giới thiệu docker và ứng dụng trong ci-cdGiới thiệu docker và ứng dụng trong ci-cd
Giới thiệu docker và ứng dụng trong ci-cd
GMO-Z.com Vietnam Lab Center
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
Thomas Graf
 
Log analysis with elastic stack
Log analysis with elastic stackLog analysis with elastic stack
Log analysis with elastic stack
Bangladesh Network Operators Group
 

What's hot (20)

Hands on ansible
Hands on ansibleHands on ansible
Hands on ansible
 
Red Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform OverviewRed Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform Overview
 
Understanding container security
Understanding container securityUnderstanding container security
Understanding container security
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Docker multi-stage build
Docker multi-stage buildDocker multi-stage build
Docker multi-stage build
 
Docker compose
Docker composeDocker compose
Docker compose
 
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapRHadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
Hadoop benchmark: Evaluating Cloudera, Hortonworks, and MapR
 
SplunkLive 2011 Beginners Session
SplunkLive 2011 Beginners SessionSplunkLive 2011 Beginners Session
SplunkLive 2011 Beginners Session
 
Monitoring infrastructure with prometheus
Monitoring infrastructure with prometheusMonitoring infrastructure with prometheus
Monitoring infrastructure with prometheus
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm Mode
 
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
Camel Desing Patterns Learned Through Blood, Sweat, and TearsCamel Desing Patterns Learned Through Blood, Sweat, and Tears
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
 
Introduction openstack horizon
Introduction openstack horizonIntroduction openstack horizon
Introduction openstack horizon
 
OpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
OpenStack 개요 및 활용 사례 @ Community Open Camp with MicrosoftOpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
OpenStack 개요 및 활용 사례 @ Community Open Camp with Microsoft
 
Effectively using Open Source with conda
Effectively using Open Source with condaEffectively using Open Source with conda
Effectively using Open Source with conda
 
Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...
 
IBM Cloud Object Storage System (powered by Cleversafe) and its Applications
IBM Cloud Object Storage System (powered by Cleversafe) and its ApplicationsIBM Cloud Object Storage System (powered by Cleversafe) and its Applications
IBM Cloud Object Storage System (powered by Cleversafe) and its Applications
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
Giới thiệu docker và ứng dụng trong ci-cd
Giới thiệu docker và ứng dụng trong ci-cdGiới thiệu docker và ứng dụng trong ci-cd
Giới thiệu docker và ứng dụng trong ci-cd
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
 
Log analysis with elastic stack
Log analysis with elastic stackLog analysis with elastic stack
Log analysis with elastic stack
 

Similar to Appium Automation with Kotlin

Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
RapidValue
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
AEM HUB
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
Justin Edelson
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeOSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
NETWAYS
 
J Unit
J UnitJ Unit
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
shadabgilani
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
David Barreto
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
David Barreto
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
RapidValue
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
Alteryx SDK
Alteryx SDKAlteryx SDK
Alteryx SDK
James Dunkerley
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
TechWell
 
JUnit 5
JUnit 5JUnit 5
Testing in android
Testing in androidTesting in android
Testing in android
jtrindade
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
VMware Tanzu
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
Dmitriy Sobko
 

Similar to Appium Automation with Kotlin (20)

Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeOSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
 
J Unit
J UnitJ Unit
J Unit
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Alteryx SDK
Alteryx SDKAlteryx SDK
Alteryx SDK
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Testing in android
Testing in androidTesting in android
Testing in android
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 

More from RapidValue

How to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-SpaHow to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-Spa
RapidValue
 
Play with Jenkins Pipeline
Play with Jenkins PipelinePlay with Jenkins Pipeline
Play with Jenkins Pipeline
RapidValue
 
Accessibility Testing using Axe
Accessibility Testing using AxeAccessibility Testing using Axe
Accessibility Testing using Axe
RapidValue
 
Automation in Digital Cloud Labs
Automation in Digital Cloud LabsAutomation in Digital Cloud Labs
Automation in Digital Cloud Labs
RapidValue
 
Microservices Architecture - Top Trends & Key Business Benefits
Microservices Architecture -  Top Trends & Key Business BenefitsMicroservices Architecture -  Top Trends & Key Business Benefits
Microservices Architecture - Top Trends & Key Business Benefits
RapidValue
 
Uploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIUploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADI
RapidValue
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
RapidValue
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
RapidValue
 
Real-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelReal-time Automation Result in Slack Channel
Real-time Automation Result in Slack Channel
RapidValue
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
RapidValue
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
Video Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsVideo Recording of Selenium Automation Flows
Video Recording of Selenium Automation Flows
RapidValue
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
RapidValue
 
The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QA
RapidValue
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
RapidValue
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon Studio
RapidValue
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using Valgrind
RapidValue
 
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueDevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
RapidValue
 
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
RapidValue
 
MS Azure: Soaring High in the Cloud - An Infographic by RapidValue
MS Azure: Soaring High in the Cloud - An Infographic by RapidValueMS Azure: Soaring High in the Cloud - An Infographic by RapidValue
MS Azure: Soaring High in the Cloud - An Infographic by RapidValue
RapidValue
 

More from RapidValue (20)

How to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-SpaHow to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-Spa
 
Play with Jenkins Pipeline
Play with Jenkins PipelinePlay with Jenkins Pipeline
Play with Jenkins Pipeline
 
Accessibility Testing using Axe
Accessibility Testing using AxeAccessibility Testing using Axe
Accessibility Testing using Axe
 
Automation in Digital Cloud Labs
Automation in Digital Cloud LabsAutomation in Digital Cloud Labs
Automation in Digital Cloud Labs
 
Microservices Architecture - Top Trends & Key Business Benefits
Microservices Architecture -  Top Trends & Key Business BenefitsMicroservices Architecture -  Top Trends & Key Business Benefits
Microservices Architecture - Top Trends & Key Business Benefits
 
Uploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIUploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADI
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
 
Real-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelReal-time Automation Result in Slack Channel
Real-time Automation Result in Slack Channel
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Video Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsVideo Recording of Selenium Automation Flows
Video Recording of Selenium Automation Flows
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
 
The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QA
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon Studio
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using Valgrind
 
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueDevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
 
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
 
MS Azure: Soaring High in the Cloud - An Infographic by RapidValue
MS Azure: Soaring High in the Cloud - An Infographic by RapidValueMS Azure: Soaring High in the Cloud - An Infographic by RapidValue
MS Azure: Soaring High in the Cloud - An Infographic by RapidValue
 

Recently uploaded

Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

Appium Automation with Kotlin

  • 2. Appium Automation with Kotlin © RapidValue Solutions 2 Appium Automation with Kotlin Pre-requisites: Following are the pre-requisites to start Appium with Kotlin:  Install Java SDK 8 and above.  Install Eclipse or IntelliJ IDEA IDEs.  Install the Kotlin plugin in IDEs. Here I am using Eclipse as IDE and Kotlin plugin for Eclipse downloaded from https://marketplace.eclipse.org/content/kotlin-plugin-eclipse  The latest version of following maven dependencies: o testing o selenium-java o selenium-server o java-client o kotlin-test o kotlin-stdlib-jdk8 o extentreports Step-by-step Procedure Step 1: Create a maven project and add the above dependencies in pom.xml of the project. Step 2: Create a Kotlin class to keep the logic to initiate the driver and start the Appium server. Let’s say the class name is AutomationBase. We are defining this class as an abstract class. So, it is easy to extend by other classes. We have implemented startApplication, startAppiumServer, getPort, getNodePath, getJSPath, getDriverInstance and setDriverInstance methods in the AutomationBase class. Below are the sample code snippets: fun startApplication() { try { var service: AppiumDriverLocalService = startAppiumServer() var capabilities = DesiredCapabilities() capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “One Plus”) capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”) capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “10”) capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2) capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true) capabilities.setCapability(“newCommandTimeout”, 180) capabilities.setCapability(“udid”, “e6916f40”) capabilities.setCapability(MobileCapabilityType.APP, “YOUR_APP_PATH”) capabilities.setCapability(MobileCapabilityType.NO_RESET, true) if(!service.toString().isEmpty()){ driver = AndroidDriver(service.getUrl(), capabilities) } } catch (e: Exception) {
  • 3. Appium Automation with Kotlin © RapidValue Solutions 3 e.printStackTrace() } } private fun startAppiumServer(): AppiumDriverLocalService { var IP_ADDRESS: String = “127.0.0.1” var bootStrapPort: String var chromePort: String var port: Int if (!File(System.getProperty(“user.dir”) + “LogsAppium_logs”).exists()) { (File(System.getProperty(“user.dir”) + “Logs”)).mkdir() (File(System.getProperty(“user.dir”) + “LogsAppium_logs”)).mkdir() } port = getPort() bootStrapPort = Integer.toString(getPort()) chromePort = Integer.toString(getPort()) var service = AppiumDriverLocalService.buildService( AppiumServiceBuilder().withAppiumJS(File(getJSPath())) .usingDriverExecutable(File(getNodePath())).withIPAddress(IP_ADDRESS).usingPort(port) .withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER, bootStrapPort) .withArgument(AndroidServerFlag.CHROME_DRIVER_PORT, chromePort) .withLogFile(File(System.getProperty(“user.dir”) + “LogsAppium_logsappiumLogs.txt”))) service.start() if (service.isRunning()) { System.out.println(“Server is running…..” + service) } else { System.out.println(“Server startup failed…..”) System.exit(0) } return service } private fun getPort(): Int { var port: Int = 0 try { var socket = ServerSocket(0) socket.setReuseAddress(true) port = socket.getLocalPort() socket.close() } catch (e: Exception) { e.printStackTrace() } return port } private fun getNodePath(): String { var nodePath: String var p: Process var reader: BufferedReader var command: String
  • 4. Appium Automation with Kotlin © RapidValue Solutions 4 var operatingSystem: String = System.getProperty(“os.name”) if (operatingSystem.contains(“Win”)) { command = “where” + ” ” + “node” } else { command = “which ” + “node” } p = Runtime.getRuntime().exec(command) reader = BufferedReader(InputStreamReader(p.getInputStream())) nodePath = reader.readLine() p.waitFor() p.destroy() return nodePath } fun getJSPath(): String { var jsPaths: String lateinit var actualJSPath: String var command: String var operatingSystem: String = System.getProperty(“os.name”) if (operatingSystem.contains(“Win”)) { command = “where” + ” ” + “appium” var p: Process = Runtime.getRuntime().exec(command) var stdInput: BufferedReader = BufferedReader(InputStreamReader(p.getInputStream())) jsPaths = stdInput.readLine() actualJSPath = jsPaths.replace(“appium”, “node_modulesappiumbuildlibmain.js”) p.waitFor() p.destroy() } else { actualJSPath = “//usr//local//lib//node_modules//appium//build//lib//main.js” } return actualJSPath } fun getDriverInstance(): WebDriver { return this.driver } fun setDriverInstance(driver: WebDriver) { this.driver = driver } startApplication method helps to instantiate driver sessions based on the specified capabilities. startAppiumServer method helps to start the Appium server and also, create and write server logs to a text file. getPort method helps to create the dynamic network port that supports the startAppiumServer method. getNodePath method helps to get the node path and it supports the startAppiumServer method. getJSPath method helps to get the Appium main.js path and it supports the startAppiumServer method. Step 3: Create a TestRunner class and it extends AutomationBase class. This class holds TestNG annotations @Listeners, @BeforeClass, and @AfterSuite. Below are the complete code snippets:
  • 5. Appium Automation with Kotlin © RapidValue Solutions 5 @Listeners(AutomationReport::class) open class TestRunner : AutomationBase() { @BeforeClass fun setUp() { startApplication() } @AfterSuite fun tearDown() { Thread.sleep(3000) driver.quit() } } Step 4: Create a sample test class to keep the test cases. Let’s call it SampleTests and it extends TestRunner class. Following are the sample code snippets: class SampleTests : TestRunner() { @Test fun TC001_testEnterPincode() { SampleTestsHelper.enterPinCode(driver, “682030”) } @Test fun TC002_testSearchFail() { Assert.fail() } } Step 5: Create a Kotlin class which should act as a helper class of test class. Let’s call it SampleTestsHelper and define this SampleTestsHelper as object. So, Kotlin will create an instance automatically when we invoke the methods of SampleTestsHelper. No need to create a separate instance to invoke the methods of the helper class. Below are the complete code snippets: object SampleTestsHelper { /** * This method used to enter pin code * * @author sanojs * @since 01-09-2020 */ fun enterPinCode(driver: WebDriver, valueToSearch: String) {
  • 6. Appium Automation with Kotlin © RapidValue Solutions 6 try { driver.findElement(By.id(“in.dmart:id/et_activity_pincode_pincode”)).sendKeys(pincod) } catch (e: Exception) { e.printStackTrace() } } } Step 6: Create a Kotlin class to keep the logic to generate an Automation test execution report in HTML format. Let’s say the class name as AutomationReport. Here, we are using extentreports library to generate an HTML report. Also, we are using ITestListener interface to control the executions and results. Below are the complete code snippets of the AutomationReport class, class AutomationReport : ITestListener { public lateinit var sparkReporter: ExtentSparkReporter public lateinit var extentReport: ExtentReports public lateinit var extentTest: ExtentTest /** * This override method used to create HTML template for the test report * * @author sanojs * @since 01-09-2020 */ override fun onStart(testContext: ITestContext) { try { sparkReporter = ExtentSparkReporter(System.getProperty(“user.dir”) + “/AutomationReport/”) sparkReporter.config().setDocumentTitle(“Appium Kotlin Automation”) sparkReporter.config().setReportName(“Automation Execution Report”) sparkReporter.config().setTheme(com.aventstack.extentreports.reporter.configuration.Theme.DARK) extentReport = ExtentReports() extentReport.attachReporter(sparkReporter) extentReport.setSystemInfo(“Application Name”, “Kotlin Appium Demo”) extentReport.setSystemInfo(“Platform”, System.getProperty(“os.name”)) extentReport.setSystemInfo(“Environment”, “QA”) } catch (e: Exception) { e.printStackTrace() } } /** * This override method used to collect current test case name add to the report * * @author sanojs * @since 01-09-2020 */ override fun onTestStart(result: ITestResult) { var testName: String = result.getMethod().getMethodName() extentTest = extentReport.createTest(testName)
  • 7. Appium Automation with Kotlin © RapidValue Solutions 7 } /** * This override method used to add pass status to the report * * @author sanojs * @since 01-09-2020 */ override fun onTestSuccess(result: ITestResult) { var testName: String = result.getMethod().getMethodName() try { extentTest.log( Status.PASS, MarkupHelper.createLabel(testName + ” Test Case PASSED”, ExtentColor.GREEN) ) } catch (e: Exception) { e.printStackTrace() } } /** * This override method used to add fail status to the report * * @author sanojs * @since 01-09-2020 */ override fun onTestFailure(result: ITestResult) { var driver: WebDriver var currentClass = result.getInstance() var testName: String = result.getMethod().getMethodName() try { driver = (currentClass as AutomationBase).getDriverInstance() var screenshotPath = Utilities().screenshotCapture(driver, result.getName()) extentTest.log( Status.FAIL, MarkupHelper.createLabel(testName + ” Test Case FAILED”, ExtentColor.RED) ) extentTest.log( Status.FAIL, MarkupHelper.createLabel(“Reason for Failure: ” + result.getThrowable().toString(), ExtentColor.RED) ) extentTest.addScreenCaptureFromPath(screenshotPath) } catch (e: Exception) { e.printStackTrace() } } /** * This override method used to add skip status to the report * * @author sanojs * @since 01-09-2020 */
  • 8. Appium Automation with Kotlin © RapidValue Solutions 8 override fun onTestSkipped(result: ITestResult) { var testName: String = result.getMethod().getMethodName() try { extentTest.log( Status.SKIP, MarkupHelper.createLabel(testName + ” Test Case SKIPPED”, ExtentColor.ORANGE) ) } catch (e: Exception) { e.printStackTrace() } } /** * This override method used to store HTML report to the specified path and flush extent report instance * * @author sanojs * @since 01-09-2020 */ override fun onFinish(testContext: ITestContext) { try { extentReport.flush() val dateFormat = SimpleDateFormat(“dd-MMM-yyyy_HH-mm-ss”) val date = Date() val filePathdate: String = dateFormat.format(date).toString() var actualReportPath: String = System.getProperty(“user.dir”) + “/AutomationReport/” + “index.html” File(actualReportPath).renameTo( File( System.getProperty(“user.dir”) + “/AutomationReport/” + “Automation_Report_” + filePathdate + “.html” ) ) } catch (e: Exception) { e.printStackTrace() } } } Step 7: Create another class called Utilities to keep common utility functions required for automation. Here, we just added one utility to capture the screenshot. Below is the code snippet to capture the screenshot, fun screenshotCapture(driver: WebDriver, fileName: String): String { var destination: String = “” try { var scrFile = (driver as TakesScreenshot).getScreenshotAs(OutputType.FILE) var dateFormat = SimpleDateFormat(“yyyyMMddHHmmss”) var cal = Calendar.getInstance() var path = File(“Failure_Screenshots”).getAbsolutePath() destination = path + “/” + fileName + dateFormat.format(cal.getTime()) + “.png” scrFile.copyTo(File(destination))
  • 9. Appium Automation with Kotlin © RapidValue Solutions 9 } catch (e: Exception) { e.printStackTrace() } return destination } Step 8: Add a testng.xml file into the project structure and map your test classes into the testng.xml to run the test cases. Once the execution is complete, the HTML report will get generated inside the AutomationReport folder in the project structure. Below is the overall project structure of Appium with Kotlin: NOTE:  Kotlin Runtime Library will automatically get added to the build path of the project when you create a Kotlin class under any package.  Kotlin class extension is .kt  The semicolon is not mandatory to end the statements in the class.  While inheriting a class from a parent class you have to declare the parent class as open, using an open keyword or you can declare the parent class as abstract using abstract. You can’t inherit a singleton class. So avoid extending the class which is declared as object in Kotlin.  If you declare a class with an object keyword then no need to create an instance. Kotlin will create an instance to access the methods or variables of that class.
  • 10. Appium Automation with Kotlin © RapidValue Solutions 10 Conclusion Kotlin is a general-purpose, open-source, statically typed programming language that combines object- oriented and functional programming features. So, Kotlin is a strong and powerful language that helps the automation engineers to write their automation script for Appium. This article aims to help the Appium automation engineers to upskill and write their scripting in a different language such as Kotlin. By, Sanoj S, Test Architect, RapidValue
  • 11. Appium Automation with Kotlin © RapidValue Solutions 11 About RapidValue RapidValue is a global leader in digital product engineering solutions including mobility, omni-channel, IoT, AI, RPA and cloud to enterprises worldwide. RapidValue offers its digital services to the world’s top brands, Fortune 1000 companies and innovative emerging start-ups. With offices in the United States, the United Kingdom, Germany and India and operations spread across the Middle-East, Europe and Canada, RapidValue delivers enterprise services and solutions across various industry verticals. Disclaimer: This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used, circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful. www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com +1 877.643.1850 contactus@rapidvaluesolutions.com