Skip to content

Commit

Permalink
upd docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tiurin committed Jul 30, 2024
1 parent 7b3b09e commit 04e8ffa
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 95 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.
4 changes: 2 additions & 2 deletions composeApp/src/commonTest/kotlin/BaseInteractionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,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 @@ -48,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
16 changes: 12 additions & 4 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 ExampleTest {

@OptIn(ExperimentalTestApi::class)
@Test
fun myTest() = runComposeUiTest {
Expand Down
176 changes: 176 additions & 0 deletions docs/docs/android/testconditions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
sidebar_position: 6
---

# Test Conditions Management

It is a feature that includes 3 parts

- RuleSequence
- SetUpRule & TearDownRule
- @SetUp @TearDown annotations

RuleSequence + SetUps & TearDowns for tests = full control of your tests

- control the execution of pre- and postconditions of each test
- control the moment of activity launching. It is one of the most important point in android automation.
- don't write @Before and @After methods by changing it to the lambdas of SetUpRule or TearDownRule object
- combine conditions of your test using annotations

## RuleSequence

This rule is a modern replacement of JUnit 4 *RuleChain*. It allows to control an order of rules execution.

The RuleChain is not flexible. It is unpleasant to use RuleChain especially with class inheritance. That's why
[RuleSequence](https://github.com/alex-tiurin/ultron/blob/master/ultron/src/main/java/com/atiurin/ultron/testlifecycle/rulesequence/RuleSequence.kt)
has been created.

The order of rules execution depends on its addition order.
RuleSequence contains three rules lists with their own priority.
- first - rules from this list will be executed first of all
- normal - rules will be added to this list by default
- last - rules from this list will be executed last

It is recommended to create `RuleSequence` in `BaseTest`. You will be able to add rules to `RuleSequence` in `BaseTest` and in `BaseTest` subclasses.

```kotlin
abstract class BaseTest {
val setupRule = SetUpRule(name = "some name").add {
// some resonable precondition for all tests, eg login or smth like that
}

@get:Rule
open val ruleSequence = RuleSequence(setupRule)
}
```
It's better to add rules in subclasses inside `init` section.
```kotlin
class DemoTest : BaseTest() {
private val activityRule = ActivityScenarioRule(MainActivity::class.java)

init {
ruleSequence.addLast(activityRule)
}
}
```
**Note**: while using `RuleSequence`(as it was with `RuleChain`) you don't need to specify `@get:Rule` annotation for other rules.

Full code sample:
- [BaseTest](https://github.com/alex-tiurin/ultron/blob/master/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/BaseTest.kt)
- [DemoEspressoTest](https://github.com/alex-tiurin/ultron/blob/master/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/espresso/DemoEspressoTest.kt)

To learn more about order of rules execution see [Deep dive into rules order with RuleSequence](https://github.com/alex-tiurin/ultron/wiki/Deep-dive-into-rules-order-with-RuleSequence)


## SetUpRule

This rule allows you to specify lambdas which will be definitely invoked before a test is started.
Moreover in combination with **RuleSequence** setup lambdas could be invoked before an activity is launched.

### Precondition for each tests

Add lambda to `SetUpRule` without any string key and it will be executed before each test in class.

```kotlin
open val setupRule = SetUpRule("Login user rule")
.add(name = "Login valid user $CURRENT_USER") {
Log.info("Login valid user will be executed before any test is started")
AccountManager(InstrumentationRegistry.getInstrumentation().targetContext).login(
CURRENT_USER.login, CURRENT_USER.password
)
}
```
### Precondition for specific test

1. add lambda with string key to `SetUpRule`
2. add `@SetUp` annotation with specified key to desired test

```kotlin
setupRule.add(FIRST_CONDITION){
Log.info("$FIRST_CONDITION setup, executed for test with annotation @SetUp(FIRST_CONDITION)")
}

@SetUp(FIRST_CONDITION)
@Test
fun someTest() {
// some test steps
}
```

**Attention**: dont forget to add `SetUpRule` to `RuleSequence`

```kotlin
ruleSequence.add(setupRule)
```

## TearDownRule

This rule allows you to specify lambdas which will be definitely invoked after a test is finished.

### Postcondition for all tests

Add lambda to `TearDownRule` without any string key and it will be executed after each test in class.

```kotlin
open val tearDownRule = TearDownRule(name = "Logout user from app")
.add {
AccountManager(InstrumentationRegistry.getInstrumentation().targetContext).logout()
}
```
### Postcondition for specific test

1. add lambda with string key to `TearDownRule`
2. add `@TearDown` annotation with specified key to desired test

```kotlin
tearDownRule.add (LAST_CONDITION){
Log.info("$LAST_CONDITION tearDown, executed for test with annotation @TearDown(LAST_CONDITION)")
}

@TearDown(LAST_CONDITION)
@Test
fun someTest() {
// some test steps
}
```

**Attention**: dont forget to add `TearDownRule` to `RuleSequence`

```kotlin
ruleSequence.addLast(tearDownRule)
```

## Add your SetUps and TearDowns to Allure report

Lets clearly define a term **condition**. It's any code block that you've `add` for`SetUpRule` or `TearDownRule`.

For example:
```kotlin
SetUpRule(name = "sample set up").add {
//codition code
}
```
It's possible to add all SetUps and TearDowns to Allure report with applying a recommended config:

```kotlin
UltronAllureConfig.applyRecommended()
```

You can read about Allure configuration [here](../common/allure.md)

What it gives us:

- Rule `name` param will be used as name of Allure step.

```kotlin
SetUpRule(name = "External step name").add {...}
```

- Condition `name` param will be used as a name of inner step

```kotlin
SetUpRule(name = "External step name").add(name = "Internal step name") {
//condition code
}
```

6 changes: 2 additions & 4 deletions docs/docs/common/allure.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 1

# Allure

Ultron can generate artifacts for Allure report.
Ultron can generate artifacts for Allure report only for Android UI tests.

Just set Ultron `testInstrumentationRunner` in your app build.gradle file ([example build.gradle.kts](https://github.com/open-tool/ultron/blob/master/sample-app/build.gradle.kts#L14))

Expand Down Expand Up @@ -50,8 +50,6 @@ You also can add any artifact you need. It will be described later.

![allure](https://github.com/open-tool/ultron/assets/12834123/c05c813a-ece6-45e6-a04f-e1c92b82ffb1)



***
## Ultron `step`
Ultron wraps Allure `step` method into it's own one.
Expand Down Expand Up @@ -109,7 +107,7 @@ UltronComposeConfig.apply {
```
## Add detailed info about your conditions to report

Ultron provides cool feature called **Test condition management** (https://github.com/open-tool/ultron/wiki/Full-control-of-your-tests)
Ultron provides cool feature called [Test condition management](../android/testconditions.md)

With recommended config all conditions will be added to Allure report automatically. The `name` of rule and condition is used as Allure `step` name.

Expand Down
Loading

0 comments on commit 04e8ffa

Please sign in to comment.