Skip to content

Commit

Permalink
Merge pull request #6 from ashi-psn/develop
Browse files Browse the repository at this point in the history
modify warning
  • Loading branch information
ashi-psn authored Aug 23, 2022
2 parents 6db3ebc + 77ef89a commit 10eeef2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Foundation

public struct StatusResponse: Codable {
let value: Value
public let value: Value

struct Value: Codable {
let ready: Bool
let message: String
public struct Value: Codable {
public let ready: Bool
public let message: String
}
}
26 changes: 26 additions & 0 deletions Sources/SwiftWebDriver/Element/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import NIO
public protocol FindElementProtocol {
func findElement(_ locatorType: LocatorType) async throws -> Element
func findElements(_ locatorType: LocatorType) async throws -> Elements
func waitUntil(_ locatorType: LocatorType, retryCount: Int, durationSeconds: Int) async throws -> Bool
}

public protocol ElementCommandProtocol: FindElementProtocol {
Expand Down Expand Up @@ -97,4 +98,29 @@ public struct Element: ElementCommandProtocol {
let response = try await APIClient.shared.request(request)
return response.value
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@discardableResult
public func waitUntil(_ locatorType: LocatorType, retryCount: Int = 3, durationSeconds: Int = 1) async throws -> Bool {

do {
let _ = try await findElement(locatorType)
return true
} catch let error {
guard
retryCount > 0,
let error = error as? SeleniumError
else { return false }

guard error.value.error == "no such element" else {
return false
}

let retryCount = retryCount - 1

sleep(UInt32(durationSeconds))

return try await waitUntil(locatorType, retryCount: retryCount, durationSeconds: durationSeconds)
}
}
}
25 changes: 25 additions & 0 deletions Sources/SwiftWebDriver/Element/Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,29 @@ extension Elements {

return elements.flatMap{ $0 }
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@discardableResult
public func waitUntil(_ locatorType: LocatorType, retryCount: Int = 3, durationSeconds: Int = 1) async throws -> Bool {

do {
let _ = try await findElement(locatorType)
return true
} catch let error {
guard
retryCount > 0,
let error = error as? SeleniumError
else { return false }

guard error.value.error == "no such element" else {
return false
}

let retryCount = retryCount - 1

sleep(UInt32(durationSeconds))

return try await waitUntil(locatorType, retryCount: retryCount, durationSeconds: durationSeconds)
}
}
}
1 change: 1 addition & 0 deletions Sources/SwiftWebDriver/WebDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class WebDriver<T: Driver> {
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@discardableResult
public func waitUntil(_ locatorType: LocatorType, retryCount: Int = 3, durationSeconds: Int = 1) async throws -> Bool {
return try await driver.waitUntil(locatorType, retryCount: retryCount, durationSeconds: durationSeconds)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public class ChromeDriver: Driver {
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@discardableResult
public func waitUntil(_ locatorType: LocatorType, retryCount: Int = 3, durationSeconds: Int = 1) async throws -> Bool {

guard let sessionId = sessionId else {
Expand Down

0 comments on commit 10eeef2

Please sign in to comment.