Skip to content

Commit

Permalink
Added new VisibilityMatchers, TextHelpers and ActionHelpers (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffasitella committed Feb 2, 2022
1 parent 532d3bb commit a233aa8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ar.com.wolox.wolmo.testing.espresso.actions

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -36,4 +37,34 @@ object ActionsHelper {
onView(withId(it)).perform(click())
}
}

/**
* Use this method to long click a view.
*
* @param viewId the ID of the view you want to click.
* <pre>{@code
* longClick(R.id.myButton)
* }
* </pre>
*/
fun longClick(vararg viewId: Int) {
viewId.forEach {
onView(withId(it)).perform(ViewActions.longClick())
}
}

/**
* Use this method to double click a view.
*
* @param viewId the ID of the view you want to click.
* <pre>{@code
* doubleClick(R.id.myButton)
* }
* </pre>
*/
fun doubleClick(vararg viewId: Int) {
viewId.forEach {
onView(withId(it)).perform(ViewActions.doubleClick())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ar.com.wolox.wolmo.testing.espresso.text

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.matcher.ViewMatchers.withId
import ar.com.wolox.wolmo.testing.model.Assertion

object TextHelpers {

/**
* Use this method to type text inside an EditText and closing the soft keyboar.d
* Use this method to type text inside an EditText and closing the soft keyboard
*
* @param viewId the ID of the view in which the text will be typed.
* @param text the text to be typed
Expand All @@ -20,4 +21,31 @@ object TextHelpers {
fun writeText(viewId: Int, text: String) {
onView(withId(viewId)).perform(typeText(text), closeSoftKeyboard())
}

/**
* Use this method to clear the current text inside an EditText.
*
* @param viewId the ID of the view in which the text will be typed.
* <pre>{@code
* clearText(R.id.myEditText)
* }
* </pre>
*/
fun clearText(viewId: Int) {
onView(withId(viewId)).perform(ViewActions.clearText())
}

/**
* Use this method to replace the current text inside an EditText and closing the soft keyboard
*
* @param viewId the ID of the view in which the text will be typed.
* @param text the new text to be typed
* <pre>{@code
* replaceText(R.id.myEditText, R.id.my_new_text)
* }
* </pre>
*/
fun replaceText(viewId: Int, newText: String) {
onView(withId(viewId)).perform(ViewActions.replaceText(newText), closeSoftKeyboard())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,60 @@ object VisibilityMatchers {
onView(withId(it)).check(matches(ViewMatchers.isNotEnabled()))
}
}

/**
* This method checks if the given views are clickable.
*
* @param viewId
* <pre>{@code
* checkIsClickable(R.id.myImageView, R.id.myTextView)
* }
* </pre>
*/
fun checkIsClickable(vararg viewId: Int) {
viewId.forEach {
onView(withId(it)).check(matches(ViewMatchers.isClickable()))
}
}

/**
* This method checks if the given views are not clickable.
*
* @param viewId
* <pre>{@code
* checkIsNotClickable(R.id.myImageView, R.id.myTextView)
* }
* </pre>
*/
fun checkIsNotClickable(vararg viewId: Int) {
viewId.forEach {
onView(withId(it)).check(matches(ViewMatchers.isNotClickable()))
}
}

/**
* This method checks if the given view has focus.
*
* @param viewId
* <pre>{@code
* checkIsFocused(R.id.myImageView)
* }
* </pre>
*/
fun checkIsFocused(viewId: Int) {
onView(withId(viewId)).check(matches(ViewMatchers.isFocused()))
}

/**
* This method checks if the given view does not have focus.
*
* @param viewId
* <pre>{@code
* checkIsNotFocused(R.id.myImageView)
* }
* </pre>
*/
fun checkIsNotFocused(viewId: Int) {
onView(withId(viewId)).check(matches(ViewMatchers.isNotFocused()))
}
}

0 comments on commit a233aa8

Please sign in to comment.