Skip to content

Commit 170d7f4

Browse files
authored
Merge pull request #21143 from wordpress-mobile/test/latest-wip-xcframework-and-ui-tests
Fix failing UI tests after React Native upgrade in Gutenberg
2 parents 551968e + 4530832 commit 170d7f4

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

.buildkite/cache-builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
common_params:
88
# Common plugin settings to use with the `plugins` key.
99
- &common_plugins
10-
- automattic/a8c-ci-toolkit#2.17.0
10+
- automattic/a8c-ci-toolkit#2.18.1
1111
- automattic/git-s3-cache#1.1.4:
1212
bucket: "a8c-repo-mirrors"
1313
repo: "automattic/wordpress-ios/"

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
common_params:
33
# Common plugin settings to use with the `plugins` key.
44
- &common_plugins
5-
- automattic/a8c-ci-toolkit#2.17.0
5+
- automattic/a8c-ci-toolkit#2.18.1
66
- automattic/git-s3-cache#1.1.4:
77
bucket: "a8c-repo-mirrors"
88
repo: "automattic/wordpress-ios/"

.buildkite/release-builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
common_params:
55
# Common plugin settings to use with the `plugins` key.
66
- &common_plugins
7-
- automattic/a8c-ci-toolkit#2.17.0
7+
- automattic/a8c-ci-toolkit#2.18.1
88
- automattic/git-s3-cache#1.1.4:
99
bucket: "a8c-repo-mirrors"
1010
repo: "automattic/wordpress-ios/"

WordPress/UITestsFoundation/Screens/Editor/BlockEditorScreen.swift

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public class BlockEditorScreen: ScreenObject {
5757
public func enterTextInTitle(text: String) -> BlockEditorScreen {
5858
let titleView = app.otherElements["Post title. Empty"].firstMatch // Uses a localized string
5959
XCTAssert(titleView.waitForExistence(timeout: 3), "Title View does not exist!")
60-
61-
titleView.tap()
62-
titleView.typeText(text)
60+
type(text: text, in: titleView)
6361

6462
return self
6563
}
@@ -72,7 +70,7 @@ public class BlockEditorScreen: ScreenObject {
7270
addBlock("Paragraph block")
7371

7472
let paragraphView = app.otherElements["Paragraph Block. Row 1. Empty"].textViews.element(boundBy: 0)
75-
paragraphView.typeText(text)
73+
type(text: text, in: paragraphView)
7674

7775
return self
7876
}
@@ -368,4 +366,44 @@ public class BlockEditorScreen: ScreenObject {
368366
editorCloseButton.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)).tap()
369367
return try BlockEditorScreen()
370368
}
369+
370+
// This could be moved as an XCUIApplication method via an extension if needed elsewhere.
371+
private func type(text: String, in element: XCUIElement) {
372+
// A simple implementation here would be:
373+
//
374+
// element.tap()
375+
// element.typeText(text)
376+
//
377+
// But as of a recent (but not pinpointed at the time of writing) Gutenberg update, that is not enough.
378+
// The test would fail with: Neither element nor any descendant has keyboard focus.
379+
// (E.g.: https://buildkite.com/automattic/wordpress-ios/builds/15598)
380+
//
381+
// The following is a convoluted but seemingly robust approach that bypasses the keyboard by using the pasteboard instead.
382+
UIPasteboard.general.string = text
383+
384+
// Safety check
385+
XCTAssertTrue(element.waitForExistence(timeout: 1))
386+
387+
element.doubleTap()
388+
389+
let pasteButton = app.menuItems["Paste"]
390+
391+
if pasteButton.waitForExistence(timeout: 1) == false {
392+
// Drill in hierarchy looking for it
393+
var found = false
394+
element.descendants(matching: .any).enumerated().forEach { e in
395+
guard found == false else { return }
396+
397+
e.element.firstMatch.doubleTap()
398+
399+
if pasteButton.waitForExistence(timeout: 1) {
400+
found = true
401+
}
402+
}
403+
}
404+
405+
XCTAssertTrue(pasteButton.exists, "Could not find menu item paste button.")
406+
407+
pasteButton.tap()
408+
}
371409
}

0 commit comments

Comments
 (0)