Crate appium_client

source ·
Expand description

Rust client for Appium Server, for automated mobile app testing

It is based on fantoccini and retains all capabilities of fantoccini’s client, such as screenshotting, touch actions, getting page source etc.

Please note that this is only a client of Appium, so also check out Appium docs.

Creating a client

To create a client, you need capabilities for the Appium session. Capabilities describe what device you use and they will determine what features are available to you.

After creating a desired set of capabilities, use ClientBuilder to create a client. And you also need a running Appium server, see Appium docs for how to set up one (https://appium.io/docs/en/2.1/quickstart/).

Creating an iOS capabilities and client:

use appium_client::capabilities::{AppCapable, UdidCapable};
use appium_client::capabilities::ios::IOSCapabilities;
use appium_client::ClientBuilder;
use appium_client::commands::ios::ShakesDevice;

let mut capabilities = IOSCapabilities::new_xcui();
capabilities.udid("000011114567899");
capabilities.app("/apps/sample.ipa");

let client = ClientBuilder::native(capabilities)
   .connect("http://localhost:4723/wd/hub/")
   .await?;

// now you can use the client to issue commands and find elements on screen

Finding elements

This appium-client adds support for Appium locators such as iOS Class Chain, or UiAutomator. See find for more info on Appium locators.

Basic usage:

use appium_client::capabilities::android::AndroidCapabilities;
use appium_client::ClientBuilder;
use appium_client::find::{AppiumFind, By};

let mut capabilities = AndroidCapabilities::new_uiautomator();
// create the client
let client = ClientBuilder::native(capabilities)
    .connect("http://localhost:4723/wd/hub/")
    .await?;

// locate an element (find it)
let element = client
    .find_by(By::accessibility_id("Click this"))
    .await?;

element.click().await?;

Wait for an element to appear

Appium locators can be also waited on (just like you can wait for element with fantoccini), see wait to learn how to wait.

Basic usage:

use appium_client::capabilities::android::AndroidCapabilities;
use appium_client::ClientBuilder;
use appium_client::find::{AppiumFind, By};

let mut capabilities = AndroidCapabilities::new_uiautomator();
// create the client
let client = ClientBuilder::native(capabilities)
    .connect("http://localhost:4723/wd/hub/")
    .await?;

// wait until element appears
let element = client
    .appium_wait()
    .for_element(By::accessibility_id("Click this"))
    .await?;

element.click().await?;

Commands

If you want to rotate the emulator’s screen, or send keys, or do some other things supported by Appium, then you can use features implemented in commands module.

Those commands should be available to you depending whether you created AndroidCapabilities or IOSCapabilities.

If you wish to issue a custom command (not implemented by this lib), then use issue_command(Custom).

use http::Method;
use serde_json::json;
use appium_client::capabilities::android::AndroidCapabilities;
use appium_client::capabilities::{AppCapable, UdidCapable, UiAutomator2AppCompatible};
use appium_client::ClientBuilder;
use appium_client::commands::AppiumCommand;
use appium_client::commands::keyboard::HidesKeyboard;
use appium_client::find::{AppiumFind, By};

// create capabilities
let mut capabilities = AndroidCapabilities::new_uiautomator();
capabilities.udid("emulator-5554");
capabilities.app("/apps/sample.apk");
capabilities.app_wait_activity("com.example.AppActivity");

let client = ClientBuilder::native(capabilities)
   .connect("http://localhost:4723/wd/hub/")
   .await?;

// this feature is implemented in commands by this lib
client.hide_keyboard().await?;

// use some quirky feature of Appium (not implemented in commands module)
// you can issue_cmd if you see that I didn't implement something
client.issue_cmd(AppiumCommand::Custom(
    Method::POST,
    "quirky_feature".to_string(),
    Some(json!({
        "tap": "everywhere"
    }))
)).await?;

More documentation

See the readme or examples to learn how to use this library.

Modules

  • A set of parameters used to start an Appium session.
  • Commands that you can issue to Appium server
  • Find API for locating elements on screen
  • Wait API for waiting for elements to appear on screen

Structs

Traits

Type Aliases