Skip to content

Commit

Permalink
Add tests for sendKeys modifier releasing (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Oct 26, 2024
1 parent 49df0ed commit 4e8c236
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions Tests/WinAppDriverTests/MSInfo32App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 45 additions & 7 deletions Tests/WinAppDriverTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import TestsCommon
import XCTest

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

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")))
Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit 4e8c236

Please sign in to comment.