Hi. How would I write a cucumber test for my compo...
# compose-desktop
l
Hi. How would I write a cucumber test for my compose-desktop application? The only examples of any testing I've seen so far are unit tests using createComposeRule().
a
What is a cucumber test?
l
It's a framework for black-box (BDD) testing your application. https://cucumber.io/ Each application feature you want to test is described by an executable "scenario", e.g. here are two scenarios
Copy code
Feature: Show a list of cases

  Scenario: Should show the list of cases that have been stored by the server
    Given a list of cases with the following names is stored on the server:
      | Case1 |
      | Case2 |
    And I start the client application
    Then I should see the following cases in the case list:
      | Case1 |
      | Case2 |
    And stop the client application

  Scenario: Should be able to select the last in a long list of cases
    Given a list of 1000 cases is stored on the server
    And I start the client application
    When I select case Case_1000
    Then I should see the case Case_1000 as the current case
    And stop the client application
A scenario consists of steps, and each step is implemented (in my application) using kotlin.
a
How does cucumber control the tested app, e.g. press a button?
l
If the UI is implemented as a web app, then the steps are defined using Selenium or Playwright. If the UI is a thick client app, say in Swing, then the steps are defined using java Robot directly, or what we use is the assertj-swing framework https://joel-costigliola.github.io/assertj/assertj-swing.html which put button/key presses etc on the EDT and similarly finds and reads the state of components using the EDT. I'm looking for an equivalent form of testing for compose-desktop.
a
Robot should work with Compose.
But you won’t be able to find Swing/AWT components
l
Robot can perform mouse clicks and key presses on a composable, but how can you get the screen location of the composable button in order to click it, or the position of a TextField so you can click it and make it focusable for then entering text?
a
You can use the semantics tree to find nodes in the UI. https://developer.android.com/jetpack/compose/semantics
l
Thanks, but is the only way to get access to the semantics true by using composeTestRule, i.e. in a JUnit test?
a
I don’t think we’re currently exposing it outside of tests.
l
I guess I'm looking for a way to use the node matchers and assertions of composeTestRule, but outside the JUnit framework. In particular, in a higher-level test framework like cucumber. I'd also like to be able to find the semantic tree if the composables are in a ComposePanel, whether using composeTestRule/Junit or not.
a
Take a look at runComposeUiTest
l
Will do, thanks for your time and help.