@@ -15,12 +15,41 @@ final class AlfieUITests: XCTestCase {
1515 // Put teardown code here. This method is called after the invocation of each test method in the class.
1616 }
1717
18- func testExample( ) throws {
19- // UI tests must launch the application that they test.
18+ func addToCartExample( ) throws {
2019 let app = XCUIApplication ( )
21- app. launch ( )
22-
23- // Use XCTAssert and related functions to verify your tests produce the correct results.
20+ app. activate ( )
21+ 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 ( )
22+ 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 ( )
23+ app/*@START_MENU_TOKEN@*/. buttons [ " 04AugPhilos " ] /*[[".otherElements.buttons[\"04AugPhilos\"]",".buttons[\"04AugPhilos\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/. firstMatch. tap ( )
24+ app. images. matching ( identifier: " product-image " ) . element ( boundBy: 0 ) . tap ( )
25+
26+ // Wait for PDP to load and capture product name from the title header
27+ let addToBagButton = app. buttons [ " Add to bag " ]
28+ XCTAssertTrue ( addToBagButton. waitForExistence ( timeout: 5 ) , " Add to bag button should exist " )
29+
30+ // The product name is shown in the title header - get the first static text in the scroll view content
31+ // which contains the product name (displayed in titleHeader view)
32+ let productNameOnPDP = app. scrollViews. firstMatch. staticTexts. firstMatch
33+ XCTAssertTrue ( productNameOnPDP. waitForExistence ( timeout: 5 ) , " Product name should be visible on PDP " )
34+ let expectedProductName = productNameOnPDP. label
35+
36+ // Tap "Add to bag" button
37+ addToBagButton. tap ( )
38+
39+ // Navigate back from PDP - tap the first button in navigation bar
40+ let backButton = app. navigationBars. buttons. firstMatch
41+ XCTAssertTrue ( backButton. waitForExistence ( timeout: 5 ) , " Back button should exist " )
42+ backButton. tap ( )
43+
44+ // Navigate to bag tab
45+ let bagTab = app. otherElements [ " bag-tab " ]
46+ XCTAssertTrue ( bagTab. waitForExistence ( timeout: 5 ) , " Bag tab should exist " )
47+ bagTab. tap ( )
48+
49+ // Verify the product in the bag matches the one we added
50+ let productNameInBag = app. staticTexts. matching ( identifier: " product-name " ) . firstMatch
51+ XCTAssertTrue ( productNameInBag. waitForExistence ( timeout: 5 ) , " Product name should be visible in bag " )
52+ XCTAssertEqual ( productNameInBag. label, expectedProductName, " Product in bag should match the product that was added " )
2453 }
2554
2655 func testLaunchPerformance( ) throws {
0 commit comments