![]() the `firstTest` variable was manually changed from type Boolean? to Boolean, in order to compile. Converted test "Edition077_Tuning_WDA_Startup" from Java to Kotlin just by copy-pasting. Import io.appium.java_client.MobileElement It can be done easily and one file at a time.īelow is the full Kotlin test file, which can also be found in our repository of examples. As time moves on, we will see if Kotlin adoption grows, but hopefully this will allay your fears about migrating. Our test was pretty simple, but I hope you consider learning Kotlin and experiment with converting your code. The Java Appium client worked from the Kotlin code with no problem. Since the code sets a value for isFirst at the declaration site, we can convert it to the non-nullable type Boolean, and our code now compiles.Īnd tests pass! Also read: How to Improve Customer Experience in the Telecom Industry? Our copy-pasted code fails because we are attempting to use the not operator ! on a variable of type Boolean? and the compiler is complaining that the Boolean? could be null, and it isn't able to calculate the results of !null. ![]() This concept has existed for a long while, and is able to prevent many null reference exceptions and other issues. There's a lot more to this concept, including some interesting syntax and shortcuts for null-checking, and there are plenty of articles explaining it in detail online, as well as the Kotlin documentation. If you define a method which takes a String parameter, you never need to check if it is null before you use it, because it's guaranteed to not be null. So a String variable can never be null, while a String? variable can be null or a String. In order to have a null value, the variable type must be set to the "nullable" version of the type, indicated by following the class name with a ?. Kotlin uses a concept called "nullable types", where a variable of any class cannot be null. This is related to the most obvious difference between Java and Kotlin at first glance, and also my favorite feature so far. The compiler complains about our use of firstTest. Kotlin is a different language after all. The firstTest static variable from our original class has been converted to a " companion object" which is how Kotlin implements static class members. We picked a good example that brought up a case that involves some manual intervention. The test file won't actually compile though. Our project was using gradle version 4.0, so I had to update first, by running the following code:Īnd 95% of the work is done for us, leaving us with perfectly readable code. The only difficulty I ran into is that the IDE's Kotlin plugins only work with gradle version 4.1 and up. I'm using IntelliJ IDEA, and our project was already set up to use Gradle. In my specific case, I started with our code sample from two weeks ago. In this article, we'll take a simple Appium Java test, and convert it to Kotlin in just a few minutes! Read: Capturing Network Traffic in Java with Appium ![]() This allows for a gradual transition, rather than the risks of a complete rewrite. A Java project can have some code files in Kotlin, a Kotlin program can import Java libraries, and with a little extra work, Java programs can import Kotlin libraries. What many readers may not know, is that Kotlin code can be easily integrated into a Java project. Kotlin has many features which clean up some of the longstanding issues with Java, and also just gives a fresh start, without needing to support legacy decisions and APIs. Test your mobile apps and browsers on real Android devices. ![]() It is the officially preferred language for Android app development, and a friend of mine is even rewriting his team's backend API in Kotlin. The compiled code runs on the JVM, it is supported by Java IDEs, and its syntax is very similar to Java. Kotlin is a new programming language, which is many ways is the successor to Java.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |