Skip to content

Commit 0862fb3

Browse files
feat: added UI Test for the add to bag flow
1 parent 8a24b7b commit 0862fb3

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "2620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
</BuildAction>
10+
<TestAction
11+
buildConfiguration = "Debug"
12+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
13+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
14+
shouldUseLaunchSchemeArgsEnv = "YES"
15+
shouldAutocreateTestPlan = "YES">
16+
<Testables>
17+
<TestableReference
18+
skipped = "NO"
19+
parallelizable = "YES">
20+
<BuildableReference
21+
BuildableIdentifier = "primary"
22+
BlueprintIdentifier = "BE8B023D2B616979007AE489"
23+
BuildableName = "AlfieUITests.xctest"
24+
BlueprintName = "AlfieUITests"
25+
ReferencedContainer = "container:Alfie.xcodeproj">
26+
</BuildableReference>
27+
</TestableReference>
28+
</Testables>
29+
</TestAction>
30+
<LaunchAction
31+
buildConfiguration = "Debug"
32+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
33+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
34+
launchStyle = "0"
35+
useCustomWorkingDirectory = "NO"
36+
ignoresPersistentStateOnLaunch = "NO"
37+
debugDocumentVersioning = "YES"
38+
debugServiceExtension = "internal"
39+
allowLocationSimulation = "YES">
40+
</LaunchAction>
41+
<ProfileAction
42+
buildConfiguration = "Release"
43+
shouldUseLaunchSchemeArgsEnv = "YES"
44+
savedToolIdentifier = ""
45+
useCustomWorkingDirectory = "NO"
46+
debugDocumentVersioning = "YES">
47+
</ProfileAction>
48+
<AnalyzeAction
49+
buildConfiguration = "Debug">
50+
</AnalyzeAction>
51+
<ArchiveAction
52+
buildConfiguration = "Release"
53+
revealArchiveInOrganizer = "YES">
54+
</ArchiveAction>
55+
</Scheme>

Alfie/AlfieUITests/AlfieUITests.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)