Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Sources/SwiftWebDriver/WebDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.
//
// This package is freely distributable under the MIT license.
// This Package is a modified fork of https://github.com/ashi-psn/SwiftWebDriver.

import Foundation
import NIOCore

public class WebDriver<T: Driver> {

Check warning on line 9 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
private let driver: T

/// init webDriver
Expand Down Expand Up @@ -46,7 +43,7 @@
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func getNavigation() async throws -> GetNavigationResponse {

Check warning on line 46 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
try await driver.getNavigation()
}

Expand All @@ -60,7 +57,7 @@
}

@discardableResult
public func navigateTo(url: URL) async throws -> PostNavigationResponse {

Check warning on line 60 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
try await navigateTo(urlString: url.absoluteString)
}

Expand All @@ -82,17 +79,17 @@

@discardableResult
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func navigationRefresh() async throws -> PostNavigationRefreshResponse {

Check warning on line 82 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
try await driver.postNavigationRefresh()
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func navigationTitle() async throws -> GetNavigationTitleResponse {

Check warning on line 87 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
try await driver.getNavigationTitle()
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func findElement(_ locatorType: LocatorType) async throws -> Element {

Check warning on line 92 in Sources/SwiftWebDriver/WebDriver.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
try await driver.findElement(locatorType)
}

Expand Down Expand Up @@ -133,7 +130,11 @@
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func setAttribute(element: Element, attributeName: String, newValue: String) async throws {
public func setAttribute(element: Element, attributeName: String, newValue: String) async throws {
try await driver.setAttribute(element: element, attributeName: attributeName, newValue: newValue)
}

public func getProperty(element: Element, property: String) async throws -> PostExecuteResponse {
try await driver.getProperty(element: element, property: property)
}
}
13 changes: 10 additions & 3 deletions Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.
//
// This package is freely distributable under the MIT license.
// This Package is a modified fork of https://github.com/ashi-psn/SwiftWebDriver.

import AsyncHTTPClient
import Foundation
Expand Down Expand Up @@ -312,6 +309,16 @@ public class ChromeDriver: Driver {
try await execute(script, args: args, type: .sync)
}

public func getProperty(element: Element, property: String) async throws -> PostExecuteResponse {
let script = "return arguments[0][arguments[1]];"

let args: [AnyEncodable] = [
AnyEncodable(["element-6066-11e4-a52e-4f735466cecf": element.elementId]),
AnyEncodable(property)
]
return try await execute(script, args: args, type: .sync)
}

deinit {
let url = url
let sessionId = sessionId
Expand Down
5 changes: 2 additions & 3 deletions Sources/SwiftWebDriver/WebDrivers/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.
//
// This package is freely distributable under the MIT license.
// This Package is a modified fork of https://github.com/ashi-psn/SwiftWebDriver.

import AsyncHTTPClient
import Foundation
Expand Down Expand Up @@ -51,4 +48,6 @@ public protocol Driver: FindElementProtocol {
func getActiveElement() async throws -> Element

func setAttribute(element: Element, attributeName: String, newValue: String) async throws

func getProperty(element: Element, property: String) async throws -> PostExecuteResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ChromeDriverGetPropertyIntegrationTests.swift
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

@testable import SwiftWebDriver
import Testing

@Suite("Chrome Driver Get Property", .serialized)
internal class ChromeDriverGetPropertyIntegrationTests: ChromeDriverTest {
@Test("Get Property")
func getProperty() async throws {
page = "elementHandleTestPage.html"
try await driver.navigateTo(urlString: testPageURL.absoluteString)
let updatedElementValue = "NewElementValue"
try await driver.execute("""
let element = document.getElementById('attribute')
element.value = '\(updatedElementValue)'
""")
let element = try await driver.findElement(.css(.id("attribute")))
guard
let elementValue = try await driver.getProperty(element: element, property: "value").value?.stringValue
else {
#expect(Bool(false), "Could not convert element value to string value")
return
}

#expect(elementValue == updatedElementValue)
}

deinit {}
}
Loading