Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub trait RapiClient {
library_bundle: Option<Vec<LibraryBundleReference>>,
granted_permission: Option<Vec<String>>,
batch_isolation: Option<BatchIsolation>,
front_camera: Option<String>,
back_camera: Option<String>,
) -> Result<String>;
async fn get_run(&self, id: &str) -> Result<TestRun>;

Expand Down Expand Up @@ -164,6 +166,8 @@ impl RapiClient for RapiReqwestClient {
library_bundle: Option<Vec<LibraryBundleReference>>,
granted_permission: Option<Vec<String>>,
batch_isolation: Option<BatchIsolation>,
front_camera: Option<String>,
back_camera: Option<String>,
) -> Result<String> {
let url = format!("{}/v2/run", self.base_url);
let params = [("api_key", self.api_key.clone())];
Expand Down Expand Up @@ -299,6 +303,8 @@ impl RapiClient for RapiReqwestClient {
bundles,
granted_permission: granted_permission.clone(),
app_uninstall,
front_camera,
back_camera,
};

let response = self.client.post(url).json(&create_request).send().await?;
Expand Down Expand Up @@ -682,6 +688,10 @@ struct CreateRunRequest {
granted_permission: Option<Vec<String>>,
#[serde(rename = "app_uninstall", default)]
app_uninstall: Option<bool>,
#[serde(rename = "front_camera", default)]
front_camera: Option<String>,
#[serde(rename = "back_camera", default)]
back_camera: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions src/cli/android/maestro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub(crate) async fn run(
None,
None,
None,
None,
None,
formatter,
)
.await
Expand Down
62 changes: 62 additions & 0 deletions src/cli/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,43 @@ impl Display for Flavor {
}
}

#[derive(Debug, clap::ValueEnum, Clone)]
pub enum FrontCamera {
#[clap(name = "none")]
None,
#[clap(name = "emulated")]
Emulated,
}

impl Display for FrontCamera {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FrontCamera::None => f.write_str("none"),
FrontCamera::Emulated => f.write_str("emulated"),
}
}
}

#[derive(Debug, clap::ValueEnum, Clone)]
pub enum BackCamera {
#[clap(name = "none")]
None,
#[clap(name = "virtualscene")]
VirtualScene,
#[clap(name = "emulated")]
Emulated,
}

impl Display for BackCamera {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BackCamera::None => f.write_str("none"),
BackCamera::VirtualScene => f.write_str("virtualscene"),
BackCamera::Emulated => f.write_str("emulated"),
}
}
}

#[allow(clippy::too_many_arguments)]
pub(crate) async fn run(
application: Option<std::path::PathBuf>,
Expand All @@ -122,6 +159,8 @@ pub(crate) async fn run(
application_bundle: Option<Vec<String>>,
library_bundle: Option<Vec<PathBuf>>,
mock_location: bool,
front_camera: Option<FrontCamera>,
back_camera: Option<BackCamera>,
) -> Result<bool> {
if application.is_none()
&& test_application.is_none()
Expand Down Expand Up @@ -183,6 +222,7 @@ If you are interesting in library testing then please use advance mode with --li
}

validate_device_configuration(&os_version, &system_image, &device, &flavor)?;
validate_camera_configuration(&system_image, &front_camera, &back_camera)?;

let filter_file = common.filter_file.map(filtering::convert::convert);
let filtering_configuration = match filter_file {
Expand Down Expand Up @@ -284,6 +324,8 @@ If you are interesting in library testing then please use advance mode with --li
library_bundle,
None,
None,
front_camera.map(|x| x.to_string()),
back_camera.map(|x| x.to_string()),
formatter,
)
.await
Expand Down Expand Up @@ -370,6 +412,26 @@ pub(crate) fn validate_device_configuration(
Ok(())
}

pub(crate) fn validate_camera_configuration(
system_image: &Option<SystemImage>,
front_camera: &Option<FrontCamera>,
back_camera: &Option<BackCamera>,
) -> Result<()> {
if front_camera.is_none() && back_camera.is_none() {
return Ok(());
}

match system_image {
Some(SystemImage::GoogleApis) | Some(SystemImage::GoogleApisPlaystore) => Ok(()),
_ => Err(ConfigurationError::UnsupportedRunConfiguration {
message:
"Camera options (--front-camera, --back-camera) are only supported with google_apis or google_apis_playstore system images"
.into(),
}
.into()),
}
}

pub(crate) async fn validate(
application: Option<PathBuf>,
test_application: Option<PathBuf>,
Expand Down
2 changes: 2 additions & 0 deletions src/cli/ios/maestro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub(crate) async fn run(
None,
None,
None,
None,
None,
formatter,
)
.await
Expand Down
2 changes: 2 additions & 0 deletions src/cli/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ pub(crate) async fn run(
None,
granted_permission,
batch_isolation,
None,
None,
formatter,
)
.await
Expand Down
18 changes: 18 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ impl Cli {
library_bundle,
profiling_args,
mock_location,
front_camera,
back_camera,
} => {
android::run(
application,
Expand All @@ -78,6 +80,8 @@ impl Cli {
application_bundle,
library_bundle,
mock_location,
front_camera,
back_camera,
)
.await
}
Expand Down Expand Up @@ -549,6 +553,20 @@ Example: '--library-bundle apks/library1-debug-androidTest.apk --library-bundle
help = "Allow mock location access for application"
)]
mock_location: bool,

#[arg(
value_enum,
long,
help = "Front camera mode. Only supported with google_apis or google_apis_playstore system images"
)]
front_camera: Option<android::FrontCamera>,

#[arg(
value_enum,
long,
help = "Back camera mode. Only supported with google_apis or google_apis_playstore system images"
)]
back_camera: Option<android::BackCamera>,
},
#[allow(non_camel_case_types)]
#[command(name = "ios")]
Expand Down
4 changes: 4 additions & 0 deletions src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl TriggerTestRunInteractor {
library_bundle: Option<Vec<LibraryBundleReference>>,
granted_permission: Option<Vec<String>>,
batch_isolation: Option<BatchIsolation>,
front_camera: Option<String>,
back_camera: Option<String>,
mut formatter: StandardFormatter,
) -> Result<bool> {
let client = RapiReqwestClient::new(base_url, api_key);
Expand Down Expand Up @@ -184,6 +186,8 @@ impl TriggerTestRunInteractor {
library_bundle,
granted_permission,
batch_isolation,
front_camera,
back_camera,
)
.await?;

Expand Down
Loading