use std::time::Duration;
use fantoccini::actions::{InputSource, MOUSE_BUTTON_LEFT, PointerAction, TouchActions};
use appium_client::ClientBuilder;
use appium_client::capabilities::*;
use appium_client::capabilities::android::AndroidCapabilities;
use appium_client::find::{AppiumFind, By};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut capabilities = AndroidCapabilities::new_uiautomator();
capabilities.app("https://github.com/appium/android-apidemos/releases/download/v3.1.0/ApiDemos-debug.apk");
let client = ClientBuilder::native(capabilities)
.connect("http://localhost:4723/")
.await?;
client.find_by(By::accessibility_id("Views"))
.await?
.click()
.await?;
let (width, height) = client.get_window_size().await?;
let horizontal_center = (width / 2) as f64;
let almost_top = height as f64 * 0.2;
let almost_bottom = height as f64 * 0.8;
let swipe_down = TouchActions::new("finger".to_string())
.then(PointerAction::MoveTo {
duration: Some(Duration::from_millis(0)),
x: horizontal_center,
y: almost_bottom,
})
.then(PointerAction::Down {
button: MOUSE_BUTTON_LEFT })
.then(PointerAction::MoveTo {
duration: Some(Duration::from_millis(500)),
x: horizontal_center,
y: almost_top,
});
client.perform_actions(swipe_down)
.await?;
Ok(())
}