�
��i* � � � d Z y)uk
// Example test case for a different scenario
// calculator-test.js
const { remote } = require('webdriverio');
const assert = require('assert');
// Test configuration for Pixel 6 with Android 14
const capabilities = {
platformName: 'Android',
'appium:deviceName': 'Pixel 6',
'appium:platformVersion': '14', // Updated to match your device
'appium:automationName': 'UiAutomator2',
'appium:appPackage': 'com.google.android.calculator',
'appium:appActivity': 'com.android.calculator2.Calculator',
'appium:newCommandTimeout': 240
};
// Appium server options
const wdOpts = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
logLevel: 'info',
capabilities
};
// Test function
async function runTest() {
console.log('Initializing Appium session...');
const driver = await remote(wdOpts);
try {
console.log('Starting calculator test...');
// Wait for the calculator to fully load
await driver.pause(3000);
// Taking a screenshot to help with debugging
await driver.saveScreenshot('./calculator-initial.png');
console.log('Screenshot saved to calculator-initial.png');
// Using resource-ids instead of text attributes
// These selectors use multiple strategies for better reliability
console.log('Pressing 5...');
try {
const button5 = await driver.$('android=new UiSelector().className("android.widget.ImageButton").descriptionContains("5")');
await button5.click();
} catch (error) {
console.log('First strategy failed, trying alternative for number 5...');
try {
const button5 = await driver.$('~5'); // Using accessibility ID
await button5.click();
} catch (error2) {
console.log('Second strategy failed, trying third strategy for number 5...');
const button5 = await driver.$('//*[contains(@resource-id, "digit_5") or contains(@content-desc, "5")]');
await button5.click();
}
}
console.log('Pressing +...');
try {
const buttonPlus = await driver.$('android=new UiSelector().className("android.widget.ImageButton").descriptionContains("plus")');
await buttonPlus.click();
} catch (error) {
console.log('First strategy failed, trying alternative for plus...');
try {
const buttonPlus = await driver.$('~plus');
await buttonPlus.click();
} catch (error2) {
console.log('Second strategy failed, trying third strategy for plus...');
const buttonPlus = await driver.$('//*[contains(@resource-id, "op_add") or contains(@content-desc, "plus") or contains(@content-desc, "add")]');
await buttonPlus.click();
}
}
console.log('Pressing 7...');
try {
const button7 = await driver.$('android=new UiSelector().className("android.widget.ImageButton").descriptionContains("7")');
await button7.click();
} catch (error) {
console.log('First strategy failed, trying alternative for number 7...');
try {
const button7 = await driver.$('~7');
await button7.click();
} catch (error2) {
console.log('Second strategy failed, trying third strategy for number 7...');
const button7 = await driver.$('//*[contains(@resource-id, "digit_7") or contains(@content-desc, "7")]');
await button7.click();
}
}
console.log('Pressing =...');
try {
const buttonEquals = await driver.$('android=new UiSelector().className("android.widget.ImageButton").descriptionContains("equals")');
await buttonEquals.click();
} catch (error) {
console.log('First strategy failed, trying alternative for equals...');
try {
const buttonEquals = await driver.$('~equals');
await buttonEquals.click();
} catch (error2) {
console.log('Second strategy failed, trying third strategy for equals...');
const buttonEquals = await driver.$('//*[contains(@resource-id, "eq") or contains(@content-desc, "equals")]');
await buttonEquals.click();
}
}
await driver.saveScreenshot('./calculator-result.png');
console.log('Result screenshot saved to calculator-result.png');
console.log('Getting the result...');
let resultText;
try {
const resultElement = await driver.$('//*[contains(@resource-id, "result")]');
resultText = await resultElement.getText();
} catch (error) {
console.log('First strategy failed, trying alternative for result...');
try {
const resultElement = await driver.$('//android.widget.TextView[contains(@resource-id, "display")]');
resultText = await resultElement.getText();
} catch (error2) {
console.log('Second strategy failed, trying generic TextView for result...');
const elements = await driver.$$('//android.widget.TextView');
for (const element of elements) {
const text = await element.getText();
if (text.includes('12') || text.trim() === '12') {
resultText = text;
break;
}
}
}
}
console.log(`The result is: ${resultText}`);
const numericResult = resultText.replace(/[^0-9]/g, '');
assert.strictEqual(numericResult, '12', `Expected 5+7=12, but got ${resultText}`);
console.log('Test PASSED ✓');
} catch (error) {
console.error('Test FAILED ✗');
console.error(error);
try {
await driver.saveScreenshot('./calculator-error.png');
console.log('Error screenshot saved to calculator-error.png');
} catch (screenshotError) {
console.log('Could not take error screenshot', screenshotError);
}
throw error;
} finally {
console.log('Ending Appium session...');
await driver.deleteSession();
}
}
// Run the test
runTest().catch(console.error);
N)�CALCULATOR_EXAMPLE_TEST� � �IC:\Users\abhishekm\source\knovva\knnova\mobile-mcp\appcrawler\examples.py�<module>r s ��]� r