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

Kaspresso test #965

Draft
wants to merge 8 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ 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")
}
}

step("Should be a home screen after login") {
testLogger.i("Should be a home screen after login")
MainFeedActivity {
shouldBeHomeScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,26 @@ object CredentialAuthScreen : KScreen<CredentialAuthScreen>() {

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне это нравится, можно переиспользовать для разных кейсов с логином

loginField {
isVisible()
click()
replaceText(email)
}

passwordField {
isVisible()
click()
replaceText(password)
}

signInButton {
isVisible()
click()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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.Rule
import org.junit.Test

class SocialAuthScreenTest : TestCase() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоит назвать файл так же как и класс.

@get:Rule
val activityTestRule = ActivityScenarioRule(SocialAuthActivity::class.java)

@Test
// @Link("https://vyahhi.myjetbrains.com/youtrack/issue/TESTAPPS-174")
fun testGuestCanSeeSocialAuthScreen() =
run {
step("Should be Social Auth Screen") {
testLogger.i("Should be Social Auth Screen")
SocialAuthScreen {
shouldBeCredentialAuthScreen()
}
}
}

@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")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<MainFeedActivity>() {
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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Context>()
private val preferencesEditor = applicationContext.getSharedPreferences("device_specific", Context.MODE_PRIVATE)

@get:Rule
val activityScenario = ActivityScenarioRule<CourseActivity>(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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,4 +12,56 @@ object SocialAuthScreen : KScreen<SocialAuthScreen>() {
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 signUpButton = KButton { withId(R.id.launchSignUpButton) }

fun openCredentialAuthScreen() {
signInWithEmailButton {
isVisible()
click()
}
}

fun shouldBeCredentialAuthScreen() {
val applicationResources = ApplicationProvider.getApplicationContext<Context>().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)
}
}
}
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]

Expand Down