Skip to content

Commit

Permalink
Add tests for sendKeys modifier releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Oct 26, 2024
1 parent 49df0ed commit 6e22e08
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 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
60 changes: 49 additions & 11 deletions Tests/WinAppDriverTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ 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 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)
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 6e22e08

Please sign in to comment.