Skip to content

Commit

Permalink
Merge pull request #17536 from wordpress-mobile/reader-ui-tests-clean
Browse files Browse the repository at this point in the history
Add UI tests to check the ability to scroll reader content and interact with the items
  • Loading branch information
tiagomar authored Nov 26, 2021
2 parents 8815a01 + 40ba38f commit 8ceb016
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
38 changes: 38 additions & 0 deletions WordPress/UITestsFoundation/Screens/ReaderScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@ public class ReaderScreen: ScreenObject {
)
}

public func openLastPost() {
getLastPost().tap()
}

public func openLastPostInSafari() {
getLastPost().buttons["More"].tap()
app.buttons["Visit"].tap()
}

public func getLastPost() -> XCUIElement {
guard let post = app.cells.lastMatch else { fatalError("ReaderScreen: No posts loaded") }
scrollDownUntilElementIsHittable(element: post)
return post
}

private func scrollDownUntilElementIsHittable(element: XCUIElement) {
var loopCount = 0
while !element.waitForIsHittable(timeout: 3) && loopCount < 10 {
loopCount += 1
app.swipeUp(velocity: .fast)
}
}

public func postContentEquals(_ expected: String) -> Bool {
let equalsPostContent = NSPredicate(format: "label == %@", expected)
let isPostContentEqual = app.staticTexts.element(matching: equalsPostContent).waitForIsHittable(timeout: 3)

return isPostContentEqual
}

public func dismissPost() {
let backButton = app.buttons["Back"]
let dismissButton = app.buttons["Dismiss"]

if dismissButton.isHittable { dismissButton.tap() }
if backButton.isHittable { backButton.tap() }
}

public static func isLoaded() -> Bool {
(try? ReaderScreen().isLoaded) ?? false
}
Expand Down
4 changes: 4 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,7 @@
E6F2788421BC1A4A008B4DB5 /* PlanFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F2787E21BC1A49008B4DB5 /* PlanFeature.swift */; };
E6FACB1E1EC675E300284AC7 /* GravatarProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FACB1D1EC675E300284AC7 /* GravatarProfile.swift */; };
E8DEE110E4BC3FA1974AB1BB /* Pods_WordPressTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B921F5DD9A1F257C792EC225 /* Pods_WordPressTest.framework */; };
EAB10E4027487F5D000DA4C1 /* ReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */; };
F10465142554260600655194 /* BindableTapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F10465132554260600655194 /* BindableTapGestureRecognizer.swift */; };
F10D634F26F0B78E00E46CC7 /* Blog+Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F10D634E26F0B78E00E46CC7 /* Blog+Organization.swift */; };
F10D635026F0B78E00E46CC7 /* Blog+Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F10D634E26F0B78E00E46CC7 /* Blog+Organization.swift */; };
Expand Down Expand Up @@ -7322,6 +7323,7 @@
E6F2787E21BC1A49008B4DB5 /* PlanFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanFeature.swift; sourceTree = "<group>"; };
E6FACB1D1EC675E300284AC7 /* GravatarProfile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GravatarProfile.swift; sourceTree = "<group>"; };
E850CD4B77CF21E683104B5A /* Pods-WordPressStatsWidgets.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressStatsWidgets.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressStatsWidgets/Pods-WordPressStatsWidgets.debug.xcconfig"; sourceTree = "<group>"; };
EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderTests.swift; sourceTree = "<group>"; };
EEF80689364FA9CAE10405E8 /* Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressNotificationServiceExtension/Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig"; sourceTree = "<group>"; };
EF379F0A70B6AC45330EE287 /* Pods-WordPressTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressTest.release.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressTest/Pods-WordPressTest.release.xcconfig"; sourceTree = "<group>"; };
F10465132554260600655194 /* BindableTapGestureRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BindableTapGestureRecognizer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -13111,6 +13113,7 @@
BEA101B61FF13F0500CE5C7D /* Tests */ = {
isa = PBXGroup;
children = (
EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */,
6E5BA46826A59D620043A6F2 /* SupportScreenTests.swift */,
FF2716911CAAC87B0006E2D4 /* LoginTests.swift */,
CC7CB97222B1510900642EE9 /* SignupTests.swift */,
Expand Down Expand Up @@ -20735,6 +20738,7 @@
buildActionMask = 2147483647;
files = (
FFA0B7D71CAC1F9F00533B9D /* MainNavigationTests.swift in Sources */,
EAB10E4027487F5D000DA4C1 /* ReaderTests.swift in Sources */,
BED4D8301FF11DEF00A11345 /* EditorAztecTests.swift in Sources */,
3F2F856326FAF612000FCDA5 /* EditorGutenbergTests.swift in Sources */,
FF2716921CAAC87B0006E2D4 /* LoginTests.swift in Sources */,
Expand Down
36 changes: 36 additions & 0 deletions WordPress/WordPressUITests/Tests/ReaderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import UITestsFoundation
import XCTest

class ReaderTests: XCTestCase {
private var readerScreen: ReaderScreen!

override func setUpWithError() throws {
setUpTestSuite()

_ = try LoginFlow.loginIfNeeded(siteUrl: WPUITestCredentials.testWPcomSiteAddress, email: WPUITestCredentials.testWPcomUserEmail, password: WPUITestCredentials.testWPcomPassword)
readerScreen = try EditorFlow
.goToMySiteScreen()
.tabBar.goToReaderScreen()
}

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
if readerScreen != nil && !TabNavComponent.isVisible() {
readerScreen.dismissPost()
}
try LoginFlow.logoutIfNeeded()
try super.tearDownWithError()
}

let expectedPostContent = "Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis. Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis. Proin dictum non ligula aliquam varius. Nam ornare accumsan ante, sollicitudin bibendum erat bibendum nec. Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis."

func testViewPost() {
readerScreen.openLastPost()
XCTAssert(readerScreen.postContentEquals(expectedPostContent))
}

func testViewPostInSafari() {
readerScreen.openLastPostInSafari()
XCTAssert(readerScreen.postContentEquals(expectedPostContent))
}
}

0 comments on commit 8ceb016

Please sign in to comment.