1- import { createAppiumWebDriver , windowsNativeAppCapabilities } from 'selenium-appium'
1+ import { createWebDriver2 , windowsNativeAppCapabilities } from 'selenium-appium'
22import { By } from 'selenium-webdriver'
33jest . setTimeout ( 50000 ) ;
44
55const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
6- const driver = createAppiumWebDriver ( windowsNativeAppCapabilities ( calculatorAppId ) )
6+ const driver = createWebDriver2 ( windowsNativeAppCapabilities ( calculatorAppId ) )
77
88beforeAll ( ( ) => {
9- return driver . start ( ) ;
9+ return driver . start ( ) ;
1010} ) ;
1111
1212afterAll ( ( ) => {
1313 return driver . stop ( ) ;
1414} ) ;
1515
1616async function getCalculatorResultText ( ) {
17- const text = await driver . getByAccessibilityId ( 'CalculatorResults' ) . getText ( ) ;
17+ const text = await driver . getByNativeAccessibilityId ( 'CalculatorResults' ) . getText ( ) ;
1818 return text . replace ( 'Display is' , '' ) . trim ( ) ;
1919}
2020
2121describe ( 'Addition' , ( ) => {
2222 // Applies only to tests in this describe block
2323 beforeEach ( async ( ) => {
24- await driver . getByName ( 'Clear' ) . clear ( ) ;
24+ await driver . getByNativeName ( 'Clear' ) . clear ( ) ;
2525 } ) ;
2626
2727 test ( 'Addition' , async ( ) => {
2828 // 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 ( ) ;
3333 expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
3434 } ) ;
3535
3636 test ( 'Division' , async ( ) => {
3737 // 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 ( ) ;
4444 expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
4545 } ) ;
4646
4747 test ( 'Multiplication' , async ( ) => {
4848 // 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 ( ) ;
5353 expect ( await getCalculatorResultText ( ) ) . toBe ( '81' ) ;
5454 } ) ;
5555
5656
5757
5858 test ( 'Subtraction' , async ( ) => {
5959 // 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 ( ) ;
6464 expect ( await getCalculatorResultText ( ) ) . toBe ( '8' ) ;
6565 } ) ;
6666} ) ;
0 commit comments