Kotlin Selenium

Selenium :

Selenium is an open-source and a portable automated software testing tool for testing web applications. It has capabilities to work across different browsers and operating systems.

Selenium is set of tools that helps testers to automate web-based applications more efficiently, Testing done using Selenium tool is usually referred as Selenium Testing.

  • Test scripts can be written in any of these programming languages: Java,Python, C#, PHP, Ruby, Perl & .Net and Kotlin obviously
  • Selenium tests can run on these OS: Windows, Mac or Linux
  • Tests can be carried out using any browser: Mozilla Firefox, Internet Explorer, Google Chrome, Safari or Opera
  • It can be integrated with unit testing frameworks like such as TestNG & JUnit for managing test cases and generating reports
  • It can be integrated with Maven, Jenkins & Docker to achieve Continuous Testing

Kotlin :

Kotlin is a open source, statically typed, general purpose programming language that runs on JVM. It is introduced by JetBrains, the official designer of the most intelligent Java IDE, named IntelliJ IDEA.

It combines object oriented programming and functional features into unique platform, which means it has capabilities work like java as well as javascript.

Google announced that Kotlin is official language for android development, Kotlin support everything like java not only Android development.

Here comes the Boom, Why did google announced kotlin as official rather than its own language "GO Lang"?

Google announced the kotlin as official language of android because of the kotlin features.

Kotlin Features :

  • Handling Nullability in great ways with different operator, It is very hard to get NullPointerException because kotlin compiler complains about it.
  • Nullable Data types for all the data types
  • Kotlin Lambdas to reduce the code
  • Java interchangeability, You can mix java and kotlin in same file and same class
  • No More For loop with conditions
  • No checked exception in kotlin
  • Every thing is object literally

Kotlin Selenium Tutorial:

As I explained before you can mix and write the kotlin and java, so i thought to use the selenium jar available for java to automate with kotlin and selenium.

When we combine the features of selenium and kotlin it gets more power than any language used with selenium.

So this selenium kotlin tutorial covers all the topics required for automating web application step by step from beginner to expert level..

Install Selenium with Kotlin

Step by step installation of Selenium using kotlin language :

  • Select File->New->Project in Intellij
  • new-project-selenium-kotlin
  • Now select Kotlin/Jvm option and press Next button
  • kotlin-jvm-intellij-new-project
  • Provide Some Project and Location and Press Finish then click and This window option
  • name-project-location-selenium-kotlin
  • Now Right click on the src folder and select new and then Koltin/Koltin File
  • right-click-src-new-kotlin-file
  • Provide some name to the kotlin file
  • first-kotlin-selenium-file
  • Navigate to Selenium HQ and download the Jar file under Selenium server section
  • download-selenium-kotlin
  • If you want to move the jar file, you can move it to the directory you want
  • Open IntelliJ IDE and Go to File -> Project Structure
  • intellij-kotlin-selenium
  • Click on the + button on the right and select JARs or directories
  • integrate-selenium-kotlin-with-intellij
  • Now navigate to the folder where you have stored the selenium Jar and select the Jar and click Okay.
  • select-selenium-kotlin-jar-intellij
  • Now create a Main block in you kotlin file and type Webdriver, if you are able to see suggestion from selenium the you have installed selenium success fully, Please do mind the case.
  • integrated-selenium-kotlin-jar-intellij
  • Below code will not work if you execute, but it should not show any error in your IDE.
    import org.openqa.selenium.firefox.FirefoxDriver
    fun main(args: Array) {
    	// Set geckodriver path
    	val driver = FirefoxDriver()

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

You can also share knowledge by Adding a topic here

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions