From 0862fb37efebaa8f72a8693d14eeaaa9d59deda8 Mon Sep 17 00:00:00 2001 From: Paul Vasile Date: Tue, 23 Dec 2025 09:49:16 +0200 Subject: [PATCH 1/2] feat: added UI Test for the add to bag flow --- .../xcschemes/AlfieUITests.xcscheme | 55 +++++++++++++++++++ Alfie/AlfieUITests/AlfieUITests.swift | 39 +++++++++++-- 2 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 Alfie/Alfie.xcodeproj/xcshareddata/xcschemes/AlfieUITests.xcscheme diff --git a/Alfie/Alfie.xcodeproj/xcshareddata/xcschemes/AlfieUITests.xcscheme b/Alfie/Alfie.xcodeproj/xcshareddata/xcschemes/AlfieUITests.xcscheme new file mode 100644 index 00000000..8f26b66a --- /dev/null +++ b/Alfie/Alfie.xcodeproj/xcshareddata/xcschemes/AlfieUITests.xcscheme @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Alfie/AlfieUITests/AlfieUITests.swift b/Alfie/AlfieUITests/AlfieUITests.swift index 08a14c22..2fe25a99 100644 --- a/Alfie/AlfieUITests/AlfieUITests.swift +++ b/Alfie/AlfieUITests/AlfieUITests.swift @@ -15,12 +15,41 @@ final class AlfieUITests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. } - func testExample() throws { - // UI tests must launch the application that they test. + func addToCartExample() throws { let app = XCUIApplication() - app.launch() - - // Use XCTAssert and related functions to verify your tests produce the correct results. + app.activate() + app/*@START_MENU_TOKEN@*/.images["storefront"]/*[[".otherElements[\"shop-tab\"].images",".otherElements.images[\"storefront\"]",".images[\"storefront\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap() + app/*@START_MENU_TOKEN@*/.scrollViews.buttons["Brands"].firstMatch/*[[".buttons",".matching(identifier: \"Brands\")",".element(boundBy: 1)",".containing(.staticText, identifier: \"Brands\").firstMatch",".matching(identifier: \"category-item\").containing(.staticText, identifier: \"Brands\").firstMatch",".scrollViews.buttons[\"Brands\"].firstMatch"],[[[-1,5],[-1,0,1]],[[-1,3],[-1,4],[-1,1,2]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/.tap() + app/*@START_MENU_TOKEN@*/.buttons["04AugPhilos"]/*[[".otherElements.buttons[\"04AugPhilos\"]",".buttons[\"04AugPhilos\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap() + app.images.matching(identifier: "product-image").element(boundBy: 0).tap() + + // Wait for PDP to load and capture product name from the title header + let addToBagButton = app.buttons["Add to bag"] + XCTAssertTrue(addToBagButton.waitForExistence(timeout: 5), "Add to bag button should exist") + + // The product name is shown in the title header - get the first static text in the scroll view content + // which contains the product name (displayed in titleHeader view) + let productNameOnPDP = app.scrollViews.firstMatch.staticTexts.firstMatch + XCTAssertTrue(productNameOnPDP.waitForExistence(timeout: 5), "Product name should be visible on PDP") + let expectedProductName = productNameOnPDP.label + + // Tap "Add to bag" button + addToBagButton.tap() + + // Navigate back from PDP - tap the first button in navigation bar + let backButton = app.navigationBars.buttons.firstMatch + XCTAssertTrue(backButton.waitForExistence(timeout: 5), "Back button should exist") + backButton.tap() + + // Navigate to bag tab + let bagTab = app.otherElements["bag-tab"] + XCTAssertTrue(bagTab.waitForExistence(timeout: 5), "Bag tab should exist") + bagTab.tap() + + // Verify the product in the bag matches the one we added + let productNameInBag = app.staticTexts.matching(identifier: "product-name").firstMatch + XCTAssertTrue(productNameInBag.waitForExistence(timeout: 5), "Product name should be visible in bag") + XCTAssertEqual(productNameInBag.label, expectedProductName, "Product in bag should match the product that was added") } func testLaunchPerformance() throws { From c2f032970789ab67e1f358a078bce210e1861daf Mon Sep 17 00:00:00 2001 From: Paul Vasile Date: Tue, 23 Dec 2025 09:57:07 +0200 Subject: [PATCH 2/2] fix: naming issue --- Alfie/AlfieUITests/AlfieUITests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Alfie/AlfieUITests/AlfieUITests.swift b/Alfie/AlfieUITests/AlfieUITests.swift index 2fe25a99..cac0e55f 100644 --- a/Alfie/AlfieUITests/AlfieUITests.swift +++ b/Alfie/AlfieUITests/AlfieUITests.swift @@ -15,7 +15,7 @@ final class AlfieUITests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. } - func addToCartExample() throws { + func testAddToCartFullFlow() throws { let app = XCUIApplication() app.activate() app/*@START_MENU_TOKEN@*/.images["storefront"]/*[[".otherElements[\"shop-tab\"].images",".otherElements.images[\"storefront\"]",".images[\"storefront\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()