Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made examples more generic and added some more printing examples #24

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Next Next commit
Made login example more complex to showcase cucumber
  • Loading branch information
ChristoferAlexander committed Jul 3, 2023
commit e08fc97f83b6dc8a6ae09d784a7c3c99d2953f45
2 changes: 1 addition & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {

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

implementation("io.insert-koin:koin-androidx-compose:3.4.1")
Expand Down
3 changes: 2 additions & 1 deletion android/src/androidTest/assets/features/Home.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Feature: Home
Scenario: Home screen

Scenario: Logout
Given Email is "test@test.com"
Given I am in the "Home" screen
Then I see "test@test.com" text
Expand Down
36 changes: 34 additions & 2 deletions android/src/androidTest/assets/features/Login.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
Feature: Login
Scenario: Login screen

Scenario: Failed attempt with wrong credentials
Given I am in the "Login" screen
Then I see the "Email" textfield with text "Email"
Then I type "test@test.comunism" in the email field
Then I see the "Password" textfield with text "Password"
Then I type "1234" in the password field
Then I see the "Login" button
Then I press the login button
Then I see the "Login" screen
Then I see the "Incorrect email or password" screen

Scenario: Failed attempt with empty email
Given I am in the "Login" screen
Then I see the "Email" textfield with text "Email"
Then I see the "Password" textfield with text "Password"
Then I type "1234" in the password field
Then I see the "Login" button
Then I press the login button
Then I see the "Login" screen
Then I see the "Missing email" screen

Scenario: Failed attempt with empty password
Given I am in the "Login" screen
Then I see the "Email" textfield with text "Email"
Then I see the "Password" textfield with text "Password"
Then I type "1234" in the password field
Then I see the "Login" button
Then I press the login button
Then I see the "Login" screen
Then I see the "Missing password" screen

Scenario: Successful attempt
Given I am in the "Login" screen
Then I see the "Email" textfield with text "Email"
Then I type "test@test.com" in the email field
Expand All @@ -8,4 +40,4 @@ Feature: Login
Then I see the "Login" button
Then I press the login button
Then I see the "Home" screen
Then I see "test@test.com" text
Then I see "test@test.com" text
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import com.corrado4eyes.cucumber.GherkinLambda1
import com.corrado4eyes.cucumber.GherkinLambda2
import com.corrado4eyes.cucumberplayground.android.MainActivity
import com.corrado4eyes.cucumbershared.tests.TestCase
import io.cucumber.core.api.Scenario
import io.cucumber.java.After
import io.cucumber.java.AfterStep
import io.cucumber.java.Before
import io.cucumber.java.BeforeStep
import io.cucumber.java8.En
import io.cucumber.junit.WithJunitRule
import org.junit.Rule
Expand All @@ -30,6 +35,41 @@ class StepDefinitions : En {
@get:Rule(order = 0)
val testRule = createComposeRule()

@Before(order = 0)
fun beforeScenarioStart(scenario: Scenario) {
// Will run before each scenario
println("-----------------Start of Scenario ${scenario.name}-----------------")
}

@Before(order = 1)
fun beforeScenario(scenario: Scenario) {
// Will run before each scenario but second in order
println("Running steps:")
}

@After(order = 1)
fun afterScenarioFinish(scenario: Scenario) {
// Will run after each scenario
println("Steps completed")
}

@After(order = 0)
fun afterScenario(scenario: Scenario) {
// Will run after each scenario but second in order
println("-----------------End of Scenario ${scenario.name}-----------------")
}

// TODO figure out for specific step, crashes the app with exception if you try @BeforeStep("some step")
@BeforeStep
fun beforeStep(scenario: Scenario) {
// Run stuff before each scenario step
}

@AfterStep
fun afterStep(scenario: Scenario) {
// Run stuff after each scenario step
}

init {
TestCase.Common.ScreenIsVisible(
GherkinLambda1 { screenName ->
Expand All @@ -39,6 +79,7 @@ class StepDefinitions : En {
arguments["testEmail"] = ""
"Login screen"
}

"Home" -> {
arguments["isLoggedIn"] = "true"
"Home screen"
Expand Down Expand Up @@ -116,7 +157,7 @@ class StepDefinitions : En {
)
}

private fun <T: Activity> launch(intent: Intent) {
private fun <T : Activity> launch(intent: Intent) {
scenario = ActivityScenario.launch<T>(intent)
}
}
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 628c667357c176acb30372b1f5ac2574ef0cf182

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
1 change: 0 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ kotlin {
val commonTest by getting {
dependencies {
api(kotlin("test"))
api(kotlin("test-junit"))
api("com.splendo.kaluga:test-utils:$kalugaVersion")
api("io.insert-koin:koin-test:$koinVersion")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ class LoginViewModelTest : KoinUIThreadViewModelTest<LoginViewModelTest.KoinCont
}
) {
val authService = get<AuthService>() as AuthServiceMock
override val viewModel: LoginViewModel = LoginViewModel(authService)
override val viewModel: LoginViewModel = LoginViewModel()
}

@Test
fun test_on_login_button_pressed_fail_with_empty_email() = testOnUIThread {
viewModel.login()
assertTrue(viewModel.emailText.stateFlow.value.isEmpty())
// assertEquals(Colors.red, viewModel.emailTextFieldBorderColor.stateFlow.value)
assertEquals("Missing email", viewModel.emailErrorText.stateFlow.value)
}

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

viewModel.login()
// assertEquals() Navigation goes to Home
// assertEquals() Navigation goes to Home
}

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