diff --git a/Sources/SwiftWebDriver/WebDriver.swift b/Sources/SwiftWebDriver/WebDriver.swift index f35eb9a..3364eeb 100644 --- a/Sources/SwiftWebDriver/WebDriver.swift +++ b/Sources/SwiftWebDriver/WebDriver.swift @@ -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 Foundation import NIOCore @@ -133,7 +130,11 @@ public class WebDriver { } @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) + } } diff --git a/Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift b/Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift index 1d27aa1..6ad2ac3 100644 --- a/Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift +++ b/Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift @@ -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 @@ -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 diff --git a/Sources/SwiftWebDriver/WebDrivers/Driver.swift b/Sources/SwiftWebDriver/WebDrivers/Driver.swift index 87d6637..e8e1069 100644 --- a/Sources/SwiftWebDriver/WebDrivers/Driver.swift +++ b/Sources/SwiftWebDriver/WebDrivers/Driver.swift @@ -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 @@ -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 } diff --git a/Tests/SwiftWebDriverIntegrationTests/ChromeDriver/Element/ChromeDriverGetPropertyIntegrationTests.swift b/Tests/SwiftWebDriverIntegrationTests/ChromeDriver/Element/ChromeDriverGetPropertyIntegrationTests.swift new file mode 100644 index 0000000..0ad1f1c --- /dev/null +++ b/Tests/SwiftWebDriverIntegrationTests/ChromeDriver/Element/ChromeDriverGetPropertyIntegrationTests.swift @@ -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 {} +}