@@ -4,20 +4,25 @@ import TestsCommon
4
4
import XCTest
5
5
6
6
class RequestsTests : XCTestCase {
7
- static var _app : Result < MSInfo32App , any Error > !
8
- var app : MSInfo32App ! { get { try ? Self . _app. get ( ) } }
7
+ static var winAppDriver : Result < WinAppDriver , any Error > !
9
8
10
9
override class func setUp( ) {
11
- _app = Result { try MSInfo32App ( winAppDriver : WinAppDriver . start ( ) ) }
10
+ winAppDriver = Result { try WinAppDriver . start ( ) }
12
11
}
13
12
13
+ override class func tearDown( ) {
14
+ winAppDriver = nil
15
+ }
16
+
17
+ var app : MSInfo32App !
18
+
14
19
override func setUpWithError( ) throws {
15
- if case . failure( let error) = Self . _app {
16
- throw XCTSkip ( " Failed to start test app: \( error) " )
17
- }
20
+ app = try MSInfo32App ( winAppDriver: Self . winAppDriver. get ( ) )
18
21
}
19
22
20
- override class func tearDown( ) { _app = nil }
23
+ override func tearDown( ) {
24
+ app = nil
25
+ }
21
26
22
27
func testCanGetChildElements( ) throws {
23
28
let children = try XCTUnwrap ( app. listView. findElements ( locator: . xpath( " //ListItem " ) ) )
@@ -96,6 +101,39 @@ class RequestsTests: XCTestCase {
96
101
try XCTAssert ( !Self. hasKeyboardFocus ( app. findWhatEditBox) )
97
102
}
98
103
104
+ func testSessionSendKeys_scopedModifiers( ) throws {
105
+ try app. findWhatEditBox. click ( )
106
+ try app. session. sendKeys ( Keys . shift ( Keys . a) + Keys. a)
107
+ XCTAssertEqual ( try app. findWhatEditBox. text, " Aa " )
108
+ }
109
+
110
+ func testSessionSendKeys_autoReleasedModifiers( ) throws {
111
+ try app. findWhatEditBox. click ( )
112
+ try app. session. sendKeys ( Keys . shiftModifier + Keys. a)
113
+ try app. session. sendKeys ( Keys . a)
114
+ XCTAssertEqual ( try app. findWhatEditBox. text, " Aa " )
115
+ }
116
+
117
+ func testSessionSendKeys_stickyModifiers( ) throws {
118
+ try app. findWhatEditBox. click ( )
119
+ try app. session. sendKeys ( Keys . shiftModifier + Keys. a, releaseModifiers: false )
120
+ try app. session. sendKeys ( Keys . a)
121
+ try app. session. sendKeys ( . releaseModifiers)
122
+ try app. session. sendKeys ( Keys . a)
123
+ XCTAssertEqual ( try app. findWhatEditBox. text, " AAa " )
124
+ }
125
+
126
+ func testElementSendKeys_scopedModifiers( ) throws {
127
+ try app. findWhatEditBox. sendKeys ( Keys . shift ( Keys . a) + Keys. a)
128
+ XCTAssertEqual ( try app. findWhatEditBox. text, " Aa " )
129
+ }
130
+
131
+ func testElementSendKeys_autoReleasedModifiers( ) throws {
132
+ try app. findWhatEditBox. sendKeys ( Keys . shiftModifier + Keys. a)
133
+ try app. findWhatEditBox. sendKeys ( Keys . a)
134
+ XCTAssertEqual ( try app. findWhatEditBox. text, " Aa " )
135
+ }
136
+
99
137
private static func hasKeyboardFocus( _ element: Element ) throws -> Bool {
100
138
try XCTUnwrap ( element. getAttribute ( name: WinAppDriver . Attributes. hasKeyboardFocus) ) . lowercased ( ) == " true "
101
139
}
0 commit comments