From 519b1f2fa8809010480c1799544088d7ff6e0f53 Mon Sep 17 00:00:00 2001 From: vitaliyya Date: Tue, 5 Apr 2022 16:28:43 +0400 Subject: [PATCH 1/7] Added new Kaspresso tests --- .../view/auth/ui/activity/LoginFormTest.kt | 111 ++++++++++++++++++ .../view/auth/ui/activity/SocialAuthScreen.kt | 6 + 2 files changed, 117 insertions(+) create mode 100644 app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt new file mode 100644 index 0000000000..4b0cd986c8 --- /dev/null +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt @@ -0,0 +1,111 @@ +package org.stepik.android.view.auth.ui.activity + +import androidx.test.ext.junit.rules.ActivityScenarioRule +import com.kaspersky.kaspresso.testcases.api.testcase.TestCase +import org.junit.After +import org.junit.Rule +import org.junit.Test + +class SocialAuthScreenTest : TestCase() { + @get:Rule + val activityTestRule = ActivityScenarioRule(SocialAuthActivity::class.java) + + @Test + // @Link("https://vyahhi.myjetbrains.com/youtrack/issue/TESTAPPS-174") + fun testGuestCanSeeSocialAuthScreen() = + run { + step("Should be dismiss button") { + testLogger.d("Should be dismiss button on social auth screen") + SocialAuthScreen { + dismissButton { + isVisible() + } + } + } + + step("Should be Stepik logo") { + testLogger.d("Should be Stepik logo on social auth screen") + SocialAuthScreen { + stepikLogo.isVisible() + } + } + + step("Should be title screen") { + testLogger.d("Should be title on social auth screen") + SocialAuthScreen { + titleScreen { + isVisible() + hasText("Sign In with social accounts") + } + } + } + + step("Should be More button") { + testLogger.d("Should be more button on social auth screen") + SocialAuthScreen { + moreButton { + isVisible() + hasText("More") + } + } + } + + step("Should be sign in with e-mail button") { + testLogger.d("+") + SocialAuthScreen { + signInWithEmailButton { + isVisible() + isClickable() + hasText("Sign in with e-mail") + } + } + } + + step("Should be launch sign up button") { + testLogger.d("---") + SocialAuthScreen { + launchSignUpButton { + isVisible() + hasText("Sign up") + } + } + } + } + + @Test + // @Link("https://vyahhi.myjetbrains.com/youtrack/issue/TESTAPPS-175") + fun testGuestCanExpandSocialAccounts() = + run { + step("Click 'More' button") { + testLogger.i("Click more button") + SocialAuthScreen { + moreButton { + isVisible() + isClickable() + hasText("More") + click() + } + } + } + + step ("Should not be More button") { + testLogger.i("After click on More Button it disappear") + SocialAuthScreen { + moreButton { + isNotDisplayed() + } + } + } + + step("Should be Less button") { + testLogger.i("Should be Less button") + SocialAuthScreen { + lessButton { + isVisible() + isClickable() + hasText("Less") + } + } + } + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt index f91293665b..54183e0c60 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt @@ -10,4 +10,10 @@ object SocialAuthScreen : KScreen() { override val viewClass: Class<*> = SocialAuthActivity::class.java val signInWithEmailButton = KButton { withId(R.id.signInWithEmail) } + val dismissButton = KButton { withId(R.id.dismissButton) } + val stepikLogo = KButton { withId(R.id.stepikLogo) } + val titleScreen = KButton { withId(R.id.signInText) } + val moreButton = KButton { withId(R.id.showMore) } + val lessButton = KButton { withId(R.id.showLess) } + val launchSignUpButton = KButton { withId(R.id.launchSignUpButton) } } \ No newline at end of file From d255420aeb280a689df0c9e248609d2650d56ec8 Mon Sep 17 00:00:00 2001 From: vitaliyya Date: Tue, 5 Apr 2022 18:58:54 +0400 Subject: [PATCH 2/7] Small fix --- .../org/stepik/android/view/auth/ui/activity/LoginFormTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt index 4b0cd986c8..aeceb79e47 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt @@ -2,7 +2,6 @@ package org.stepik.android.view.auth.ui.activity import androidx.test.ext.junit.rules.ActivityScenarioRule import com.kaspersky.kaspresso.testcases.api.testcase.TestCase -import org.junit.After import org.junit.Rule import org.junit.Test From 6056a1a7fec32cf70f51311839b62226a2918904 Mon Sep 17 00:00:00 2001 From: vitaliyya Date: Wed, 6 Apr 2022 01:02:57 +0400 Subject: [PATCH 3/7] Redesigned the login test with page object model (POM) --- .../view/auth/ui/activity/AuthSampleTest.kt | 19 ++++++---------- .../auth/ui/activity/CredentialAuthScreen.kt | 22 +++++++++++++++++-- .../view/auth/ui/activity/LoginFormTest.kt | 4 +++- .../view/auth/ui/activity/SocialAuthScreen.kt | 7 ++++++ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt index a7b3200572..0ea1f161c8 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt @@ -10,24 +10,19 @@ class AuthSampleTest : TestCase() { val activityTestRule = ActivityScenarioRule(SocialAuthActivity::class.java) @Test - fun test() = + fun testGuestCanLoginWithCorrectCredentials() = run { - step("Open Social Auth Screen") { - testLogger.d("I am testLogger") + step("Open Credential Auth Screen") { + testLogger.d("Open Credential Auth Screen") SocialAuthScreen { - signInWithEmailButton { - isVisible() - click() - } + openCredentialAuthScreen() } } - step("Open Credential Auth Screen") { + step("Login with email and password on credential auth screen") { + testLogger.i("Login with email and password on credential auth screen") CredentialAuthScreen { - loginField.isVisible() - loginField.typeText("test@stepik.org") - passwordField.typeText("stepikthebest") - loginField.hasText("test@stepik.org") + loginWithEmailAndPassword(email = "testlearner@stepik.org", password = "512") } } } diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt index 8f497c0146..49ddec6851 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt @@ -8,7 +8,25 @@ object CredentialAuthScreen : KScreen() { override val layoutId: Int = R.layout.activity_auth_credential override val viewClass: Class<*> = CredentialAuthActivity::class.java - val loginField = KEditText { withId(R.id.loginField) } - val passwordField = KEditText { withId(R.id.passwordField) } + val loginField = KEditText { + withId(R.id.loginField) + isDisplayed() + } + val passwordField = KEditText { + withId(R.id.passwordField) + isDisplayed() + } + + fun loginWithEmailAndPassword(email: String, password: String) { + loginField { + click() + replaceText(email) + } + + passwordField { + click() + replaceText(password) + } + } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt index aeceb79e47..fc74f3e69a 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt @@ -25,7 +25,9 @@ class SocialAuthScreenTest : TestCase() { step("Should be Stepik logo") { testLogger.d("Should be Stepik logo on social auth screen") SocialAuthScreen { - stepikLogo.isVisible() + stepikLogo { + isVisible() + } } } diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt index 54183e0c60..4a8c799cfd 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt @@ -16,4 +16,11 @@ object SocialAuthScreen : KScreen() { val moreButton = KButton { withId(R.id.showMore) } val lessButton = KButton { withId(R.id.showLess) } val launchSignUpButton = KButton { withId(R.id.launchSignUpButton) } + + fun openCredentialAuthScreen() { + signInWithEmailButton { + isDisplayed() + click() + } + } } \ No newline at end of file From 11e0be78b92527102d5a0abf7e4cfad8fea13568 Mon Sep 17 00:00:00 2001 From: Rostislav Smirnov Date: Thu, 7 Apr 2022 15:50:43 +0300 Subject: [PATCH 4/7] Build expected sign in string text --- .../view/auth/ui/activity/LoginFormTest.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt index fc74f3e69a..abf602d242 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt @@ -1,7 +1,10 @@ package org.stepik.android.view.auth.ui.activity +import android.content.Context +import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.rules.ActivityScenarioRule import com.kaspersky.kaspresso.testcases.api.testcase.TestCase +import org.stepic.droid.R import org.junit.Rule import org.junit.Test @@ -13,6 +16,8 @@ class SocialAuthScreenTest : TestCase() { // @Link("https://vyahhi.myjetbrains.com/youtrack/issue/TESTAPPS-174") fun testGuestCanSeeSocialAuthScreen() = run { + val applicationResources = ApplicationProvider.getApplicationContext().resources + step("Should be dismiss button") { testLogger.d("Should be dismiss button on social auth screen") SocialAuthScreen { @@ -36,7 +41,12 @@ class SocialAuthScreenTest : TestCase() { SocialAuthScreen { titleScreen { isVisible() - hasText("Sign In with social accounts") + val expectedText = + buildString { + append(applicationResources.getString(R.string.sign_in)) + append(applicationResources.getString(R.string.sign_in_with_social_suffix)) + } + hasText(expectedText) } } } @@ -46,7 +56,8 @@ class SocialAuthScreenTest : TestCase() { SocialAuthScreen { moreButton { isVisible() - hasText("More") + + hasText(R.string.social_recycler_show_more) } } } From 14af6d8a6be916b4747538b9d547ac0d71ef9f5b Mon Sep 17 00:00:00 2001 From: Rostislav Smirnov Date: Thu, 7 Apr 2022 17:14:31 +0300 Subject: [PATCH 5/7] Add shared preferences example --- .../ui/activity/SharedPreferencesSample.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SharedPreferencesSample.kt diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SharedPreferencesSample.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SharedPreferencesSample.kt new file mode 100644 index 0000000000..a1bfd84351 --- /dev/null +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SharedPreferencesSample.kt @@ -0,0 +1,37 @@ +package org.stepik.android.view.auth.ui.activity + +import android.content.Context +import androidx.core.content.edit +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.rules.ActivityScenarioRule +import com.kaspersky.kaspresso.testcases.api.testcase.TestCase +import org.junit.Rule +import org.junit.Test +import org.stepik.android.domain.course.analytic.CourseViewSource +import org.stepik.android.view.course.ui.activity.CourseActivity + +class SharedPreferencesSample : TestCase() { + + private val applicationContext = ApplicationProvider.getApplicationContext() + private val preferencesEditor = applicationContext.getSharedPreferences("device_specific", Context.MODE_PRIVATE) + + @get:Rule + val activityScenario = ActivityScenarioRule(CourseActivity.createIntent(applicationContext, 101420L, CourseViewSource.Unknown)) + + @Test + fun testOpenCourseScreen() = + before { + preferencesEditor.edit(commit = true) { + /** + * Value can be - DiscountPurple, DiscountGreen, DiscountTransparent + */ + putString("split_test_discount_appearance", "DiscountGreen") + } + }.after { +// preferencesEditor.edit(commit = true) { clear() } + }.run { + step("Open Course Screen with ID = 101420") { + Thread.sleep(5000) + } + } +} \ No newline at end of file From 7d11f5e75350caed74075672863e034a879be147 Mon Sep 17 00:00:00 2001 From: vitaliyya Date: Thu, 7 Apr 2022 23:47:37 +0400 Subject: [PATCH 6/7] Redesigned the social auth screen test with POM --- .../view/auth/ui/activity/AuthSampleTest.kt | 7 ++ .../auth/ui/activity/CredentialAuthScreen.kt | 21 +++--- .../view/auth/ui/activity/LoginFormTest.kt | 69 +------------------ .../view/auth/ui/activity/MainFeedActivity.kt | 19 +++++ .../view/auth/ui/activity/SocialAuthScreen.kt | 45 +++++++++++- 5 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/MainFeedActivity.kt diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt index 0ea1f161c8..5356f12f8e 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/AuthSampleTest.kt @@ -25,5 +25,12 @@ class AuthSampleTest : TestCase() { loginWithEmailAndPassword(email = "testlearner@stepik.org", password = "512") } } + + step("Should be a home screen after login") { + testLogger.i("Should be a home screen after login") + MainFeedActivity { + shouldBeHomeScreen() + } + } } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt index 49ddec6851..db7c591ec1 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/CredentialAuthScreen.kt @@ -8,25 +8,28 @@ object CredentialAuthScreen : KScreen() { override val layoutId: Int = R.layout.activity_auth_credential override val viewClass: Class<*> = CredentialAuthActivity::class.java - val loginField = KEditText { - withId(R.id.loginField) - isDisplayed() - } - - val passwordField = KEditText { - withId(R.id.passwordField) - isDisplayed() - } + val loginField = KEditText { withId(R.id.loginField) } + val passwordField = KEditText { withId(R.id.passwordField) } + val signInButton = KEditText { withId(R.id.loginButton)} + val forgotPasswordButton = KEditText { withId(R.id.forgotPasswordView)} + val checkableImageButton = KEditText { withId(R.id.text_input_end_icon)} fun loginWithEmailAndPassword(email: String, password: String) { loginField { + isVisible() click() replaceText(email) } passwordField { + isVisible() click() replaceText(password) } + + signInButton { + isVisible() + click() + } } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt index abf602d242..714acf5f0c 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/LoginFormTest.kt @@ -1,10 +1,7 @@ package org.stepik.android.view.auth.ui.activity -import android.content.Context -import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.rules.ActivityScenarioRule import com.kaspersky.kaspresso.testcases.api.testcase.TestCase -import org.stepic.droid.R import org.junit.Rule import org.junit.Test @@ -16,70 +13,10 @@ class SocialAuthScreenTest : TestCase() { // @Link("https://vyahhi.myjetbrains.com/youtrack/issue/TESTAPPS-174") fun testGuestCanSeeSocialAuthScreen() = run { - val applicationResources = ApplicationProvider.getApplicationContext().resources - - step("Should be dismiss button") { - testLogger.d("Should be dismiss button on social auth screen") - SocialAuthScreen { - dismissButton { - isVisible() - } - } - } - - step("Should be Stepik logo") { - testLogger.d("Should be Stepik logo on social auth screen") - SocialAuthScreen { - stepikLogo { - isVisible() - } - } - } - - step("Should be title screen") { - testLogger.d("Should be title on social auth screen") - SocialAuthScreen { - titleScreen { - isVisible() - val expectedText = - buildString { - append(applicationResources.getString(R.string.sign_in)) - append(applicationResources.getString(R.string.sign_in_with_social_suffix)) - } - hasText(expectedText) - } - } - } - - step("Should be More button") { - testLogger.d("Should be more button on social auth screen") - SocialAuthScreen { - moreButton { - isVisible() - - hasText(R.string.social_recycler_show_more) - } - } - } - - step("Should be sign in with e-mail button") { - testLogger.d("+") + step("Should be Social Auth Screen") { + testLogger.i("Should be Social Auth Screen") SocialAuthScreen { - signInWithEmailButton { - isVisible() - isClickable() - hasText("Sign in with e-mail") - } - } - } - - step("Should be launch sign up button") { - testLogger.d("---") - SocialAuthScreen { - launchSignUpButton { - isVisible() - hasText("Sign up") - } + shouldBeCredentialAuthScreen() } } } diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/MainFeedActivity.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/MainFeedActivity.kt new file mode 100644 index 0000000000..e71e42dc4b --- /dev/null +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/MainFeedActivity.kt @@ -0,0 +1,19 @@ +package org.stepik.android.view.auth.ui.activity + +import org.stepic.droid.R +import com.kaspersky.kaspresso.screens.KScreen +import io.github.kakaocup.kakao.edit.KEditText + +object MainFeedActivity : KScreen() { + override val layoutId: Int = R.layout.activity_main_feed + override val viewClass: Class<*> = MainFeedActivity::class.java + + val toolbarTitle = KEditText { withId(R.id.centeredToolbarTitle) } + + fun shouldBeHomeScreen() { + toolbarTitle { + isVisible() + hasText(R.string.home_title) + } + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt index 4a8c799cfd..347fc97597 100644 --- a/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt +++ b/app/src/androidTest/java/org/stepik/android/view/auth/ui/activity/SocialAuthScreen.kt @@ -1,5 +1,7 @@ package org.stepik.android.view.auth.ui.activity +import android.content.Context +import androidx.test.core.app.ApplicationProvider import com.kaspersky.kaspresso.screens.KScreen import io.github.kakaocup.kakao.text.KButton import org.stepic.droid.R @@ -15,12 +17,51 @@ object SocialAuthScreen : KScreen() { val titleScreen = KButton { withId(R.id.signInText) } val moreButton = KButton { withId(R.id.showMore) } val lessButton = KButton { withId(R.id.showLess) } - val launchSignUpButton = KButton { withId(R.id.launchSignUpButton) } + val signUpButton = KButton { withId(R.id.launchSignUpButton) } fun openCredentialAuthScreen() { signInWithEmailButton { - isDisplayed() + isVisible() click() } } + + fun shouldBeCredentialAuthScreen() { + val applicationResources = ApplicationProvider.getApplicationContext().resources + + dismissButton { + isVisible() + } + + stepikLogo { + isVisible() + } + + titleScreen { + val expectedText = + buildString { + append(applicationResources.getString(R.string.sign_in)) + append(applicationResources.getString(R.string.sign_in_with_social_suffix)) + } + isVisible() + hasText(expectedText) + } + + moreButton { + isVisible() + hasText(R.string.social_recycler_show_more) + } + + signInWithEmailButton { + isVisible() + isClickable() + hasText(R.string.sign_in_with_password) + } + + signUpButton { + isVisible() + isClickable() + hasText(R.string.sign_up) + } + } } \ No newline at end of file From 1925b3ddc415bd8401500ae46a0ac1bdb0d9689b Mon Sep 17 00:00:00 2001 From: Rostislav Smirnov Date: Fri, 8 Apr 2022 17:33:23 +0300 Subject: [PATCH 7/7] Bump Flipper --- dependencies.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 88d38a2511..0a7008a076 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -108,8 +108,8 @@ ext.versions = [ ktlint : '0.34.2', ktlintRules : '1.0.0', - flipper : '0.49.0', - soloader : '0.9.0', + flipper : '0.142.0', + soloader : '0.10.1', toolargetool : '0.3.0' ]