Skip to content

Fix compilation and other minor issues with Espresso Tests #3297

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2019
Merged
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
7 changes: 4 additions & 3 deletions app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.rule.ActivityTestRule
import fr.free.nrw.commons.utils.StringUtils
import org.apache.commons.lang3.StringUtils
import timber.log.Timber

class UITestHelper {
Expand All @@ -27,6 +27,7 @@ class UITestHelper {
//Perform Login
onView(ViewMatchers.withId(R.id.login_username))
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
closeSoftKeyboard()
onView(ViewMatchers.withId(R.id.login_password))
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUserPassword()))
closeSoftKeyboard()
Expand All @@ -49,14 +50,14 @@ class UITestHelper {

private fun getTestUsername(): String {
val username = BuildConfig.TEST_USERNAME
if (StringUtils.isNullOrWhiteSpace(username) || username == "null") {
if (StringUtils.isEmpty(username) || username == "null") {
throw NotImplementedError("Configure your beta account's username")
} else return username
}

private fun getTestUserPassword(): String {
val password = BuildConfig.TEST_PASSWORD
if (StringUtils.isNullOrWhiteSpace(password) || password == "null") {
if (StringUtils.isEmpty(password) || password == "null") {
throw NotImplementedError("Configure your beta account's password")
} else return password
}
Expand Down
22 changes: 16 additions & 6 deletions app/src/androidTest/java/fr/free/nrw/commons/UploadTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,38 @@ class UploadTest {
.perform(click())
} catch (ignored: NoMatchingViewException) {}

onView(allOf<View>(withId(R.id.description_item_edit_text), withParent(withParent(withId(R.id.image_title_container)))))
onView(allOf<View>(isDisplayed(), withId(R.id.et_title)))
.perform(replaceText(commonsFileName))

onView(withId(R.id.bottom_card_next))
onView(allOf<View>(isDisplayed(), withId(R.id.description_item_edit_text)))
.perform(replaceText(commonsFileName))


onView(allOf(isDisplayed(), withId(R.id.btn_next)))
.perform(click())

try {
onView(withText("Yes"))
.check(matches(isDisplayed()))
.perform(click())
} catch (ignored: NoMatchingViewException) {}

UITestHelper.sleep(1000)

onView(withId(R.id.category_search))
onView(allOf(isDisplayed(), withId(R.id.et_search)))
.perform(replaceText("Uploaded with Mobile/Android Tests"))

UITestHelper.sleep(3000)

onView(withParent(withId(R.id.categories)))
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
.perform(click())

onView(withId(R.id.category_next))
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
.perform(click())

UITestHelper.sleep(500)

onView(withId(R.id.submit))
onView(allOf(isDisplayed(), withId(R.id.btn_submit)))
.perform(click())

UITestHelper.sleep(10000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ protected void onDestroy() {
super.onDestroy();
presenter.onDetachView();
compositeDisposable.clear();
mediaLicenseFragment.setCallback(null);
uploadCategoriesFragment.setCallback(null);
if (mediaLicenseFragment != null) {
mediaLicenseFragment.setCallback(null);
}
if (uploadCategoriesFragment != null) {
uploadCategoriesFragment.setCallback(null);
}
}
}