Skip to content
New issue

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

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

Already on GitHub? # to your account

autotests: GenresListTest, PopularMovieTest #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ dependencies {
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'com.kaspersky.android-components:kaspresso:1.4.2'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
}
47 changes: 47 additions & 0 deletions app/src/androidTest/java/com/example/moviepicker/GenresListTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.moviepicker

import androidx.test.ext.junit.rules.activityScenarioRule
import com.example.moviepicker.pages.GenresScreen
import com.example.moviepicker.pages.HomeScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Assert
import org.junit.Rule
import org.junit.Test

class GenresListTest : TestCase() {
private val genres = listOf(
"Мультфильмы",
"Триллеры",
"Комедии",
"Ужасы"
)

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

Choose a reason for hiding this comment

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

все таки я за то, чтобы выносить это в базовый тестовый класс


@Test
fun checkGenresScreen() = run {
step("Open genres screen") {
HomeScreen {
goToGenresTab()
}
}
step("Check genres count") {
GenresScreen {
Assert.assertEquals(genres.size, rvGenres.getSize())
}
}
step("Check genres list") {
GenresScreen {
rvGenres {
for (i in genres.indices) {
childAt<GenresScreen.GenreScreen>(i) {
genreButton.isVisible()
genreButton.hasText(genres[i])
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.moviepicker

import androidx.test.ext.junit.rules.activityScenarioRule
import com.example.moviepicker.pages.HomeScreen
import com.example.moviepicker.pages.MovieScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Rule
import org.junit.Test

class PopularMovieTest : TestCase() {
private val movieIndex = 0
private var title = "Звёздные войны: Эпизод 1 — Скрытая угроза"

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

@Test
fun checkPopularMovieDescription() = run {
step("Open popular movie description") {
HomeScreen {
goToMovieDescription(movieIndex)
}
}
step("Check title in description") {
MovieScreen {
movieTitle.isVisible()
movieTitle.containsText(title)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.moviepicker.pages

import android.view.View
import com.example.moviepicker.R
import com.kaspersky.kaspresso.screens.KScreen
import io.github.kakaocup.kakao.recycler.KRecyclerItem
import io.github.kakaocup.kakao.recycler.KRecyclerView
import io.github.kakaocup.kakao.text.KButton
import org.hamcrest.Matcher

object GenresScreen : KScreen<GenresScreen>() {

Choose a reason for hiding this comment

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

хочется добавить лоадабл компонент

override val layoutId: Int
get() = R.layout.fragment_genres
override val viewClass: Class<*>?
get() = null

val rvGenres = KRecyclerView(
builder = { withId(R.id.genresRecyclerView) },
itemTypeBuilder = { itemType(::GenreScreen) }
)

class GenreScreen(matcher: Matcher<View>): KRecyclerItem<GenresScreen>(matcher) {
val genreButton = KButton(matcher) { withId(R.id.genreButton) }
}
}

Choose a reason for hiding this comment

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.moviepicker.pages

import android.view.View
import com.example.moviepicker.R
import com.kaspersky.kaspresso.screens.KScreen
import io.github.kakaocup.kakao.common.views.KView
import io.github.kakaocup.kakao.recycler.KRecyclerItem
import io.github.kakaocup.kakao.recycler.KRecyclerView
import io.github.kakaocup.kakao.tabs.KTabLayout
import io.github.kakaocup.kakao.text.KTextView
import org.hamcrest.Matcher


object HomeScreen : KScreen<HomeScreen>() {
private val genresTabId = 1

override val layoutId
get() = R.layout.fragment_home
override val viewClass: Class<*>?
get() = null

private val tabLayout = KTabLayout { withId(R.id.homeTabLayout) }

private val rvPopularMovies = KRecyclerView(
builder = { withId(R.id.popularMoviesRecyclerView) },
itemTypeBuilder = { itemType(::PopularMovieScreen) }
)

class PopularMovieScreen(matcher: Matcher<View>): KRecyclerItem<PopularMovieScreen>(matcher) {
val movieCard = KView(matcher) { withId(R.id.movieCard) }
val movieTitle = KTextView(matcher) { withId(R.id.movieTitle) }
}

fun goToGenresTab() {
this.tabLayout.selectTab(genresTabId)
}

fun goToMovieDescription(index: Int) {
rvPopularMovies.childAt<PopularMovieScreen>(index) {
movieCard.isVisible()
movieCard.click()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.moviepicker.pages

import com.example.moviepicker.R
import com.kaspersky.kaspresso.screens.KScreen
import io.github.kakaocup.kakao.text.KTextView

object MovieScreen : KScreen<MovieScreen>() {
override val layoutId: Int
get() = R.layout.fragment_description
override val viewClass: Class<*>?
get() = null

val movieTitle = KTextView { withId(R.id.movieName) }
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/genre_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/genreContainer"
>
<Button
android:id="@+id/genreButton"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/vertical_movie_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:id="@+id/movieCardContainer"
>
<LinearLayout
android:id="@+id/movieCard"
Expand Down