1
+ import { createAppiumWebDriver , windowsNativeAppCapabilities } from 'selenium-appium'
2
+ import { By } from 'selenium-webdriver'
3
+ jest . setTimeout ( 50000 ) ;
4
+
5
+ const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
6
+ const driver = createAppiumWebDriver ( windowsNativeAppCapabilities ( calculatorAppId ) )
7
+
8
+ beforeAll ( ( ) => {
9
+ return driver . start ( ) ;
10
+ } ) ;
11
+
12
+ afterAll ( ( ) => {
13
+ return driver . stop ( ) ;
14
+ } ) ;
15
+
16
+ async function getCalculatorResultText ( ) {
17
+ const text = await driver . getByAccessibilityId ( 'CalculatorResults' ) . getText ( ) ;
18
+ return text . replace ( 'Display is' , '' ) . trim ( ) ;
19
+ }
20
+
21
+ describe ( 'Addition' , ( ) => {
22
+ // Applies only to tests in this describe block
23
+ beforeEach ( async ( ) => {
24
+ await driver . getByName ( 'Clear' ) . clear ( ) ;
25
+ } ) ;
26
+
27
+ test ( 'Addition' , async ( ) => {
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 ( ) ;
33
+ expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
34
+ } ) ;
35
+
36
+ test ( 'Division' , async ( ) => {
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 ( ) ;
44
+ expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
45
+ } ) ;
46
+
47
+ test ( 'Multiplication' , async ( ) => {
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 ( ) ;
53
+ expect ( await getCalculatorResultText ( ) ) . toBe ( '81' ) ;
54
+ } ) ;
55
+
56
+
57
+
58
+ test ( 'Subtraction' , async ( ) => {
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 ( ) ;
64
+ expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
65
+ } ) ;
66
+ } ) ;
0 commit comments