Skip to content

Commit e08fc97

Browse files
Made login example more complex to showcase cucumber
1 parent 72388b5 commit e08fc97

File tree

7 files changed

+82
-10
lines changed

7 files changed

+82
-10
lines changed

android/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ dependencies {
7070

7171
androidTestImplementation(project(":cucumberShared"))
7272
androidTestImplementation("io.cucumber:cucumber-android:4.10.0")
73-
// TODO figure out how it can be updated without breeaking the project
73+
// TODO figure out how it can be updated without breaking the project
7474
androidTestImplementation("io.cucumber:cucumber-java8:4.8.1")
7575

7676
implementation("io.insert-koin:koin-androidx-compose:3.4.1")

android/src/androidTest/assets/features/Home.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Home
2-
Scenario: Home screen
2+
3+
Scenario: Logout
34
Given Email is "[email protected]"
45
Given I am in the "Home" screen
56
Then I see "[email protected]" text
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
Feature: Login
2-
Scenario: Login screen
2+
3+
Scenario: Failed attempt with wrong credentials
4+
Given I am in the "Login" screen
5+
Then I see the "Email" textfield with text "Email"
6+
Then I type "[email protected]" in the email field
7+
Then I see the "Password" textfield with text "Password"
8+
Then I type "1234" in the password field
9+
Then I see the "Login" button
10+
Then I press the login button
11+
Then I see the "Login" screen
12+
Then I see the "Incorrect email or password" screen
13+
14+
Scenario: Failed attempt with empty email
15+
Given I am in the "Login" screen
16+
Then I see the "Email" textfield with text "Email"
17+
Then I see the "Password" textfield with text "Password"
18+
Then I type "1234" in the password field
19+
Then I see the "Login" button
20+
Then I press the login button
21+
Then I see the "Login" screen
22+
Then I see the "Missing email" screen
23+
24+
Scenario: Failed attempt with empty password
25+
Given I am in the "Login" screen
26+
Then I see the "Email" textfield with text "Email"
27+
Then I see the "Password" textfield with text "Password"
28+
Then I type "1234" in the password field
29+
Then I see the "Login" button
30+
Then I press the login button
31+
Then I see the "Login" screen
32+
Then I see the "Missing password" screen
33+
34+
Scenario: Successful attempt
335
Given I am in the "Login" screen
436
Then I see the "Email" textfield with text "Email"
537
Then I type "[email protected]" in the email field
@@ -8,4 +40,4 @@ Feature: Login
840
Then I see the "Login" button
941
Then I press the login button
1042
Then I see the "Home" screen
11-
Then I see "[email protected]" text
43+
Then I see "[email protected]" text

android/src/androidTest/kotlin/com/corrado4eyes/cucumberplayground/test/StepDefinitions.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import com.corrado4eyes.cucumber.GherkinLambda1
1717
import com.corrado4eyes.cucumber.GherkinLambda2
1818
import com.corrado4eyes.cucumberplayground.android.MainActivity
1919
import com.corrado4eyes.cucumbershared.tests.TestCase
20+
import io.cucumber.core.api.Scenario
21+
import io.cucumber.java.After
22+
import io.cucumber.java.AfterStep
23+
import io.cucumber.java.Before
24+
import io.cucumber.java.BeforeStep
2025
import io.cucumber.java8.En
2126
import io.cucumber.junit.WithJunitRule
2227
import org.junit.Rule
@@ -30,6 +35,41 @@ class StepDefinitions : En {
3035
@get:Rule(order = 0)
3136
val testRule = createComposeRule()
3237

38+
@Before(order = 0)
39+
fun beforeScenarioStart(scenario: Scenario) {
40+
// Will run before each scenario
41+
println("-----------------Start of Scenario ${scenario.name}-----------------")
42+
}
43+
44+
@Before(order = 1)
45+
fun beforeScenario(scenario: Scenario) {
46+
// Will run before each scenario but second in order
47+
println("Running steps:")
48+
}
49+
50+
@After(order = 1)
51+
fun afterScenarioFinish(scenario: Scenario) {
52+
// Will run after each scenario
53+
println("Steps completed")
54+
}
55+
56+
@After(order = 0)
57+
fun afterScenario(scenario: Scenario) {
58+
// Will run after each scenario but second in order
59+
println("-----------------End of Scenario ${scenario.name}-----------------")
60+
}
61+
62+
// TODO figure out for specific step, crashes the app with exception if you try @BeforeStep("some step")
63+
@BeforeStep
64+
fun beforeStep(scenario: Scenario) {
65+
// Run stuff before each scenario step
66+
}
67+
68+
@AfterStep
69+
fun afterStep(scenario: Scenario) {
70+
// Run stuff after each scenario step
71+
}
72+
3373
init {
3474
TestCase.Common.ScreenIsVisible(
3575
GherkinLambda1 { screenName ->
@@ -39,6 +79,7 @@ class StepDefinitions : En {
3979
arguments["testEmail"] = ""
4080
"Login screen"
4181
}
82+
4283
"Home" -> {
4384
arguments["isLoggedIn"] = "true"
4485
"Home screen"
@@ -116,7 +157,7 @@ class StepDefinitions : En {
116157
)
117158
}
118159

119-
private fun <T: Activity> launch(intent: Intent) {
160+
private fun <T : Activity> launch(intent: Intent) {
120161
scenario = ActivityScenario.launch<T>(intent)
121162
}
122163
}

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: 628c667357c176acb30372b1f5ac2574ef0cf182
1515

16-
COCOAPODS: 1.11.3
16+
COCOAPODS: 1.12.1

shared/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ kotlin {
6262
val commonTest by getting {
6363
dependencies {
6464
api(kotlin("test"))
65-
api(kotlin("test-junit"))
6665
api("com.splendo.kaluga:test-utils:$kalugaVersion")
6766
api("io.insert-koin:koin-test:$koinVersion")
6867
}

shared/src/commonTest/kotlin/com/corrado4eyes/cucumberplayground/cucumber/viewModels/LoginViewModelTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ class LoginViewModelTest : KoinUIThreadViewModelTest<LoginViewModelTest.KoinCont
1919
}
2020
) {
2121
val authService = get<AuthService>() as AuthServiceMock
22-
override val viewModel: LoginViewModel = LoginViewModel(authService)
22+
override val viewModel: LoginViewModel = LoginViewModel()
2323
}
2424

2525
@Test
2626
fun test_on_login_button_pressed_fail_with_empty_email() = testOnUIThread {
2727
viewModel.login()
2828
assertTrue(viewModel.emailText.stateFlow.value.isEmpty())
29-
// assertEquals(Colors.red, viewModel.emailTextFieldBorderColor.stateFlow.value)
3029
assertEquals("Missing email", viewModel.emailErrorText.stateFlow.value)
3130
}
3231

@@ -54,7 +53,7 @@ class LoginViewModelTest : KoinUIThreadViewModelTest<LoginViewModelTest.KoinCont
5453
viewModel.passwordText.stateFlow.value = "1234"
5554

5655
viewModel.login()
57-
// assertEquals() Navigation goes to Home
56+
// assertEquals() Navigation goes to Home
5857
}
5958

6059
private inline fun KoinContext.fillCredentials(withPassword: Boolean) {

0 commit comments

Comments
 (0)