porting ui base to be a onboarding robot and providing via the element robot

This commit is contained in:
Adam Brown 2021-11-05 13:56:34 +00:00
parent 17789f00bb
commit 0f1c9f4af5
4 changed files with 89 additions and 17 deletions

View File

@ -18,7 +18,7 @@ package im.vector.app
import android.net.Uri
import androidx.lifecycle.Observer
import im.vector.app.ui.UiTestBase
import im.vector.app.ui.robot.OnboardingRobot
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@ -39,7 +39,7 @@ abstract class VerificationTestBase {
val password = "password"
val homeServerUrl: String = "http://10.0.2.2:8080"
protected val uiTestBase = UiTestBase()
protected val uiTestBase = OnboardingRobot()
fun createAccountAndSync(matrix: Matrix,
userName: String,

View File

@ -17,25 +17,47 @@
package im.vector.app.ui.robot
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import com.adevinta.android.barista.interaction.BaristaDrawerInteractions.openDrawer
import im.vector.app.EspressoHelper
import im.vector.app.R
import im.vector.app.activityIdlingResource
import im.vector.app.espresso.tools.waitUntilActivityVisible
import im.vector.app.espresso.tools.waitUntilViewVisible
import im.vector.app.features.createdirect.CreateDirectRoomActivity
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
import java.lang.Thread.sleep
import im.vector.app.features.home.HomeActivity
import im.vector.app.initialSyncIdlingResource
import im.vector.app.withIdlingResource
class ElementRobot {
fun login(userId: String) {
val onboardingRobot = OnboardingRobot()
onboardingRobot.createAccount(userId = userId)
withIdlingResource(activityIdlingResource(HomeActivity::class.java)) {
BaristaVisibilityAssertions.assertDisplayed(R.id.roomListContainer)
ViewActions.closeSoftKeyboard()
}
val activity = EspressoHelper.getCurrentActivity()!!
val uiSession = (activity as HomeActivity).activeSessionHolder.getActiveSession()
withIdlingResource(initialSyncIdlingResource(uiSession)) {
BaristaVisibilityAssertions.assertDisplayed(R.id.roomListContainer)
}
waitUntilViewVisible(withId(R.id.bottomNavigationView))
}
fun settings(block: SettingsRobot.() -> Unit) {
openDrawer()
clickOn(R.id.homeDrawerHeaderSettingsView)
block(SettingsRobot())
pressBack()
waitUntilViewVisible(ViewMatchers.withId(R.id.bottomNavigationView))
waitUntilViewVisible(withId(R.id.bottomNavigationView))
}
fun newDirectMessage(block: NewDirectMessageRobot.() -> Unit) {
@ -43,21 +65,21 @@ class ElementRobot {
clickOn(R.id.createChatRoomButton)
waitUntilActivityVisible<CreateDirectRoomActivity>()
// close keyboard
sleep(1000)
pressBack()
block(NewDirectMessageRobot())
pressBack()
waitUntilViewVisible(ViewMatchers.withId(R.id.bottomNavigationView))
waitUntilViewVisible(withId(R.id.bottomNavigationView))
}
fun newRoom(block: NewRoomRobot.() -> Unit) {
clickOn(R.id.bottom_action_rooms)
clickOn(R.id.createGroupRoomButton)
sleep(1000)
waitUntilActivityVisible<RoomDirectoryActivity>()
BaristaVisibilityAssertions.assertDisplayed(R.id.publicRoomsList)
block(NewRoomRobot())
pressBack()
waitUntilViewVisible(ViewMatchers.withId(R.id.bottomNavigationView))
RoomListRobot().newRoom { block() }
waitUntilViewVisible(withId(R.id.bottomNavigationView))
}
fun roomList(block: RoomListRobot.() -> Unit) {
clickOn(R.id.bottom_action_rooms)
block(RoomListRobot())
waitUntilViewVisible(withId(R.id.bottomNavigationView))
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package im.vector.app.ui
package im.vector.app.ui.robot
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onView
@ -31,7 +31,7 @@ import im.vector.app.features.home.HomeActivity
import im.vector.app.waitForView
import java.lang.Thread.sleep
class UiTestBase {
class OnboardingRobot {
fun createAccount(userId: String, password: String = "password", homeServerUrl: String = "http://10.0.2.2:8080") {
initSession(true, userId, password, homeServerUrl)

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.ui.robot
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions
import com.adevinta.android.barista.interaction.BaristaClickInteractions
import im.vector.app.R
import im.vector.app.espresso.tools.waitUntilActivityVisible
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
class RoomListRobot {
fun verifyCreatedRoom() {
Espresso.onView(ViewMatchers.withId(R.id.roomListView))
.perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
ViewMatchers.hasDescendant(ViewMatchers.withText(R.string.room_displayname_empty_room)),
ViewActions.longClick()
)
)
Espresso.pressBack()
}
fun newRoom(block: NewRoomRobot.() -> Unit) {
BaristaClickInteractions.clickOn(R.id.createGroupRoomButton)
waitUntilActivityVisible<RoomDirectoryActivity>()
BaristaVisibilityAssertions.assertDisplayed(R.id.publicRoomsList)
block(NewRoomRobot())
Espresso.pressBack()
}
}