From 4e8c236830160fc6b57a1f0ece0272bbc42c11a0 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Sat, 26 Oct 2024 14:53:45 -0400 Subject: [PATCH] Add tests for sendKeys modifier releasing (#161) --- Tests/WinAppDriverTests/MSInfo32App.swift | 1 + Tests/WinAppDriverTests/RequestsTests.swift | 52 ++++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Tests/WinAppDriverTests/MSInfo32App.swift b/Tests/WinAppDriverTests/MSInfo32App.swift index eb0db7e..8e0853b 100644 --- a/Tests/WinAppDriverTests/MSInfo32App.swift +++ b/Tests/WinAppDriverTests/MSInfo32App.swift @@ -10,6 +10,7 @@ class MSInfo32App { init(winAppDriver: WinAppDriver) throws { let capabilities = WinAppDriver.Capabilities.startApp(name: "\(WindowsSystemPaths.system32)\\msinfo32.exe") session = try Session(webDriver: winAppDriver, desiredCapabilities: capabilities, requiredCapabilities: capabilities) + session.implicitWaitTimeout = 1 } private lazy var _maximizeButton = Result { diff --git a/Tests/WinAppDriverTests/RequestsTests.swift b/Tests/WinAppDriverTests/RequestsTests.swift index 1d7b577..87ca2a9 100644 --- a/Tests/WinAppDriverTests/RequestsTests.swift +++ b/Tests/WinAppDriverTests/RequestsTests.swift @@ -4,20 +4,25 @@ import TestsCommon import XCTest class RequestsTests: XCTestCase { - static var _app: Result! - var app: MSInfo32App! { get { try? Self._app.get() } } + static var winAppDriver: Result! override class func setUp() { - _app = Result { try MSInfo32App(winAppDriver: WinAppDriver.start()) } + winAppDriver = Result { try WinAppDriver.start() } } + override class func tearDown() { + winAppDriver = nil + } + + var app: MSInfo32App! + override func setUpWithError() throws { - if case .failure(let error) = Self._app { - throw XCTSkip("Failed to start test app: \(error)") - } + app = try MSInfo32App(winAppDriver: Self.winAppDriver.get()) } - override class func tearDown() { _app = nil } + override func tearDown() { + app = nil + } func testCanGetChildElements() throws { let children = try XCTUnwrap(app.listView.findElements(locator: .xpath("//ListItem"))) @@ -96,6 +101,39 @@ class RequestsTests: XCTestCase { try XCTAssert(!Self.hasKeyboardFocus(app.findWhatEditBox)) } + func testSessionSendKeys_scopedModifiers() throws { + try app.findWhatEditBox.click() + try app.session.sendKeys(Keys.shift(Keys.a) + Keys.a) + XCTAssertEqual(try app.findWhatEditBox.text, "Aa") + } + + func testSessionSendKeys_autoReleasedModifiers() throws { + try app.findWhatEditBox.click() + try app.session.sendKeys(Keys.shiftModifier + Keys.a) + try app.session.sendKeys(Keys.a) + XCTAssertEqual(try app.findWhatEditBox.text, "Aa") + } + + func testSessionSendKeys_stickyModifiers() throws { + try app.findWhatEditBox.click() + try app.session.sendKeys(Keys.shiftModifier + Keys.a, releaseModifiers: false) + try app.session.sendKeys(Keys.a) + try app.session.sendKeys(.releaseModifiers) + try app.session.sendKeys(Keys.a) + XCTAssertEqual(try app.findWhatEditBox.text, "AAa") + } + + func testElementSendKeys_scopedModifiers() throws { + try app.findWhatEditBox.sendKeys(Keys.shift(Keys.a) + Keys.a) + XCTAssertEqual(try app.findWhatEditBox.text, "Aa") + } + + func testElementSendKeys_autoReleasedModifiers() throws { + try app.findWhatEditBox.sendKeys(Keys.shiftModifier + Keys.a) + try app.findWhatEditBox.sendKeys(Keys.a) + XCTAssertEqual(try app.findWhatEditBox.text, "Aa") + } + private static func hasKeyboardFocus(_ element: Element) throws -> Bool { try XCTUnwrap(element.getAttribute(name: WinAppDriver.Attributes.hasKeyboardFocus)).lowercased() == "true" }