From a74f8f01214178b3605a77d4fdabe2702ba76ffc Mon Sep 17 00:00:00 2001 From: jos <17252150+jostnes@users.noreply.github.com> Date: Mon, 5 Dec 2022 18:15:38 +0800 Subject: [PATCH 1/2] add load stats ui test --- .../Screens/MyStore/MyStoreScreen.swift | 42 +++++++++++++++++++ WooCommerce/WooCommerceUITests/README.md | 2 +- .../WooCommerceUITests/Tests/StatsTests.swift | 15 +++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift b/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift index 903914aac41..0291aa9c530 100644 --- a/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift +++ b/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift @@ -27,4 +27,46 @@ public final class MyStoreScreen: ScreenObject { topBannerCloseButton.tap() return self } + + func tapTimeframeTab(timeframe: String) -> MyStoreScreen { + app.cells.staticTexts[timeframe].tap() + + return self + } + + public func goToThisWeekTab() -> MyStoreScreen { + return tapTimeframeTab(timeframe: "This Week") + } + + public func goToThisMonthTab() -> MyStoreScreen { + return tapTimeframeTab(timeframe: "This Month") + } + + public func goToThisYearTab() -> MyStoreScreen { + return tapTimeframeTab(timeframe: "This Year") + } + + func verifyStatsForTimeframeLoaded(timeframe: String) -> MyStoreScreen { + let textPredicate = NSPredicate(format: "label MATCHES %@", "Store revenue chart \(timeframe)") + XCTAssertTrue(app.images.containing(textPredicate).element.exists, "\(timeframe) chart not displayed") + + return self + } + + public func verifyTodayStatsLoaded() -> MyStoreScreen { + return verifyStatsForTimeframeLoaded(timeframe: "Today") + } + + public func verifyThisWeekStatsLoaded() -> MyStoreScreen { + return verifyStatsForTimeframeLoaded(timeframe: "This Week") + } + + public func verifyThisMonthStatsLoaded() -> MyStoreScreen { + return verifyStatsForTimeframeLoaded(timeframe: "This Month") + } + + @discardableResult + public func verifyThisYearStatsLoaded() -> MyStoreScreen { + return verifyStatsForTimeframeLoaded(timeframe: "This Year") + } } diff --git a/WooCommerce/WooCommerceUITests/README.md b/WooCommerce/WooCommerceUITests/README.md index ec16bb495e7..0657e2c1479 100644 --- a/WooCommerce/WooCommerceUITests/README.md +++ b/WooCommerce/WooCommerceUITests/README.md @@ -14,7 +14,7 @@ The following flows are covered/planned to be covered by UI tests. Tests that ar - [ ] Log in with Apple - [ ] Log in with Google 2. My Store - - [ ] Stats Today, This Week, This Month, This Year load + - [x] Stats Today, This Week, This Month, This Year load - [ ] Tap chart on stats 3. Orders - [x] Orders list loads diff --git a/WooCommerce/WooCommerceUITests/Tests/StatsTests.swift b/WooCommerce/WooCommerceUITests/Tests/StatsTests.swift index 2a1fd794a2d..d5c896c7900 100644 --- a/WooCommerce/WooCommerceUITests/Tests/StatsTests.swift +++ b/WooCommerce/WooCommerceUITests/Tests/StatsTests.swift @@ -4,7 +4,6 @@ import XCTest final class StatsTests: XCTestCase { override func setUpWithError() throws { - try skipTillImplemented() continueAfterFailure = false // UI tests must launch the application that they test. @@ -15,12 +14,14 @@ final class StatsTests: XCTestCase { try LoginFlow.logInWithWPcom() } - func skipped_test_load_stats_screen() throws { + func test_load_stats_screen() throws { try TabNavComponent().goToMyStoreScreen() - } - - func skipTillImplemented(file: StaticString = #file, line: UInt = #line) throws { - try XCTSkipIf(true, - "Skipping until test is properly implemented", file: file, line: line) + .verifyTodayStatsLoaded() + .goToThisWeekTab() + .verifyThisWeekStatsLoaded() + .goToThisMonthTab() + .verifyThisMonthStatsLoaded() + .goToThisYearTab() + .verifyThisYearStatsLoaded() } } From 27a1d7c2ea79251ad3e836ffa68ba2db740c24b1 Mon Sep 17 00:00:00 2001 From: jos <17252150+jostnes@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:10:45 +0800 Subject: [PATCH 2/2] use accessibilityId instead of staticTexts --- .../Screens/MyStore/MyStoreScreen.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift b/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift index 0291aa9c530..b60a3642813 100644 --- a/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift +++ b/WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift @@ -28,22 +28,22 @@ public final class MyStoreScreen: ScreenObject { return self } - func tapTimeframeTab(timeframe: String) -> MyStoreScreen { - app.cells.staticTexts[timeframe].tap() + func tapTimeframeTab(timeframeId: String) -> MyStoreScreen { + app.cells[timeframeId].tap() return self } public func goToThisWeekTab() -> MyStoreScreen { - return tapTimeframeTab(timeframe: "This Week") + return tapTimeframeTab(timeframeId: "period-data-thisWeek-tab") } public func goToThisMonthTab() -> MyStoreScreen { - return tapTimeframeTab(timeframe: "This Month") + return tapTimeframeTab(timeframeId: "period-data-thisMonth-tab") } public func goToThisYearTab() -> MyStoreScreen { - return tapTimeframeTab(timeframe: "This Year") + return tapTimeframeTab(timeframeId: "period-data-thisYear-tab") } func verifyStatsForTimeframeLoaded(timeframe: String) -> MyStoreScreen {