Introduction to Appium
Appium is an open-source tool for automating mobile applications. It supports automation on various platforms such as iOS, Android, and Windows. It allows you to write tests using multiple programming languages including Java, JavaScript, Ruby, and Python, making it highly versatile and accessible.
Why Use Appium?
Appium offers a host of features that make it a popular choice for mobile automation testing:
- Cross-platform: Use the same test script across different platforms.
- Language Agnostic: Write tests in various programming languages.
- Open-source: Community-driven and continuously updated.
API Examples
1. Installing Appium
To get started with Appium, you first need to install it:
npm install -g appium
2. Starting Appium Server
Start the Appium server from the command line:
appium
3. Desired Capabilities
Desired capabilities are a set of keys and values sent to the Appium server to tell the server what kind of automation session we’re interested in starting. Here’s an example for an Android test:
const wdio = require("webdriverio"); const opts = { path: '/wd/hub', port: 4723, capabilities: { platformName: "Android", platformVersion: "10", deviceName: "emulator-5554", app: "path/to/the/app.apk", automationName: "UiAutomator2" } }; const client = await wdio.remote(opts);
4. Interacting with Elements
Let’s see some commonly used methods to interact with elements:
Finding Elements
const element = await client.$("~accessibility-id");
Clicking an Element
await element.click();
Sending Keys
await element.setValue("Hello World");
5. Screenshot
Taking a screenshot of the device screen:
await client.saveScreenshot("./screenshot.png");
Sample Mobile App Test
Below is a comprehensive example demonstrating a test scenario:
const wdio = require("webdriverio"); async function main() { const opts = { path: '/wd/hub', port: 4723, capabilities: { platformName: "Android", platformVersion: "10", deviceName: "emulator-5554", app: "path/to/the/app.apk", automationName: "UiAutomator2" } }; const client = await wdio.remote(opts); // Find the input field const inputField = await client.$("~input-field"); await inputField.setValue("Sample text"); // Find the button and click it const button = await client.$("~submit-button"); await button.click(); // Take a screenshot after performing actions await client.saveScreenshot("./action-screenshot.png"); await client.deleteSession(); } main();
Conclusion
Appium is a powerful tool for mobile automation that provides a flexible and robust framework for writing and implementing tests. With its support for multiple platforms and programming languages, it is a go-to tool for many automation engineers.
By following the examples provided, you should now have a good starting point to begin your automation journey with Appium. Happy testing!
Hash: 13adf3e19b4630cefd2fb7a69444794d1400393baa43d3bfa2f6ab77f7c47a69