Skip to content

Commit 4e8c236

Browse files
Add tests for sendKeys modifier releasing (#161)
1 parent 49df0ed commit 4e8c236

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

Tests/WinAppDriverTests/MSInfo32App.swift

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class MSInfo32App {
1010
init(winAppDriver: WinAppDriver) throws {
1111
let capabilities = WinAppDriver.Capabilities.startApp(name: "\(WindowsSystemPaths.system32)\\msinfo32.exe")
1212
session = try Session(webDriver: winAppDriver, desiredCapabilities: capabilities, requiredCapabilities: capabilities)
13+
session.implicitWaitTimeout = 1
1314
}
1415

1516
private lazy var _maximizeButton = Result {

Tests/WinAppDriverTests/RequestsTests.swift

+45-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@ import TestsCommon
44
import XCTest
55

66
class RequestsTests: XCTestCase {
7-
static var _app: Result<MSInfo32App, any Error>!
8-
var app: MSInfo32App! { get { try? Self._app.get() } }
7+
static var winAppDriver: Result<WinAppDriver, any Error>!
98

109
override class func setUp() {
11-
_app = Result { try MSInfo32App(winAppDriver: WinAppDriver.start()) }
10+
winAppDriver = Result { try WinAppDriver.start() }
1211
}
1312

13+
override class func tearDown() {
14+
winAppDriver = nil
15+
}
16+
17+
var app: MSInfo32App!
18+
1419
override func setUpWithError() throws {
15-
if case .failure(let error) = Self._app {
16-
throw XCTSkip("Failed to start test app: \(error)")
17-
}
20+
app = try MSInfo32App(winAppDriver: Self.winAppDriver.get())
1821
}
1922

20-
override class func tearDown() { _app = nil }
23+
override func tearDown() {
24+
app = nil
25+
}
2126

2227
func testCanGetChildElements() throws {
2328
let children = try XCTUnwrap(app.listView.findElements(locator: .xpath("//ListItem")))
@@ -96,6 +101,39 @@ class RequestsTests: XCTestCase {
96101
try XCTAssert(!Self.hasKeyboardFocus(app.findWhatEditBox))
97102
}
98103

104+
func testSessionSendKeys_scopedModifiers() throws {
105+
try app.findWhatEditBox.click()
106+
try app.session.sendKeys(Keys.shift(Keys.a) + Keys.a)
107+
XCTAssertEqual(try app.findWhatEditBox.text, "Aa")
108+
}
109+
110+
func testSessionSendKeys_autoReleasedModifiers() throws {
111+
try app.findWhatEditBox.click()
112+
try app.session.sendKeys(Keys.shiftModifier + Keys.a)
113+
try app.session.sendKeys(Keys.a)
114+
XCTAssertEqual(try app.findWhatEditBox.text, "Aa")
115+
}
116+
117+
func testSessionSendKeys_stickyModifiers() throws {
118+
try app.findWhatEditBox.click()
119+
try app.session.sendKeys(Keys.shiftModifier + Keys.a, releaseModifiers: false)
120+
try app.session.sendKeys(Keys.a)
121+
try app.session.sendKeys(.releaseModifiers)
122+
try app.session.sendKeys(Keys.a)
123+
XCTAssertEqual(try app.findWhatEditBox.text, "AAa")
124+
}
125+
126+
func testElementSendKeys_scopedModifiers() throws {
127+
try app.findWhatEditBox.sendKeys(Keys.shift(Keys.a) + Keys.a)
128+
XCTAssertEqual(try app.findWhatEditBox.text, "Aa")
129+
}
130+
131+
func testElementSendKeys_autoReleasedModifiers() throws {
132+
try app.findWhatEditBox.sendKeys(Keys.shiftModifier + Keys.a)
133+
try app.findWhatEditBox.sendKeys(Keys.a)
134+
XCTAssertEqual(try app.findWhatEditBox.text, "Aa")
135+
}
136+
99137
private static func hasKeyboardFocus(_ element: Element) throws -> Bool {
100138
try XCTUnwrap(element.getAttribute(name: WinAppDriver.Attributes.hasKeyboardFocus)).lowercased() == "true"
101139
}

0 commit comments

Comments
 (0)