From 6e22e08250bac78de2a687069a4cc395b6903913 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Sat, 26 Oct 2024 14:38:53 -0400 Subject: [PATCH] Add tests for sendKeys modifier releasing --- Tests/WinAppDriverTests/MSInfo32App.swift | 1 + Tests/WinAppDriverTests/RequestsTests.swift | 60 +++++++++++++++++---- 2 files changed, 50 insertions(+), 11 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..5ab0c8c 100644 --- a/Tests/WinAppDriverTests/RequestsTests.swift +++ b/Tests/WinAppDriverTests/RequestsTests.swift @@ -4,26 +4,31 @@ 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 func setUpWithError() throws { - if case .failure(let error) = Self._app { - throw XCTSkip("Failed to start test app: \(error)") - } + override class func tearDown() { + winAppDriver = nil } - override class func tearDown() { _app = nil } + var app: MSInfo32App! + + override func setUpWithError() throws { + app = try MSInfo32App(winAppDriver: Self.winAppDriver.get()) + } - func testCanGetChildElements() throws { - let children = try XCTUnwrap(app.listView.findElements(locator: .xpath("//ListItem"))) - XCTAssert(children.count > 0) + override func tearDown() { + app = nil } + // func testCanGetChildElements() throws { + // let children = try XCTUnwrap(app.listView.findElements(locator: .xpath("//ListItem"))) + // XCTAssert(children.count > 0) + // } + func testStatusReportsWinAppDriverOnWindows() throws { let status = try XCTUnwrap(app.session.webDriver.status) XCTAssertNotNil(status.build?.version) @@ -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" }