Skip to content

Commit

Permalink
Make Session.windowHandle(s) into properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Feb 26, 2024
1 parent 4d3408c commit dff6c50
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Docs/SupportedAPIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ Contributions to expand support to unimplemented functionality are always welcom
| POST | `/session/:sessionId/window/:windowHandle/position` | Supported | Not implemented |
| GET | `/session/:sessionId/window/:windowHandle/position` | Supported | Not implemented |
| POST | `/session/:sessionId/window/:windowHandle/maximize` | Supported | Not implemented |
| GET | `/session/:sessionId/window_handle` | Supported | `Session.windowHandle()`|
| GET | `/session/:sessionId/window_handles` | Supported | `Session.windowHandles()`|
| GET | `/session/:sessionId/window_handle` | Supported | `Session.windowHandle`|
| GET | `/session/:sessionId/window_handles` | Supported | `Session.windowHandles`|
16 changes: 10 additions & 6 deletions Sources/WebDriver/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,19 @@ public class Session {
}

/// - Returns: Current window handle
public func windowHandle() throws -> String {
let response = try webDriver.send(Requests.SessionWindowHandle(session: id))
return response.value
public var windowHandle: String {
get throws {
let response = try webDriver.send(Requests.SessionWindowHandle(session: id))
return response.value
}
}

/// - Returns: Array of window handles
public func windowHandles() throws -> [String] {
let response = try webDriver.send(Requests.SessionWindowHandles(session: id))
return response.value
public func windowHandles: [String] {
get throws {
let response = try webDriver.send(Requests.SessionWindowHandles(session: id))
return response.value
}
}

/// Deletes the current session.
Expand Down
4 changes: 2 additions & 2 deletions Tests/UnitTests/APIToRequestMappingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class APIToRequestMappingTests: XCTestCase {
mockWebDriver.expect(path: "session/mySession/window_handle", method: .get, type: Requests.SessionWindowHandle.self) {
ResponseWithValue(.init("myWindow"))
}
XCTAssert(try session.windowHandle() == "myWindow")
XCTAssert(try session.windowHandle == "myWindow")
}

func testWindowHandles() throws {
Expand All @@ -231,7 +231,7 @@ class APIToRequestMappingTests: XCTestCase {
mockWebDriver.expect(path: "session/mySession/window_handles", method: .get, type: Requests.SessionWindowHandles.self) {
ResponseWithValue(.init(["myWindow", "myWindow"]))
}
XCTAssert(try session.windowHandles() == ["myWindow", "myWindow"])
XCTAssert(try session.windowHandles == ["myWindow", "myWindow"])
}

func testSessionSource() throws {
Expand Down

0 comments on commit dff6c50

Please sign in to comment.