Skip to content

Commit 242aaa1

Browse files
committed
Fix EditLinkPage#updateURL action by introducing safety mechanisms: assert focus, add a delay, close the keyboard
1 parent 2a93d62 commit 242aaa1

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ class EditLinkPage : BasePage() {
3333
}
3434

3535
fun updateURL(url: String): EditLinkPage {
36-
urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard())
36+
threadSleep(2000L) // Wait for the page to load
37+
try {
38+
urlField.perform(click())
39+
urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard())
40+
} catch (e: RuntimeException){
41+
// If the URL field is not visible, it might be because the keyboard is open.
42+
// Close the keyboard and try again.
43+
urlField.perform(ViewActions.closeSoftKeyboard())
44+
urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard())
45+
}
3746
label("Entered url")
3847

3948
return this
@@ -80,4 +89,9 @@ class EditLinkPage : BasePage() {
8089
cancelButton.perform(click())
8190
label("Canceled")
8291
}
92+
93+
fun threadSleep(millis: Long): EditLinkPage {
94+
Thread.sleep(millis)
95+
return this
96+
}
8397
}

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/LinkHistoryTests.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,19 @@ class LinkHistoryTests : BaseHistoryTest() {
204204
*/
205205
private fun addLinkAndVerify(editorPage: EditorPage, link: String, expected: String, name: String? = null) {
206206
editorPage.makeLink()
207-
EditLinkPage().updateURL(link)
207+
editorPage.threadSleep(throttleTime)
208+
209+
val editLinkPage = EditLinkPage()
210+
editLinkPage.updateURL(link)
208211
name?.let {
209-
EditLinkPage().updateName(it)
212+
editLinkPage.updateName(it)
210213
}
211-
EditLinkPage().ok()
214+
editLinkPage.ok()
212215

213216
editorPage
214217
.toggleHtml()
215218
.verifyHTML(expected)
216219
.toggleHtml()
217220
.threadSleep(throttleTime)
218221
}
219-
}
222+
}

0 commit comments

Comments
 (0)