Skip to content

Commit

Permalink
2.5.0-alpha13 (#83)
Browse files Browse the repository at this point in the history
* Fix Compose recommended config

* add runDesktopUltronUiTest

* upd docs
  • Loading branch information
alex-tiurin authored Jul 30, 2024
1 parent 4db0a4e commit 07327cd
Show file tree
Hide file tree
Showing 47 changed files with 783 additions and 365 deletions.
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,35 @@ You don't need to learn any new classes or special syntax. All magic actions and
<img src="https://user-images.githubusercontent.com/12834123/252498170-61e5a440-c2b5-42ea-8bfb-91ee12248422.png#gh-dark-mode-only" width=600>
</p>

## [Documentation](https://open-tool.github.io/ultron/) | [Releases](https://github.com/open-tool/ultron/releases)
## [Documentation](https://open-tool.github.io/ultron/) | [Releases](https://github.com/open-tool/ultron/releases) | [Telegram](https://t.me/ultron_framework)

## What are the benefits of using the framework?

- Exceptional support for [**Compose**](https://github.com/open-tool/ultron/wiki/Compose)
- Out-of-the-box generation of [**Allure report**](https://github.com/open-tool/ultron/wiki/Allure)
- Page/Screen Object pattern support
- Exceptional simplification for [**Compose UI tests**](https://open-tool.github.io/ultron/docs/compose/index)
- Out-of-the-box generation of [**Allure report**](https://open-tool.github.io/ultron/docs/common/allure) (Now, for Android UI tests only)
- A straightforward and expressive syntax
- Ensured **Stability** for all actions and assertions
- Complete control over every action and assertion
- Incredible interaction with [**RecyclerView**](https://github.com/open-tool/ultron/wiki/RecyclerView) and [**Compose lists**](https://github.com/open-tool/ultron/wiki/Compose#ultron-compose-lazycolumnlazyrow).
- An **Architectural** approach to developing UI tests
- Incredible interaction with lists: [**RecyclerView**](./android/recyclerview.md) and [**Compose LazyList**](https://open-tool.github.io/ultron/docs/compose/lazylist).
- An **Architectural** approach to developing UI tests (search "Best practice")
- An incredible mechanism for setups and teardowns (You can even set up preconditions for a single test within a test class, without affecting the others)
- [The ability to effortlessly extend the framework with your own operations](https://github.com/open-tool/ultron/wiki/Ultron-Extension)
- [The ability to effortlessly extend the framework with your own operations](https://open-tool.github.io/ultron/docs/common/extension)
- Accelerated UI Automator operations
- Ability to monitor each stage of operation execution with [Listeners](https://github.com/open-tool/ultron/wiki/Listeners)
- [Custom operation assertions](https://github.com/open-tool/ultron/wiki/Custom-operation-assertions)
- Ability to monitor each stage of operation execution with [Listeners](https://open-tool.github.io/ultron/docs/common/listeners)
- [Custom operation assertions](https://open-tool.github.io/ultron/docs/common/customassertion)

***
### Wiki
The framework offers an excellent [wiki](https://github.com/open-tool/ultron/wiki) that addresses the majority of significant usage scenarios.
### Documentation
The framework offers an excellent [documentation](https://open-tool.github.io/ultron/docs/) that addresses the majority of significant usage scenarios.

### A few words about syntax

The standard syntax provided by Google is intricate and not intuitive. This is especially evident when dealing with RecyclerView interactions.
The standard syntax provided by Google is intricate and not intuitive. This is especially evident when dealing with **LazyList** and **RecyclerView** interactions.

Let's explore some examples:

#### 1. Simple compose operation (refer to the wiki [here](https://github.com/open-tool/ultron/wiki/Compose#ultron-compose))
#### 1. Simple compose operation (refer to the doc [here](https://open-tool.github.io/ultron/docs/compose/index))

_Compose framework_

Expand All @@ -56,7 +57,7 @@ hasTestTag("Continue").click()
hasText("Welcome").assertIsDisplayed()
```

#### 2. Compose list operation (refer to the wiki [here](https://github.com/open-tool/ultron/wiki/Compose#ultron-compose-lazycolumnlazyrow))
#### 2. Compose list operation (refer to the [doc](https://open-tool.github.io/ultron/docs/compose/lazylist))

_Compose framework_

Expand Down Expand Up @@ -89,9 +90,9 @@ _Ultron_
```kotlin
withId(R.id.send_button).isDisplayed().click()
```
This presents a cleaner approach. Ultron's operation names mirror Espresso's, while also providing additional operations.
This presents a cleaner approach. Ultron's operation names mirror Espresso's, while also providing additional operations.

Refer to the [wiki](https://github.com/open-tool/ultron/wiki/Espresso-operations) for further details.
Refer to the [doc](https://open-tool.github.io/ultron/docs/android/espress) for further details.

#### 4. Action on RecyclerView list item

Expand All @@ -115,9 +116,9 @@ withRecyclerView(R.id.recycler_friends)
.click()
```

Explore the [wiki](https://github.com/open-tool/ultron/wiki/RecyclerView) to unveil Ultron's magic with RecyclerView interactions.
Explore the [doc](https://open-tool.github.io/ultron/docs/android/espress) to unveil Ultron's magic with RecyclerView interactions.

#### 5. Espresso WebView operations
#### 5. Espresso WebView operations

_Espresso_

Expand All @@ -139,7 +140,7 @@ id("button1").webClick()
id("title").hasText(newTitle)
```

Refer to the [wiki](https://github.com/open-tool/ultron/wiki/WebView) for more details.
Refer to the [doc](https://open-tool.github.io/ultron/docs/android/webview) for more details.

#### 6. UI Automator operations

Expand All @@ -157,7 +158,7 @@ _Ultron_
```kotlin
byResId(R.id.button1).click()
```
Refer to the [wiki](https://github.com/open-tool/ultron/wiki/UI-Automator-operation)
Refer to the [doc](https://open-tool.github.io/ultron/docs/android/uiautomator)
***
### Acquiring the result of any operation as Boolean value

Expand Down Expand Up @@ -237,27 +238,27 @@ Refer to the full code sample [DemoEspressoTest.class](https://github.com/open-t

In essence, your project's architecture will look like this:

<img src="https://github.com/open-tool/ultron/assets/12834123/b0882d34-a18d-4f1f-959b-f75796d11036" width=700>
[acrchitecture](https://github.com/open-tool/ultron/assets/12834123/b0882d34-a18d-4f1f-959b-f75796d11036)

***
## Allure report

Ultron has built in support to generate artifacts for Allure reports. Just apply the recommended configuration and set testIntrumentationRunner.
Ultron has built in support to generate artifacts for Allure reports. Just apply the recommended configuration and set testIntrumentationRunner.

For the complete guide, refer to the [wiki](https://github.com/open-tool/ultron/wiki/Allure)
For the complete guide, refer to the [Allure description](https://open-tool.github.io/ultron/docs/common/allure)

```kotlin
@BeforeClass @JvmStatic
fun setConfig() {
UltronConfig.applyRecommended()
UltronAllureConfig.applyRecommended()
UltronComposeConfig.applyRecommended()
UltronComposeConfig.applyRecommended()
}
```
![allure](https://github.com/open-tool/ultron/assets/12834123/c05c813a-ece6-45e6-a04f-e1c92b82ffb1)

![allure compose](https://github.com/open-tool/ultron/assets/12834123/1f751f3d-fc58-4874-a850-acd9181bfb70)


## Add Ultron to your project

Gradle
Expand All @@ -272,8 +273,4 @@ dependencies {
androidTestImplementation 'com.atiurin:ultron-compose:<latest_version>'
}
```
Please, read [gradle dependencies management](https://github.com/open-tool/ultron/wiki/Gradle-Dependencies-Management) wiki page.

## AndroidX

It is required to use AndroidX libraries. You can get some problems with Android Support ones.
Please, read [gradle dependencies management](https://open-tool.github.io/ultron/docs/intro/dependencies) doc.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ plugins {
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.compose.compiler) apply false
id("io.github.gradle-nexus.publish-plugin").version("2.0.0-rc-1")
alias(libs.plugins.kotlinAndroid) apply false
}

nexusPublishing {
Expand Down
15 changes: 13 additions & 2 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ kotlin {
isStatic = true
}
}
js(IR)
js(IR){
browser()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs()
wasmJs(){
browser {
testTask(Action {
useKarma {
useChromeHeadless()
useConfigDirectory(project.projectDir.resolve("karma.config.d").resolve("wasm"))
}
})
}
}

sourceSets {
val desktopMain by getting
Expand Down
55 changes: 55 additions & 0 deletions composeApp/karma.config.d/wasm/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// see https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file
// This file provides karma.config.d configuration to run tests with k/wasm

const path = require("path");

config.browserConsoleLogOptions.level = "debug";

const basePath = config.basePath;
const projectPath = path.resolve(basePath, "..", "..", "..", "..");
const generatedAssetsPath = path.resolve(projectPath, "build", "karma-webpack-out")

const debug = message => console.log(`[karma-config] ${message}`);

debug(`karma basePath: ${basePath}`);
debug(`karma generatedAssetsPath: ${generatedAssetsPath}`);

config.proxies["/"] = path.resolve(basePath, "kotlin");

config.files = [
{pattern: path.resolve(generatedAssetsPath, "**/*"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.png"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.gif"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.ttf"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.txt"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.json"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.xml"), included: false, served: true, watched: false},
].concat(config.files);

function KarmaWebpackOutputFramework(config) {
// This controller is instantiated and set during the preprocessor phase.
const controller = config.__karmaWebpackController;

// only if webpack has instantiated its controller
if (!controller) {
console.warn(
"Webpack has not instantiated controller yet.\n" +
"Check if you have enabled webpack preprocessor and framework before this framework"
)
return
}

config.files.push({
pattern: `${controller.outputPath}/**/*`,
included: false,
served: true,
watched: false
})
}

const KarmaWebpackOutputPlugin = {
'framework:webpack-output': ['factory', KarmaWebpackOutputFramework],
};

config.plugins.push(KarmaWebpackOutputPlugin);
config.frameworks.push("webpack-output");
5 changes: 3 additions & 2 deletions composeApp/src/commonTest/kotlin/BaseInteractionTest.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
Expand All @@ -11,9 +12,9 @@ import com.atiurin.ultron.core.compose.config.UltronComposeConfig
import com.atiurin.ultron.core.compose.nodeinteraction.click
import com.atiurin.ultron.core.compose.runUltronUiTest
import com.atiurin.ultron.extensions.assertIsDisplayed
import com.atiurin.ultron.extensions.assertTextContains
import com.atiurin.ultron.extensions.isSuccess
import com.atiurin.ultron.extensions.withAssertion
import com.atiurin.ultron.extensions.withTimeout
import com.atiurin.ultron.extensions.withUseUnmergedTree
import kotlin.test.AfterTest
import kotlin.test.Test
Expand Down Expand Up @@ -47,7 +48,7 @@ class BaseInteractionTest {
}
UltronComposeConfig.params.useUnmergedTree = true
assertFalse("Ultron operation success should be false") {
hasTestTag(testTag).isSuccess { assertTextContains("Text1") }
hasTestTag(testTag).isSuccess { withTimeout(1000).assertTextContains("Text1") }
}
assertTrue ("Ultron operation success should be true") {
hasTestTag(testTag).withUseUnmergedTree(false).isSuccess { assertTextContains("Text1") }
Expand Down
18 changes: 13 additions & 5 deletions composeApp/src/commonTest/kotlin/ExampleTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import androidx.compose.material.*
import androidx.compose.runtime.*

import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.*
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import kotlin.test.Test

class DesktopExampleTest {

class ExampleTest {
@OptIn(ExperimentalTestApi::class)
@Test
fun myTest() = runComposeUiTest {
Expand Down
35 changes: 21 additions & 14 deletions composeApp/src/desktopTest/kotlin/DesktopSampleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.*
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.junit4.createComposeRule
import org.junit.Rule
import com.atiurin.ultron.core.compose.runDesktopUltronUiTest
import com.atiurin.ultron.extensions.assertTextEquals
import com.atiurin.ultron.extensions.click
import com.atiurin.ultron.page.Page
import org.junit.Test

class DesktopSampleTest {
@get:Rule
val rule = createComposeRule()

@OptIn(ExperimentalTestApi::class)
@Test
fun myTest(){
// Declares a mock UI to demonstrate API calls
//
// Replace with your own declarations to test the code in your project
rule.setContent {
fun myTest() = runDesktopUltronUiTest {
setContent {
var text by remember { mutableStateOf("Hello") }

Text(
Expand All @@ -31,9 +28,19 @@ class DesktopSampleTest {
}
}

// Tests the declared UI with assertions and actions of the JUnit-based testing API
rule.onNodeWithTag("text").assertTextEquals("Hello")
rule.onNodeWithTag("button").performClick()
rule.onNodeWithTag("text").assertTextEquals("Compose")
SamplePage {
someStep()
}
}
}

object SamplePage : Page<SamplePage>() {
private val text = hasTestTag("text")
private val button = hasTestTag("button")

fun someStep(){
text.assertTextEquals("Hello")
button.click()
text.assertTextEquals("Compose")
}
}
51 changes: 51 additions & 0 deletions composeApp/src/iosTest/kotlin/IOSSampleTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.hasTestTag
import com.atiurin.ultron.core.compose.runUltronUiTest
import com.atiurin.ultron.extensions.assertTextEquals
import com.atiurin.ultron.extensions.click
import com.atiurin.ultron.page.Page
import kotlin.test.Test

class IOSSampleTest {
@OptIn(ExperimentalTestApi::class)
@Test
fun sampleTest() = runUltronUiTest {
setContent {
var text by remember { mutableStateOf("Hello") }

Text(
text = text,
modifier = Modifier.testTag("text")
)
Button(
onClick = { text = "Compose" },
modifier = Modifier.testTag("button")
) {
Text("Click me")
}
}

SamplePage {
someStep()
}
}
}

object SamplePage : Page<SamplePage>() {
private val text = hasTestTag("text")
private val button = hasTestTag("button")

fun someStep(){
text.assertTextEquals("Hello")
button.click()
text.assertTextEquals("Compose")
}
}
Loading

0 comments on commit 07327cd

Please sign in to comment.