11const assert = require ( 'assert' ) ;
2- const { exec } = require ( 'child_process' ) ;
32
4- let successfulCommands = [ ] ;
5-
6- // Utility function to validate the text of an element
73async function validateElementText ( driver , elementId , expectedText ) {
84 const element = await driver . $ ( `id=${ elementId } ` ) ;
95 const actualText = await element . getText ( ) ;
106 assert . strictEqual ( actualText , expectedText , `Text for element ${ elementId } does not match. Expected: "${ expectedText } ", but got: "${ actualText } "` ) ;
11- successfulCommands . push ( 'validateElementText: ' + expectedText ) ;
127 return element ;
138}
149
15- // Utility function to click on an element by its ID
1610async function clickElementById ( driver , elementId ) {
1711 const element = await driver . $ ( `id=${ elementId } ` ) ;
1812 await element . click ( ) ;
19- successfulCommands . push ( 'clickElementById: ' + elementId ) ;
2013}
2114
22- // Utility function to handle the "Allow Permissions" prompt
2315async function allowPermissions ( driver ) {
24- const allowButton = await driver . $ ( '//android.widget.Button[@resource-id="com.android.permissioncontroller:id/permission_allow_button"]' ) ;
25- await allowButton . waitForDisplayed ( { timeout : 20000 } ) ;
26- await allowButton . click ( ) ;
27- successfulCommands . push ( 'allowPermissions' ) ;
16+ try {
17+ const allowButton = await driver . $ ( '//android.widget.Button[@resource-id="com.android.permissioncontroller:id/permission_allow_button"]' ) ;
18+ await allowButton . waitForDisplayed ( { timeout : 20000 } ) ;
19+ await allowButton . click ( ) ;
20+ console . log ( 'Permissions allowed successfully' ) ;
21+ } catch ( error ) {
22+ console . error ( 'Failed to allow permissions:' , error . message ) ;
23+ }
2824}
2925
3026async function stopAppiumServer ( ) {
@@ -38,21 +34,9 @@ async function stopAppiumServer() {
3834 } ) ;
3935}
4036
41- function printSuccess ( ) {
42- console . log ( chalk . green ( `The sanity test passed. Successful commands: ${ successfulCommands . join ( ', ' ) } ` ) ) ;
43- }
44-
45- function extractFailedCommand ( stack ) {
46- // Extract the failed command from the stack trace
47- const match = stack . match ( / O b j e c t \. .+ \( ( .+ ) \) / ) ;
48- return match ? match [ 1 ] : null ;
49- }
50-
5137module . exports = {
5238 validateElementText,
5339 clickElementById,
5440 allowPermissions,
55- printSuccess,
56- extractFailedCommand,
5741 stopAppiumServer,
5842} ;
0 commit comments