forked from KasperskyLab/Kaspresso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KasperskyLab#76 from RuslanMingaliev/feature/botto…
…m_nav_checkbox feature=Kautomator_views: BottomNavigationView + Checkbox
- Loading branch information
Showing
15 changed files
with
347 additions
and
19 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...c/main/kotlin/com/kaspersky/components/kautomator/dsl/bottomnav/UiBottomNavigationView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@file:Suppress("unused") | ||
package com.kaspersky.components.kautomator.dsl.bottomnav | ||
|
||
import com.kaspersky.components.kautomator.dsl.common.builders.UiViewBuilder | ||
import com.kaspersky.components.kautomator.dsl.common.builders.UiViewSelector | ||
import com.kaspersky.components.kautomator.dsl.common.views.UiBaseView | ||
|
||
/** | ||
* View for acting and asserting on BottomNavigationView | ||
* | ||
* @see UiBottomNavigationViewActions | ||
* @see UiBottomNavigationViewAssertions | ||
*/ | ||
class UiBottomNavigationView : UiBaseView<UiBottomNavigationView>, UiBottomNavigationViewActions, UiBottomNavigationViewAssertions { | ||
constructor(selector: UiViewSelector) : super(selector) | ||
constructor(builder: UiViewBuilder.() -> Unit) : super(builder) | ||
} |
53 changes: 53 additions & 0 deletions
53
...kotlin/com/kaspersky/components/kautomator/dsl/bottomnav/UiBottomNavigationViewActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@file:Suppress("unused") | ||
package com.kaspersky.components.kautomator.dsl.bottomnav | ||
|
||
import androidx.test.uiautomator.By | ||
import com.kaspersky.components.kautomator.dsl.common.actions.UiBaseActions | ||
import com.kaspersky.components.kautomator.intercepting.operation.UiOperationType | ||
|
||
/** | ||
* Provides actions for BottomNavigationView | ||
*/ | ||
interface UiBottomNavigationViewActions : UiBaseActions { | ||
|
||
/** | ||
* Selects menu item with given id | ||
* | ||
* @param id Menu item id | ||
*/ | ||
fun setSelectedItemWithId(id: String) { | ||
view.perform(UiBottomNavigationViewActionType.SELECT_WITH_ID) { | ||
findObject(By.res(applicationPackage, id)).click() | ||
} | ||
} | ||
|
||
/** | ||
* Selects menu item with given index. Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param index Menu item index | ||
*/ | ||
fun setSelectedItemWithIndex(index: Int) { | ||
view.perform(UiBottomNavigationViewActionType.SELECT_WITH_INDEX) { | ||
children[0] // ViewGroup with menu items | ||
.children[index] // Menu item with index | ||
.click() | ||
} | ||
} | ||
|
||
/** | ||
* Selects menu item with given title. Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param title Menu item title | ||
*/ | ||
fun setSelectedItemWithTitle(title: String) { | ||
view.perform(UiBottomNavigationViewActionType.SELECT_WITH_TITLE) { | ||
findObject(By.text(title)).click() | ||
} | ||
} | ||
|
||
enum class UiBottomNavigationViewActionType : UiOperationType { | ||
SELECT_WITH_ID, | ||
SELECT_WITH_INDEX, | ||
SELECT_WITH_TITLE | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...lin/com/kaspersky/components/kautomator/dsl/bottomnav/UiBottomNavigationViewAssertions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
@file:Suppress("unused") | ||
package com.kaspersky.components.kautomator.dsl.bottomnav | ||
|
||
import androidx.test.uiautomator.By | ||
import com.google.common.truth.Truth.assertThat | ||
import com.kaspersky.components.kautomator.dsl.common.assertions.UiBaseAssertions | ||
import com.kaspersky.components.kautomator.intercepting.operation.UiOperationType | ||
|
||
/** | ||
* Provides assertions for BottomNavigationview | ||
*/ | ||
interface UiBottomNavigationViewAssertions : UiBaseAssertions { | ||
|
||
/** | ||
* Checks if the view's selected menu item id matches given one | ||
* | ||
* @param id Menu item id | ||
*/ | ||
fun hasSelectedItemWithId(id: String) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_SELECTED_ITEM_WITH_ID) { | ||
val item = findObject(By.res(applicationPackage, id)) | ||
assertThat(item.isSelected).isTrue() | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the view's selected menu item id does not match given one. | ||
* | ||
* @param id Menu item id | ||
*/ | ||
fun hasNotSelectedItemWithId(id: String) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_NOT_SELECTED_ITEM_WITH_ID) { | ||
val item = findObject(By.res(applicationPackage, id)) | ||
assertThat(item.isSelected).isFalse() | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the view's selected menu item index matches given one. | ||
* Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param index Menu item index | ||
*/ | ||
fun hasSelectedItemWithIndex(index: Int) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_SELECTED_ITEM_WITH_INDEX) { | ||
val item = children[0] // ViewGroup with menu items | ||
.children[index] // Menu item with index | ||
assertThat(item.isSelected).isTrue() | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the view's selected menu item index does not match given one. | ||
* Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param index Menu item index | ||
*/ | ||
fun hasNotSelectedItemWithIndex(index: Int) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_NOT_SELECTED_ITEM_WITH_INDEX) { | ||
val item = children[0] // ViewGroup with menu items | ||
.children[index] // Menu item with index | ||
assertThat(item.isSelected).isFalse() | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the view's selected menu item title matches given one. | ||
* Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param title Menu item title | ||
*/ | ||
fun hasSelectedItemWithTitle(title: String) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_SELECTED_ITEM_WITH_TITLE) { | ||
val item = findObject(By.text(title)) | ||
.parent // BaselineLayout | ||
.parent // Menu item | ||
assertThat(item.isSelected).isTrue() | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the view's selected menu item title does not match given one. | ||
* Note that this method uses view hierarchy which could be changed at any time. | ||
* | ||
* @param title Menu item title | ||
*/ | ||
fun hasNotSelectedItemWithTitle(title: String) { | ||
view.check(UiBottomNavigationViewAssertionType.IS_NOT_SELECTED_ITEM_WITH_TITLE) { | ||
val item = findObject(By.text(title)) | ||
.parent // BaselineLayout | ||
.parent // Menu item | ||
assertThat(item.isSelected).isFalse() | ||
} | ||
} | ||
|
||
enum class UiBottomNavigationViewAssertionType : UiOperationType { | ||
IS_SELECTED_ITEM_WITH_ID, | ||
IS_NOT_SELECTED_ITEM_WITH_ID, | ||
IS_SELECTED_ITEM_WITH_INDEX, | ||
IS_NOT_SELECTED_ITEM_WITH_INDEX, | ||
IS_SELECTED_ITEM_WITH_TITLE, | ||
IS_NOT_SELECTED_ITEM_WITH_TITLE | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
kautomator/src/main/kotlin/com/kaspersky/components/kautomator/dsl/check/UiCheckBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...mator/src/main/kotlin/com/kaspersky/components/kautomator/dsl/check/UiCheckableActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...src/androidTest/java/com/kaspersky/kaspresso/sample_kautomator/screen/ComponentsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.kaspersky.kaspresso.sample_kautomator.screen | ||
|
||
import com.kaspersky.components.kautomator.dsl.bottomnav.UiBottomNavigationView | ||
import com.kaspersky.components.kautomator.dsl.check.UiCheckBox | ||
import com.kaspersky.components.kautomator.dsl.screen.UiScreen | ||
|
||
object ComponentsScreen : UiScreen<ComponentsScreen>() { | ||
|
||
private const val MAIN_APP_PACKAGE_ID = "com.kaspersky.kaspresso.sample_kautomator" | ||
|
||
val bottomNav = UiBottomNavigationView { withId(this@ComponentsScreen.MAIN_APP_PACKAGE_ID, "bottomNav") } | ||
val checkbox = UiCheckBox { withId(this@ComponentsScreen.MAIN_APP_PACKAGE_ID, "checkBox") } | ||
} |
58 changes: 58 additions & 0 deletions
58
...ava/com/kaspersky/kaspresso/sample_kautomator/test/components/BottomNavigationViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.kaspersky.kaspresso.sample_kautomator.test.components | ||
|
||
import androidx.test.rule.ActivityTestRule | ||
import com.kaspersky.kaspresso.sample_kautomator.ComponentsActivity | ||
import com.kaspersky.kaspresso.sample_kautomator.screen.ComponentsScreen | ||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class BottomNavigationViewTest : TestCase() { | ||
|
||
companion object { | ||
private const val ITEM_0_TEXT = "Menu Item 1" | ||
private const val ITEM_1_TEXT = "Menu Item 2" | ||
|
||
private const val ITEM_0_ID = "menu_item_1" | ||
private const val ITEM_1_ID = "menu_item_2" | ||
} | ||
|
||
@get:Rule | ||
val rule = ActivityTestRule(ComponentsActivity::class.java, true, true) | ||
|
||
@Test | ||
fun test() { | ||
run { | ||
|
||
step("Select item by id") { | ||
ComponentsScreen { | ||
bottomNav { | ||
setSelectedItemWithId(ITEM_1_ID) | ||
hasSelectedItemWithId(ITEM_1_ID) | ||
hasNotSelectedItemWithId(ITEM_0_ID) | ||
} | ||
} | ||
} | ||
|
||
step("Select item by index") { | ||
ComponentsScreen { | ||
bottomNav { | ||
setSelectedItemWithIndex(0) | ||
hasSelectedItemWithIndex(0) | ||
hasNotSelectedItemWithIndex(1) | ||
} | ||
} | ||
} | ||
|
||
step("Select item by label") { | ||
ComponentsScreen { | ||
bottomNav { | ||
setSelectedItemWithTitle(ITEM_1_TEXT) | ||
hasSelectedItemWithTitle(ITEM_1_TEXT) | ||
hasNotSelectedItemWithTitle(ITEM_0_TEXT) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ndroidTest/java/com/kaspersky/kaspresso/sample_kautomator/test/components/CheckboxTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.kaspersky.kaspresso.sample_kautomator.test.components | ||
|
||
import androidx.test.rule.ActivityTestRule | ||
import com.kaspersky.kaspresso.sample_kautomator.ComponentsActivity | ||
import com.kaspersky.kaspresso.sample_kautomator.screen.ComponentsScreen | ||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class CheckboxTest : TestCase() { | ||
|
||
@get:Rule | ||
val rule = ActivityTestRule(ComponentsActivity::class.java, true, true) | ||
|
||
@Test | ||
fun test() { | ||
run { | ||
step("Set checked") { | ||
ComponentsScreen { | ||
checkbox { | ||
setChecked(true) | ||
isChecked() | ||
} | ||
} | ||
} | ||
|
||
step("Set not checked") { | ||
ComponentsScreen { | ||
checkbox { | ||
setChecked(false) | ||
isNotChecked() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
..._kautomator/src/main/java/com/kaspersky/kaspresso/sample_kautomator/ComponentsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.kaspersky.kaspresso.sample_kautomator | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class ComponentsActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_ui_components) | ||
} | ||
} |
Oops, something went wrong.