1

I want to testing js project, written on kotlin js.
For example, test, which elements added after click on btn.
How can I do it?

Such as

@Test
fun myTest() {
  when{
     window.onLoad().await()
     window.getElementById("#myBtn").click()
  }
  then {
     window.hasElementById("#myElement")
  }
}

Headless browsers may be needed here? But can't find example with kotlin with it

4
  • Are you using an existing testing system? If so, you may want to say so in your question. If not, then you would need to do some research on testing systems and come back to us when you have an issue with your use of a testing system. Commented Aug 19, 2019 at 9:11
  • @paul I can use kotlin.test, for example. But I can't understand, how UI testing proceed on unit-testing level. How test framework build DOM, can we define scope of building DOM... And how to do it in Kotlin Commented Aug 19, 2019 at 9:29
  • I see. Do you use an existing framework? kotlin.test is independant of the framework used. Commented Aug 19, 2019 at 10:01
  • @PaulStenne not, I don't use any framework yet Commented Aug 19, 2019 at 11:03

1 Answer 1

1

The language the code is written in and the language integration and functional tests for this particular code are written in are two different beast and not necessarily those two languages are supposed to be the same. However usually it's still more convenient to use the same language for tests because it makes life in some aspects easier.

From what I see from the code you've provided the idea is to test a web application. There's a lot of options you have there but I will stop on two:

Selenium

Is the most known and one of the most mature test frameworks for QA. Selenium always had a support for tests written in Java. That said, it's actually pretty straightforward and easy task to write tests for Selenium in Kotlin. Here's an article that might help you if you decide to move in this direction.

It's important to understand though, that in this case in order to reuse code from Kotlin/JS you'll most likely will have to make it multi-platform (since Selenium Kotlin code would be a JVM code). However quite often it's very easy to separate code reusable by tests - most likely it would be resources, configs etc.

Puppeteer

Is one of few options we have for writing integration test for web applications in javascript. Well, to be strict, it's actually a test framework for testing code in Chrome. You can find a lot of examples of tests written in js for Puppetteer, if you'll choose to write in Kotlin you'll just have to introduce additional step for compiling tests written in Kotlin to javascript - exactly like you do when you right "regular" Kotlin/JS code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.