Skip to content

Commit

Permalink
add more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shamanec committed Jul 22, 2023
1 parent 9b831b3 commit 793aa5b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
Binary file not shown.
76 changes: 35 additions & 41 deletions xcuitest-sample-proj/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,50 @@ struct TabBarView: View {
.tabItem {
Label("Loading", systemImage: "star")
}

DisappearButtonView()
.tabItem {
Label("Disappear", systemImage: "star")
}
}
}
}

struct CarouselView: View {
@State private var isButtonVisible = true

var body: some View {
ScrollView(.horizontal) {
LazyHStack(spacing: 16) {
ForEach(1...10, id: \.self) { index in
// Load each carousel item lazily
CarouselItemView(item: index)
VStack {
ScrollView(.horizontal) {
LazyHStack(spacing: 16) {
ForEach(1...10, id: \.self) { index in
// Load each carousel item lazily
CarouselItemView(item: index)
}
}
.padding()
.frame(height: 150)
}
.accessibilityIdentifier("carousel-view")

VStack {
if isButtonVisible {
Button("Disappearing button") {
// Handle the action when the button is tapped
hideButtonAfterDelay()
}
.foregroundColor(.white)
.padding()
.frame(width: 200, height: 50)
.background(Color.blue)
.cornerRadius(12)
.accessibilityIdentifier("disappearing-button")
}
}
.padding()
}
.accessibilityIdentifier("carousel-view")

}

private func hideButtonAfterDelay() {
// Set the button visibility to false after 5 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
isButtonVisible = false
}
}
}

Expand Down Expand Up @@ -76,32 +99,3 @@ struct LoadingElementsView: View {
}
}
}

struct DisappearButtonView: View {
@State private var isButtonVisible = true

var body: some View {
VStack {
if isButtonVisible {
Button("Disappearing button") {
// Handle the action when the button is tapped
hideButtonAfterDelay()
}
.foregroundColor(.white) // Text color
.padding()
.frame(width: 200, height: 50) // Set exact width and height
.background(Color.blue) // Button background color
.cornerRadius(12) // Rounded re
.accessibilityIdentifier("disappearing-button")
}
}
.padding()
}

private func hideButtonAfterDelay() {
// Set the button visibility to false after 5 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
isButtonVisible = false
}
}
}
11 changes: 6 additions & 5 deletions xcuitest-sample-projUITests/xcuitest_sample_projUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import XCTest
final class xcuitest_sample_projUITests: Base {

func testGentleSwipeUntil() {
print(app.debugDescription)
InteractionHelper.performGentleSwipeUntil(app.scrollViews["carousel-view"], .left, 5, until: app.staticTexts["carousel_item10"].exists)
}

Expand All @@ -30,25 +31,25 @@ final class xcuitest_sample_projUITests: Base {
func testElementDisappearsSameScreen() {
app.buttons["Disappear"].tap()
let disappearingButton = app.buttons.element(matching: .button, identifier: "disappearing-button")
XCTAssertTrue(disappearingButton.isVisible)
disappearingButton.tap()
ElementsHelper.waitUntilElementDisappears(element: disappearingButton, timeoutValue: 6)
XCTAssertFalse(disappearingButton.isVisible)
}

func testElementNotExistChangeScreens() {
app.buttons["Disappear"].tap()
let button = app.buttons.element(matching: .button, identifier: "disappearing-button")
XCTAssertTrue(button.exists)
XCTAssertTrue(button.isVisible)
app.buttons["Carousel"].tap()
XCTAssertFalse(button.exists)
}

func testWaitForQueryHaveNumberOfElements() {
app.buttons["Loading"].tap()
let elements = app.staticTexts.matching(identifier: "loaded-el")
// Wait default timeout to have at least 1 element, should pass
ElementsHelper.waitUntilTableFilled(elements: elements)
// Wait for 10 seconds to have 5 elements, should pass
ElementsHelper.waitUntilTableFilled(elements: elements, 5, TestConstants.Timeout.medium)
// Wait for 11 seconds to have 5 elements, should pass
ElementsHelper.waitUntilTableFilled(elements: elements, 11, TestConstants.Timeout.medium)
// Wait 5 more seconds to have 6 elements, should fail because only 5 in total will be loaded
ElementsHelper.waitUntilTableFilled(elements: elements, 6, TestConstants.Timeout.short)
}
Expand Down

0 comments on commit 793aa5b

Please sign in to comment.