1use std::time::Duration;
2use fantoccini::actions::{InputSource, MOUSE_BUTTON_LEFT, PointerAction, TouchActions};
3use appium_client::ClientBuilder;
4use appium_client::capabilities::*;
5use appium_client::capabilities::android::AndroidCapabilities;
6use appium_client::find::{AppiumFind, By};
7
8#[tokio::main]
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10 let mut capabilities = AndroidCapabilities::new_uiautomator();
11 capabilities.app("https://github.com/appium/android-apidemos/releases/download/v3.1.0/ApiDemos-debug.apk");
12
13 let client = ClientBuilder::native(capabilities)
14 .connect("http://localhost:4723/")
15 .await?;
16
17 client.find_by(By::accessibility_id("Views"))
19 .await?
20 .click()
21 .await?;
22
23 let (width, height) = client.get_window_size().await?;
25
26 let horizontal_center = (width / 2) as f64;
28
29 let almost_top = height as f64 * 0.2;
32 let almost_bottom = height as f64 * 0.8;
33
34 let swipe_down = TouchActions::new("finger".to_string())
35 .then(PointerAction::MoveTo {
37 duration: Some(Duration::from_millis(0)),
38 x: horizontal_center,
39 y: almost_bottom,
40 })
41 .then(PointerAction::Down {
43 button: MOUSE_BUTTON_LEFT })
45 .then(PointerAction::MoveTo {
47 duration: Some(Duration::from_millis(500)),
48 x: horizontal_center,
49 y: almost_top,
50 });
51
52 client.perform_actions(swipe_down)
53 .await?;
54
55 Ok(())
56}