1
1
const assert = require ( 'assert' ) ;
2
- const { exec } = require ( 'child_process' ) ;
3
2
4
- let successfulCommands = [ ] ;
5
-
6
- // Utility function to validate the text of an element
7
3
async function validateElementText ( driver , elementId , expectedText ) {
8
4
const element = await driver . $ ( `id=${ elementId } ` ) ;
9
5
const actualText = await element . getText ( ) ;
10
6
assert . strictEqual ( actualText , expectedText , `Text for element ${ elementId } does not match. Expected: "${ expectedText } ", but got: "${ actualText } "` ) ;
11
- successfulCommands . push ( 'validateElementText: ' + expectedText ) ;
12
7
return element ;
13
8
}
14
9
15
- // Utility function to click on an element by its ID
16
10
async function clickElementById ( driver , elementId ) {
17
11
const element = await driver . $ ( `id=${ elementId } ` ) ;
18
12
await element . click ( ) ;
19
- successfulCommands . push ( 'clickElementById: ' + elementId ) ;
20
13
}
21
14
22
- // Utility function to handle the "Allow Permissions" prompt
23
15
async 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
+ }
28
24
}
29
25
30
26
async function stopAppiumServer ( ) {
@@ -38,21 +34,9 @@ async function stopAppiumServer() {
38
34
} ) ;
39
35
}
40
36
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
-
51
37
module . exports = {
52
38
validateElementText,
53
39
clickElementById,
54
40
allowPermissions,
55
- printSuccess,
56
- extractFailedCommand,
57
41
stopAppiumServer,
58
42
} ;
0 commit comments