Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for sendKeys modifier releasing #161

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
tristanlabelle marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading