1
- import { createAppiumWebDriver , windowsNativeAppCapabilities } from 'selenium-appium'
1
+ import { createWebDriver2 , windowsNativeAppCapabilities } from 'selenium-appium'
2
2
import { By } from 'selenium-webdriver'
3
3
jest . setTimeout ( 50000 ) ;
4
4
5
5
const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
6
- const driver = createAppiumWebDriver ( windowsNativeAppCapabilities ( calculatorAppId ) )
6
+ const driver = createWebDriver2 ( windowsNativeAppCapabilities ( calculatorAppId ) )
7
7
8
8
beforeAll ( ( ) => {
9
- return driver . start ( ) ;
9
+ return driver . start ( ) ;
10
10
} ) ;
11
11
12
12
afterAll ( ( ) => {
13
13
return driver . stop ( ) ;
14
14
} ) ;
15
15
16
16
async function getCalculatorResultText ( ) {
17
- const text = await driver . getByAccessibilityId ( 'CalculatorResults' ) . getText ( ) ;
17
+ const text = await driver . getByNativeAccessibilityId ( 'CalculatorResults' ) . getText ( ) ;
18
18
return text . replace ( 'Display is' , '' ) . trim ( ) ;
19
19
}
20
20
21
21
describe ( 'Addition' , ( ) => {
22
22
// Applies only to tests in this describe block
23
23
beforeEach ( async ( ) => {
24
- await driver . getByName ( 'Clear' ) . clear ( ) ;
24
+ await driver . getByNativeName ( 'Clear' ) . clear ( ) ;
25
25
} ) ;
26
26
27
27
test ( 'Addition' , async ( ) => {
28
28
// Find the buttons by their names and click them in sequence to perform 1 + 7 = 8
29
- await driver . getByName ( 'One' ) . click ( ) ;
30
- await driver . getByName ( 'Plus' ) . click ( ) ;
31
- await driver . getByName ( 'Seven' ) . click ( ) ;
32
- await driver . getByName ( 'Equals' ) . click ( ) ;
29
+ await driver . getByNativeName ( 'One' ) . click ( ) ;
30
+ await driver . getByNativeName ( 'Plus' ) . click ( ) ;
31
+ await driver . getByNativeName ( 'Seven' ) . click ( ) ;
32
+ await driver . getByNativeName ( 'Equals' ) . click ( ) ;
33
33
expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
34
34
} ) ;
35
35
36
36
test ( 'Division' , async ( ) => {
37
37
// Find the buttons by their accessibility ids and click them in sequence to perform 88 / 11 = 8
38
- await driver . getByAccessibilityId ( 'num8Button' ) . click ( ) ;
39
- await driver . getByAccessibilityId ( 'num8Button' ) . click ( ) ;
40
- await driver . getByAccessibilityId ( 'divideButton' ) . click ( ) ;
41
- await driver . getByAccessibilityId ( 'num1Button' ) . click ( ) ;
42
- await driver . getByAccessibilityId ( 'num1Button' ) . click ( ) ;
43
- await driver . getByAccessibilityId ( 'equalButton' ) . click ( ) ;
38
+ await driver . getByNativeAccessibilityId ( 'num8Button' ) . click ( ) ;
39
+ await driver . getByNativeAccessibilityId ( 'num8Button' ) . click ( ) ;
40
+ await driver . getByNativeAccessibilityId ( 'divideButton' ) . click ( ) ;
41
+ await driver . getByNativeAccessibilityId ( 'num1Button' ) . click ( ) ;
42
+ await driver . getByNativeAccessibilityId ( 'num1Button' ) . click ( ) ;
43
+ await driver . getByNativeAccessibilityId ( 'equalButton' ) . click ( ) ;
44
44
expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
45
45
} ) ;
46
46
47
47
test ( 'Multiplication' , async ( ) => {
48
48
// Find the buttons by their names using XPath and click them in sequence to perform 9 x 9 = 81
49
- await driver . get ( By . xpath ( "//Button[@Name='Nine']" ) ) . click ( ) ;
50
- await driver . get ( By . xpath ( "//Button[@Name='Multiply by']" ) ) . click ( ) ;
51
- await driver . get ( By . xpath ( "//Button[@Name='Nine']" ) ) . click ( ) ;
52
- await driver . get ( By . xpath ( "//Button[@Name='Equals']" ) ) . click ( ) ;
49
+ await driver . getBy ( By . xpath ( "//Button[@Name='Nine']" ) ) . click ( ) ;
50
+ await driver . getBy ( By . xpath ( "//Button[@Name='Multiply by']" ) ) . click ( ) ;
51
+ await driver . getBy ( By . xpath ( "//Button[@Name='Nine']" ) ) . click ( ) ;
52
+ await driver . getBy ( By . xpath ( "//Button[@Name='Equals']" ) ) . click ( ) ;
53
53
expect ( await getCalculatorResultText ( ) ) . toBe ( '81' ) ;
54
54
} ) ;
55
55
56
56
57
57
58
58
test ( 'Subtraction' , async ( ) => {
59
59
// Find the buttons by their accessibility ids using XPath and click them in sequence to perform 9 - 1 = 8
60
- await driver . get ( By . xpath ( "//Button[@AutomationId=\"num9Button\"]" ) ) . click ( ) ;
61
- await driver . get ( By . xpath ( "//Button[@AutomationId=\"minusButton\"]" ) ) . click ( ) ;
62
- await driver . get ( By . xpath ( "//Button[@AutomationId=\"num1Button\"]" ) ) . click ( ) ;
63
- await driver . get ( By . xpath ( "//Button[@AutomationId=\"equalButton\"]" ) ) . click ( ) ;
60
+ await driver . getBy ( By . xpath ( "//Button[@AutomationId=\"num9Button\"]" ) ) . click ( ) ;
61
+ await driver . getBy ( By . xpath ( "//Button[@AutomationId=\"minusButton\"]" ) ) . click ( ) ;
62
+ await driver . getBy ( By . xpath ( "//Button[@AutomationId=\"num1Button\"]" ) ) . click ( ) ;
63
+ await driver . getBy ( By . xpath ( "//Button[@AutomationId=\"equalButton\"]" ) ) . click ( ) ;
64
64
expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
65
65
} ) ;
66
66
} ) ;
0 commit comments