Skip to content

Commit 2cb59f4

Browse files
committed
Fix UI tests
1 parent 458b497 commit 2cb59f4

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import androidx.test.espresso.NoMatchingViewException
88
import androidx.test.espresso.action.ViewActions
99
import androidx.test.espresso.matcher.ViewMatchers
1010
import androidx.test.rule.ActivityTestRule
11-
import fr.free.nrw.commons.utils.StringUtils
11+
import org.apache.commons.lang3.StringUtils
1212
import timber.log.Timber
1313

1414
class UITestHelper {
@@ -27,6 +27,7 @@ class UITestHelper {
2727
//Perform Login
2828
onView(ViewMatchers.withId(R.id.login_username))
2929
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
30+
closeSoftKeyboard()
3031
onView(ViewMatchers.withId(R.id.login_password))
3132
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUserPassword()))
3233
closeSoftKeyboard()
@@ -49,14 +50,14 @@ class UITestHelper {
4950

5051
private fun getTestUsername(): String {
5152
val username = BuildConfig.TEST_USERNAME
52-
if (StringUtils.isNullOrWhiteSpace(username) || username == "null") {
53+
if (StringUtils.isEmpty(username) || username == "null") {
5354
throw NotImplementedError("Configure your beta account's username")
5455
} else return username
5556
}
5657

5758
private fun getTestUserPassword(): String {
5859
val password = BuildConfig.TEST_PASSWORD
59-
if (StringUtils.isNullOrWhiteSpace(password) || password == "null") {
60+
if (StringUtils.isEmpty(password) || password == "null") {
6061
throw NotImplementedError("Configure your beta account's password")
6162
} else return password
6263
}

app/src/androidTest/java/fr/free/nrw/commons/UploadTest.kt

+16-6
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,38 @@ class UploadTest {
141141
.perform(click())
142142
} catch (ignored: NoMatchingViewException) {}
143143

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

147-
onView(withId(R.id.bottom_card_next))
147+
onView(allOf<View>(isDisplayed(), withId(R.id.description_item_edit_text)))
148+
.perform(replaceText(commonsFileName))
149+
150+
151+
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
148152
.perform(click())
149153

154+
try {
155+
onView(withText("Yes"))
156+
.check(matches(isDisplayed()))
157+
.perform(click())
158+
} catch (ignored: NoMatchingViewException) {}
159+
150160
UITestHelper.sleep(1000)
151161

152-
onView(withId(R.id.category_search))
162+
onView(allOf(isDisplayed(), withId(R.id.et_search)))
153163
.perform(replaceText("Uploaded with Mobile/Android Tests"))
154164

155165
UITestHelper.sleep(3000)
156166

157-
onView(withParent(withId(R.id.categories)))
167+
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
158168
.perform(click())
159169

160-
onView(withId(R.id.category_next))
170+
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
161171
.perform(click())
162172

163173
UITestHelper.sleep(500)
164174

165-
onView(withId(R.id.submit))
175+
onView(allOf(isDisplayed(), withId(R.id.btn_submit)))
166176
.perform(click())
167177

168178
UITestHelper.sleep(10000)

app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,11 @@ protected void onDestroy() {
484484
super.onDestroy();
485485
presenter.onDetachView();
486486
compositeDisposable.clear();
487-
mediaLicenseFragment.setCallback(null);
488-
uploadCategoriesFragment.setCallback(null);
487+
if (mediaLicenseFragment != null) {
488+
mediaLicenseFragment.setCallback(null);
489+
}
490+
if (uploadCategoriesFragment != null) {
491+
uploadCategoriesFragment.setCallback(null);
492+
}
489493
}
490494
}

0 commit comments

Comments
 (0)