Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Jul 3, 2024
1 parent 04f6a3c commit 0344624
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Sources/WebDriver/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Session {
public let id: String
public let capabilities: Capabilities
private var _implicitWaitTimeout: TimeInterval = 0
private var emulateImplicitWait: Bool = false // Set if the session doesn't support implicit waits.
internal var emulateImplicitWait: Bool = false // Set if the session doesn't support implicit waits.
private var shouldDelete: Bool = true

public init(webDriver: any WebDriver, existingId: String, capabilities: Capabilities = Capabilities(), owned: Bool = false) {
Expand Down Expand Up @@ -35,8 +35,9 @@ public class Session {
if !emulateImplicitWait {
do {
try setTimeout(type: TimeoutType.implicitWait, duration: newValue)
} catch {
emulateImplicitWait = true
} catch {}
}
}
_implicitWaitTimeout = newValue
}
Expand Down
15 changes: 9 additions & 6 deletions Tests/WinAppDriverTests/TimeoutTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import WinAppDriver
@testable import WebDriver
import XCTest

class TimeoutTests: XCTestCase {
Expand Down Expand Up @@ -33,25 +34,27 @@ class TimeoutTests: XCTestCase {
return Double(after.uptimeNanoseconds - before.uptimeNanoseconds) / 1_000_000_000
}

public func testLibraryImplicitWait() throws {
public func testWebDriverImplicitWait() throws {
let session = try startApp()

// Test library timeout implementation
session.implicitWaitTimeout = 1
XCTAssert(try Self.time({ _ = try session.findElement(byAccessibilityId: "IdThatDoesNotExist") }) > 0.5)

session.implicitWaitTimeout = 0
XCTAssert(try Self.time({ _ = try session.findElement(byAccessibilityId: "IdThatDoesNotExist") }) < 0.5)

XCTAssert(!session.emulateImplicitWait)
}

public func testWebDriverImplicitWait() throws {
public func testEmulatedImplicitWait() throws {
let session = try startApp()
session.implicitWaitTimeout = 0

try session.setTimeout(type: TimeoutType.implicitWait, duration: 1)
// Test library timeout implementation
session.emulateImplicitWait = true
session.implicitWaitTimeout = 1
XCTAssert(try Self.time({ _ = try session.findElement(byAccessibilityId: "IdThatDoesNotExist") }) > 0.5)

try session.setTimeout(type: TimeoutType.implicitWait, duration: 0)
session.implicitWaitTimeout = 0
XCTAssert(try Self.time({ _ = try session.findElement(byAccessibilityId: "IdThatDoesNotExist") }) < 0.5)
}
}

0 comments on commit 0344624

Please sign in to comment.