1.新建工程
打开RustCover,新建工程如下:
修改Cargo.toml文件如下:
[package] name = "test_demo" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] tokio = "1.32.0" appium-client = "0.2.0"
然后在终端输入cargo build,构建完成后点击刷新按钮即可应用安装的依赖库
或者直接在终端输入如下命令添加所需的依赖库:
cargo add tokio
cargo add appium-client
2.编写代码
在main.rs文件编写如下代码:
use appium_client::ClientBuilder; use appium_client::capabilities::*; use appium_client::capabilities::android::AndroidCapabilities; use appium_client::find::By; use appium_client::wait::AppiumWait; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let mut caps = AndroidCapabilities::new(); caps.platform_version("10"); caps.device_name("ZL5227R9TD"); caps.automation_name("UiAutomator2"); caps.app_package("vidma.video.editor.videomaker"); caps.app_activity("com.atlasv.android.mvmaker.mveditor.LaunchActivity"); caps.no_reset(true); caps.full_reset(false); let client = ClientBuilder::native(caps).connect("http://127.0.0.1:4723/wd/hub/").await?; let add_button = client.appium_wait().for_element(By::id("ivAdd")).await?; add_button.click().await?; Ok(()) }