Skip to content

Commit

Permalink
Fix Session.source to respect standard (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Feb 26, 2024
1 parent 4d3408c commit 57e608a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 1 addition & 6 deletions Sources/WebDriver/Requests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,7 @@ public enum Requests {
public var pathComponents: [String] { ["session", session, "source"] }
public var method: HTTPMethod {.get}

public typealias Response = ResponseWithValue<ResponseValue>

public struct ResponseValue: Codable {
public var source: String
}

public typealias Response = ResponseWithValue<String>
}

// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#status
Expand Down
9 changes: 5 additions & 4 deletions Sources/WebDriver/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@ public class Session {
try webDriver.send(Requests.SessionWindowSize.Post(session: id, windowHandle: handle, width: width, height: height))
}

/// - Returns: The current page source.
public func source() throws -> String {
let response = try webDriver.send(Requests.SessionSource(session: id))
return response.value.source
/// Get the current page source
public var source: String {
get throws {
try webDriver.send(Requests.SessionSource(session: id)).value
}
}

/// - Returns: Current window handle
Expand Down
4 changes: 2 additions & 2 deletions Tests/UnitTests/APIToRequestMappingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class APIToRequestMappingTests: XCTestCase {
let session = Session(webDriver: mockWebDriver, existingId: "mySession")

mockWebDriver.expect(path: "session/mySession/source", method: .get, type: Requests.SessionSource.self) {
ResponseWithValue(.init(source: "currentSource"))
ResponseWithValue("currentSource")
}
XCTAssert(try session.source() == "currentSource")
XCTAssert(try session.source == "currentSource")
}
}

0 comments on commit 57e608a

Please sign in to comment.