Skip to content

Commit 0568fd8

Browse files
committed
Modify Appium Example
1 parent 9e7cc52 commit 0568fd8

File tree

5 files changed

+25
-48
lines changed

5 files changed

+25
-48
lines changed

appium/commands.js

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
const assert = require('assert');
2-
const { exec } = require('child_process');
32

4-
let successfulCommands = [];
5-
6-
// Utility function to validate the text of an element
73
async 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
1610
async 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
2315
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+
}
2824
}
2925

3026
async 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(/Object\..+ \((.+)\)/);
48-
return match ? match[1] : null;
49-
}
50-
5137
module.exports = {
5238
validateElementText,
5339
clickElementById,
5440
allowPermissions,
55-
printSuccess,
56-
extractFailedCommand,
5741
stopAppiumServer,
5842
};

appium/config.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
module.exports = {
2-
user: {
3-
environment: 'test',
4-
5-
code: '555555',
6-
},
72
capabilities: {
83
'appium:platformName': 'Android',
94
'appium:automationName': 'UiAutomator2',
105
'appium:deviceName': 'Nexus_6P_API_33',
11-
'appium:androidInstallTimeout': '240000',
12-
'appium:uiautomator2ServerInstallTimeout': '240000',
13-
'appium:adbExecTimeout': '240000',
146
'appium:app': getAppPath(),
157
'appium:skipDeviceInitialization': true,
168
'appium:appWaitForLaunch': false,
179
'appium:systemPort': 8210,
18-
'appuium:newCommandTimeout': '600',
19-
'appium:logLevel': 'debug',
10+
'appium:newCommandTimeout': '600',
2011
'appium:autoAcceptAlerts': true,
2112
},
2213
wdOpts: {

appium/elementIds.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// elementIds.js
2+
module.exports = {
3+
titleId: 'cm.aptoide.pt:id/title',
4+
descriptionId: 'cm.aptoide.pt:id/description',
5+
skipButtonId: 'cm.aptoide.pt:id/skip_button'
6+
};

appium/tests/sanity.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
const { remote } = require('webdriverio');
22
const commands = require('../commands');
33
const config = require('../config');
4+
const elementIds = require('../elementIds');
45

56
async function runTest() {
67
const driver = await remote({ ...config.wdOpts, capabilities: config.capabilities });
78

89
try {
9-
// await commands.allowPermissions(driver);
10+
await commands.allowPermissions(driver);
11+
await commands.validateElementText(driver, elementIds.titleId, 'Discover the Best Apps');
12+
await commands.validateElementText(driver, elementIds.descriptionId, 'No content restrictions for you to find top apps');
13+
await commands.validateElementText(driver, elementIds.skipButtonId, 'SKIP');
14+
await commands.clickElementById(driver, elementIds.skipButtonId);
1015

11-
await commands.validateElementText(driver, 'cm.aptoide.pt:id/title', 'Discover the Best Apps');
12-
13-
await commands.validateElementText(driver, 'cm.aptoide.pt:id/description', 'No content restrictions for you to find top apps');
14-
15-
await commands.validateElementText(driver, 'cm.aptoide.pt:id/skip_button', 'SKIP');
16-
17-
await commands.clickElementById(driver, 'cm.aptoide.pt:id/skip_button');
18-
19-
commands.printSuccess();
2016
await driver.pause(10000);
17+
2118
} catch (error) {
2219
console.error('Test failed:', error.message);
23-
const failedCommand = commands.extractFailedCommand(error.stack);
24-
if (failedCommand) {
25-
console.error('Failed command:', failedCommand);
26-
}
2720
await commands.stopAppiumServer();
2821
process.exit(1);
22+
2923
} finally {
3024
await driver.pause(1000);
3125
await driver.deleteSession();

appium/bsconfig.js notes.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// bs config
2+
13
module.exports = {
24
user: {
35
environment: 'test',

0 commit comments

Comments
 (0)