appium-client

Rust client for Appium Server, for automated mobile app testing. It is based on fantoccini.

Sample usage

  1. Create Appium client that will be used to issue commands and locate elements.

```rust use appiumclient::ClientBuilder; use appiumclient::capabilities::*;

[tokio::main]

async fn main() -> Result<(), Box> { let mut capabilities = AndroidCapabilities::new(); capabilities.udid("emulator-5554"); capabilities.app("/apps/sample.apk"); capabilities.appwaitactivity("com.example.AppActivity");

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

Ok(())

} ```

  1. Locate an element by using your favorite location strategy (eg. by UiAutomator 2). ```rust // you need this to use Appium locators with fantoccini's Client use appium_client::find::{AppiumFind, By};

let element = client .findby(By::accessibilityid("Click this")) .await?;

element.click().await?; ```

  1. You can wait for element if it does not appear immediately on screen. ```rust // you need these to use Appium-enhanced wait with fantoccini's Client use appiumclient::find::{AppiumFind, By}; use appiumclient::wait::AppiumWait;

let element = client .appiumwait() .forelement(By::uiautomator("new UiSelector().className(\"android.widget.ImageView\");")) .await?;

element.click().await?; ```

  1. You can define how long to wait for the element and how often to check if it's already appeared. ```rust // you need these to use Appium-enhanced wait with fantoccini's Client use appiumclient::find::{AppiumFind, By}; use appiumclient::wait::AppiumWait;

let element = client .appiumwait() .atmost(Duration::fromsecs(20)) .checkevery(Duration::frommillis(500)) .forelement(By::uiautomator("new UiSelector().className(\"android.widget.ImageView\");")) .await?;

element.click().await?; ```

  1. To locate multiple elements, use find_all_by. ```rust // you need these to use Appium-enhanced wait with fantoccini's Client use appiumclient::find::{AppiumFind, By}; use appiumclient::wait::AppiumWait;

let result = client .appiumwait() .findallby(By::classname("android.widget.LinearLayout")) .await?;

result.first().unwrap().click().await?; ```

See example.