From 0344624124f9926487ffd1bef6b23c1d29941523 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 3 Jul 2024 12:00:53 -0400 Subject: [PATCH] Fix tests --- Sources/WebDriver/Session.swift | 5 +++-- Tests/WinAppDriverTests/TimeoutTests.swift | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/WebDriver/Session.swift b/Sources/WebDriver/Session.swift index b199465..b47028b 100644 --- a/Sources/WebDriver/Session.swift +++ b/Sources/WebDriver/Session.swift @@ -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) { @@ -35,8 +35,9 @@ public class Session { if !emulateImplicitWait { do { try setTimeout(type: TimeoutType.implicitWait, duration: newValue) + } catch { emulateImplicitWait = true - } catch {} + } } _implicitWaitTimeout = newValue } diff --git a/Tests/WinAppDriverTests/TimeoutTests.swift b/Tests/WinAppDriverTests/TimeoutTests.swift index df986c0..3f6f60b 100644 --- a/Tests/WinAppDriverTests/TimeoutTests.swift +++ b/Tests/WinAppDriverTests/TimeoutTests.swift @@ -1,4 +1,5 @@ @testable import WinAppDriver +@testable import WebDriver import XCTest class TimeoutTests: XCTestCase { @@ -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) } }