Skip to content

Commit

Permalink
Implement search logics to Teacher AssignmentE2E test. (#2128)
Browse files Browse the repository at this point in the history
Refactor DoesNotExistAssertion to handle timeout in seconds.

refs: MBL-16951
affects: Teacher
release note: none
  • Loading branch information
kdeakinstructure authored Aug 31, 2023
1 parent c007dcf commit d4c8bff
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class PageListPage(val searchable: Searchable) : BasePage(R.id.pageListPage) {

fun assertPageNotDisplayed(page: PageApiModel) {
// Check for front page
onView(allOf(withId(R.id.homeSubLabel), withText(page.title))).check(DoesNotExistAssertion(10000L))
onView(allOf(withId(R.id.homeSubLabel), withText(page.title))).check(DoesNotExistAssertion(10))

// Check for regular page
onView(allOf(withId(R.id.title), withText(page.title))).check(DoesNotExistAssertion(10000L))
onView(allOf(withId(R.id.title), withText(page.title))).check(DoesNotExistAssertion(10))
}

fun assertPageListItemCount(expectedCount: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ class AssignmentE2ETest : TeacherTest() {
assignmentListPage.assertHasAssignment(assignment[0])
assignmentListPage.assertNeedsGradingCountOfAssignment(assignment[0].name, 1)

Log.d(STEP_TAG,"Click on Search button and type '${quizAssignment[0].name}' to the search input field.")
assignmentListPage.searchable.clickOnSearchButton()
assignmentListPage.searchable.typeToSearchBar(quizAssignment[0].name)

Log.d(STEP_TAG, "Assert that the '${quizAssignment[0].name}' quiz assignment is the only one which is displayed because it matches the search text.")
assignmentListPage.assertHasAssignment(quizAssignment[0])
assignmentListPage.assertAssignmentNotDisplayed(assignment[0])

Log.d(STEP_TAG,"Clear search input field value and assert if both of the assignment are displayed again on the Assignment List Page.")
assignmentListPage.searchable.clickOnClearSearchButton()
assignmentListPage.assertHasAssignment(assignment[0])
assignmentListPage.assertHasAssignment(quizAssignment[0])

val newAssignmentName = "New Assignment Name"
Log.d(STEP_TAG,"Edit ${assignment[0].name} assignment's name to: $newAssignmentName.")
assignmentListPage.clickAssignment(assignment[0])
Expand Down Expand Up @@ -336,7 +349,6 @@ class AssignmentE2ETest : TeacherTest() {
Espresso.pressBack()
speedGraderCommentsPage.clickOnVideoComment()
speedGraderCommentsPage.assertMediaCommentPreviewDisplayed()

}

@E2E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import com.instructure.canvasapi2.models.Assignment
import com.instructure.dataseeding.model.AssignmentApiModel
import com.instructure.espresso.DoesNotExistAssertion
import com.instructure.espresso.OnViewWithId
import com.instructure.espresso.RecyclerViewItemCountAssertion
import com.instructure.espresso.Searchable
import com.instructure.espresso.WaitForViewWithId
import com.instructure.espresso.assertDisplayed
import com.instructure.espresso.click
import com.instructure.espresso.page.BasePage
import com.instructure.espresso.page.onView
import com.instructure.espresso.page.plus
import com.instructure.espresso.page.waitForView
import com.instructure.espresso.page.waitForViewWithText
import com.instructure.espresso.page.withAncestor
import com.instructure.espresso.page.withId
import com.instructure.espresso.page.withParent
import com.instructure.espresso.page.withText
Expand All @@ -45,7 +49,7 @@ import org.hamcrest.CoreMatchers.allOf
*
* @constructor Creates an instance of the AssignmentListPage.
*/
class AssignmentListPage : BasePage() {
class AssignmentListPage(val searchable: Searchable) : BasePage() {

private val assignmentListToolbar by OnViewWithId(R.id.assignmentListToolbar)
private val assignmentRecyclerView by OnViewWithId(R.id.assignmentRecyclerView)
Expand Down Expand Up @@ -97,6 +101,15 @@ class AssignmentListPage : BasePage() {
assertAssignmentName(assignment.name)
}

/**
* Asserts that the given assignment is NOT present in the list.
*
* @param assignment The assignment to check.
*/
fun assertAssignmentNotDisplayed(assignment: AssignmentApiModel) {
onView(withText(assignment.name)).check(DoesNotExistAssertion(10))
}

/**
* Asserts that grading periods are present.
*/
Expand Down Expand Up @@ -137,7 +150,7 @@ class AssignmentListPage : BasePage() {
}

private fun assertAssignmentName(assignmentName: String) {
waitForViewWithText(assignmentName).assertDisplayed()
waitForView(withText(assignmentName) + withAncestor(R.id.assignmentLayout)).assertDisplayed()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ abstract class TeacherTest : CanvasTest() {
val assigneeListPage = AssigneeListPage()
val assignmentDetailsPage = AssignmentDetailsPage()
val assignmentDueDatesPage = AssignmentDueDatesPage()
val assignmentListPage = AssignmentListPage()
val assignmentListPage = AssignmentListPage(Searchable(R.id.search, R.id.search_src_text, R.id.search_close_btn))
val assignmentSubmissionListPage = AssignmentSubmissionListPage()
val postSettingsPage = PostSettingsPage()
val calendarEventPage = CalendarEventPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ class NotificationBadgeAssertion(@IdRes private val menuItemId: Int, private val
}
}

class DoesNotExistAssertion(private val timeout: Long, private val pollInterval: Long = 500L) : ViewAssertion {
class DoesNotExistAssertion(private val timeoutInSeconds: Long, private val pollIntervalInSeconds: Long = 1L) : ViewAssertion {
override fun check(view: View?, noViewFoundException: NoMatchingViewException?) {
var elapsedTime = 0L

while (elapsedTime < timeout) {
while (elapsedTime < timeoutInSeconds * 1000) {
try {
doesNotExist()
return
} catch (e: AssertionFailedError) {
Thread.sleep(pollInterval)
elapsedTime += pollInterval
Thread.sleep(pollIntervalInSeconds * 1000)
elapsedTime += (pollIntervalInSeconds * 1000)
}
}

throw AssertionError("View still exists after $timeout milliseconds.")
throw AssertionError("View still exists after $timeoutInSeconds seconds.")
}
}

0 comments on commit d4c8bff

Please sign in to comment.