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
10 changes: 8 additions & 2 deletions Sources/SwiftWebDriver/WebDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 @@ -43,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 @@ -57,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 @@ -79,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 @@ -134,7 +134,13 @@
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)
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func getProperty(element: Element, propertyName: String) async throws -> PostExecuteResponse {
try await driver.getProperty(element: element, propertyName: propertyName)
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func setProperty(element: Element, propertyName: String, newValue: String) async throws {
try await driver.setProperty(element: element, propertyName: propertyName, newValue: newValue)
}
}
17 changes: 15 additions & 2 deletions Sources/SwiftWebDriver/WebDrivers/Chrome/ChromeDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,29 @@ public class ChromeDriver: Driver {
try await execute(script, args: args, type: .sync)
}

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

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

public func setProperty(element: Element, propertyName: String,
newValue: String) async throws
{
let script = "arguments[0][arguments[1]] = arguments[2];"
let args: [AnyEncodable] = [
AnyEncodable(["element-6066-11e4-a52e-4f735466cecf": element.elementId]),
AnyEncodable(propertyName),
AnyEncodable(newValue)
]

try await execute(script, args: args, type: .sync)
}

deinit {
let url = url
let sessionId = sessionId
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftWebDriver/WebDrivers/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ public protocol Driver: FindElementProtocol {

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

func getProperty(element: Element, property: String) async throws -> PostExecuteResponse
func getProperty(element: Element, propertyName: String) async throws -> PostExecuteResponse

func setProperty(element: Element, propertyName: String, newValue: String) async throws
}
20 changes: 12 additions & 8 deletions TestAssets/elementHandleTestPage.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>

<head>
<title>expect title</title>
<script>
Expand All @@ -8,29 +9,32 @@
}

function startTimer() {
window.setTimeout(function(){
window.setTimeout(function () {
let element = document.getElementById("willAppendChild")
let newElement = document.createElement('p')
newElement.textContent = 'async add element'
newElement.id = "asyncAddElement"
element.appendChild(newElement)
}, 2000)
}
window.setTimeout(function(){

window.setTimeout(function () {
let element = document.getElementById("willDelete")
element.remove()
}, 2000)
</script>
</head>

<body>
<button id="button" onclick="onClick()"></button>
<input type="text" id="attribute" value="expect attribute">
<div id="setproperty"></div>
<input type="text" id="clearInputValue" value="clearInputValue">
<input id="sendValue" type="text" value="">
<div id="willAppendChild" />
<button id="startButton" onclick="startTimer()">start</button>
<button id="willDelete" >Deleting</button>
<input id="sendValue" type="text" value="">

<div id="willAppendChild" />
<button id="startButton" onclick="startTimer()">start</button>
<button id="willDelete">Deleting</button>
</body>

</html>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ChromeDriverPropertyIntegrationTests.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 Property Integration Tests", .serialized)
internal class ChromeDriverPropertyIntegrationTests: 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, propertyName: "value").value?.stringValue
else {
#expect(Bool(false), "Could not convert element value to string value")
return
}

#expect(elementValue == updatedElementValue)
}

@Test("Set Property")
func setProperty() async throws {
page = "elementHandleTestPage.html"
try await driver.navigateTo(urlString: testPageURL.absoluteString)
let element = try await driver.findElement(.css(.id("setproperty")))
let newPropertyValue = "element new inner text"

try await driver.setProperty(element: element, propertyName: "innerText", newValue: newPropertyValue)
guard
let elementInnerTextValue = try await driver.getProperty(element: element, propertyName: "innerText").value?
.stringValue
else {
#expect(Bool(false), "Could not convert element innerText value to string value")
return
}

#expect(newPropertyValue == elementInnerTextValue)
}

deinit {}
}
Loading