Skip to content

Commit a94fe74

Browse files
authored
feat(android): add front/back camera options (#87)
* feat(android): add front/back camera options supports only google_apis and google_apis_playstore images * chore: update deps
1 parent fc39c89 commit a94fe74

8 files changed

Lines changed: 102 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub trait RapiClient {
6464
library_bundle: Option<Vec<LibraryBundleReference>>,
6565
granted_permission: Option<Vec<String>>,
6666
batch_isolation: Option<BatchIsolation>,
67+
front_camera: Option<String>,
68+
back_camera: Option<String>,
6769
) -> Result<String>;
6870
async fn get_run(&self, id: &str) -> Result<TestRun>;
6971

@@ -164,6 +166,8 @@ impl RapiClient for RapiReqwestClient {
164166
library_bundle: Option<Vec<LibraryBundleReference>>,
165167
granted_permission: Option<Vec<String>>,
166168
batch_isolation: Option<BatchIsolation>,
169+
front_camera: Option<String>,
170+
back_camera: Option<String>,
167171
) -> Result<String> {
168172
let url = format!("{}/v2/run", self.base_url);
169173
let params = [("api_key", self.api_key.clone())];
@@ -299,6 +303,8 @@ impl RapiClient for RapiReqwestClient {
299303
bundles,
300304
granted_permission: granted_permission.clone(),
301305
app_uninstall,
306+
front_camera,
307+
back_camera,
302308
};
303309

304310
let response = self.client.post(url).json(&create_request).send().await?;
@@ -682,6 +688,10 @@ struct CreateRunRequest {
682688
granted_permission: Option<Vec<String>>,
683689
#[serde(rename = "app_uninstall", default)]
684690
app_uninstall: Option<bool>,
691+
#[serde(rename = "front_camera", default)]
692+
front_camera: Option<String>,
693+
#[serde(rename = "back_camera", default)]
694+
back_camera: Option<String>,
685695
}
686696

687697
#[derive(Serialize, Deserialize, Debug)]

src/cli/android/maestro/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ pub(crate) async fn run(
131131
None,
132132
None,
133133
None,
134+
None,
135+
None,
134136
formatter,
135137
)
136138
.await

src/cli/android/mod.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,43 @@ impl Display for Flavor {
104104
}
105105
}
106106

107+
#[derive(Debug, clap::ValueEnum, Clone)]
108+
pub enum FrontCamera {
109+
#[clap(name = "none")]
110+
None,
111+
#[clap(name = "emulated")]
112+
Emulated,
113+
}
114+
115+
impl Display for FrontCamera {
116+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117+
match self {
118+
FrontCamera::None => f.write_str("none"),
119+
FrontCamera::Emulated => f.write_str("emulated"),
120+
}
121+
}
122+
}
123+
124+
#[derive(Debug, clap::ValueEnum, Clone)]
125+
pub enum BackCamera {
126+
#[clap(name = "none")]
127+
None,
128+
#[clap(name = "virtualscene")]
129+
VirtualScene,
130+
#[clap(name = "emulated")]
131+
Emulated,
132+
}
133+
134+
impl Display for BackCamera {
135+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136+
match self {
137+
BackCamera::None => f.write_str("none"),
138+
BackCamera::VirtualScene => f.write_str("virtualscene"),
139+
BackCamera::Emulated => f.write_str("emulated"),
140+
}
141+
}
142+
}
143+
107144
#[allow(clippy::too_many_arguments)]
108145
pub(crate) async fn run(
109146
application: Option<std::path::PathBuf>,
@@ -122,6 +159,8 @@ pub(crate) async fn run(
122159
application_bundle: Option<Vec<String>>,
123160
library_bundle: Option<Vec<PathBuf>>,
124161
mock_location: bool,
162+
front_camera: Option<FrontCamera>,
163+
back_camera: Option<BackCamera>,
125164
) -> Result<bool> {
126165
if application.is_none()
127166
&& test_application.is_none()
@@ -183,6 +222,7 @@ If you are interesting in library testing then please use advance mode with --li
183222
}
184223

185224
validate_device_configuration(&os_version, &system_image, &device, &flavor)?;
225+
validate_camera_configuration(&system_image, &front_camera, &back_camera)?;
186226

187227
let filter_file = common.filter_file.map(filtering::convert::convert);
188228
let filtering_configuration = match filter_file {
@@ -284,6 +324,8 @@ If you are interesting in library testing then please use advance mode with --li
284324
library_bundle,
285325
None,
286326
None,
327+
front_camera.map(|x| x.to_string()),
328+
back_camera.map(|x| x.to_string()),
287329
formatter,
288330
)
289331
.await
@@ -370,6 +412,26 @@ pub(crate) fn validate_device_configuration(
370412
Ok(())
371413
}
372414

415+
pub(crate) fn validate_camera_configuration(
416+
system_image: &Option<SystemImage>,
417+
front_camera: &Option<FrontCamera>,
418+
back_camera: &Option<BackCamera>,
419+
) -> Result<()> {
420+
if front_camera.is_none() && back_camera.is_none() {
421+
return Ok(());
422+
}
423+
424+
match system_image {
425+
Some(SystemImage::GoogleApis) | Some(SystemImage::GoogleApisPlaystore) => Ok(()),
426+
_ => Err(ConfigurationError::UnsupportedRunConfiguration {
427+
message:
428+
"Camera options (--front-camera, --back-camera) are only supported with google_apis or google_apis_playstore system images"
429+
.into(),
430+
}
431+
.into()),
432+
}
433+
}
434+
373435
pub(crate) async fn validate(
374436
application: Option<PathBuf>,
375437
test_application: Option<PathBuf>,

src/cli/ios/maestro/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub(crate) async fn run(
158158
None,
159159
None,
160160
None,
161+
None,
162+
None,
161163
formatter,
162164
)
163165
.await

src/cli/ios/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ pub(crate) async fn run(
380380
None,
381381
granted_permission,
382382
batch_isolation,
383+
None,
384+
None,
383385
formatter,
384386
)
385387
.await

src/cli/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl Cli {
6060
library_bundle,
6161
profiling_args,
6262
mock_location,
63+
front_camera,
64+
back_camera,
6365
} => {
6466
android::run(
6567
application,
@@ -78,6 +80,8 @@ impl Cli {
7880
application_bundle,
7981
library_bundle,
8082
mock_location,
83+
front_camera,
84+
back_camera,
8185
)
8286
.await
8387
}
@@ -549,6 +553,20 @@ Example: '--library-bundle apks/library1-debug-androidTest.apk --library-bundle
549553
help = "Allow mock location access for application"
550554
)]
551555
mock_location: bool,
556+
557+
#[arg(
558+
value_enum,
559+
long,
560+
help = "Front camera mode. Only supported with google_apis or google_apis_playstore system images"
561+
)]
562+
front_camera: Option<android::FrontCamera>,
563+
564+
#[arg(
565+
value_enum,
566+
long,
567+
help = "Back camera mode. Only supported with google_apis or google_apis_playstore system images"
568+
)]
569+
back_camera: Option<android::BackCamera>,
552570
},
553571
#[allow(non_camel_case_types)]
554572
#[command(name = "ios")]

src/interactor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ impl TriggerTestRunInteractor {
144144
library_bundle: Option<Vec<LibraryBundleReference>>,
145145
granted_permission: Option<Vec<String>>,
146146
batch_isolation: Option<BatchIsolation>,
147+
front_camera: Option<String>,
148+
back_camera: Option<String>,
147149
mut formatter: StandardFormatter,
148150
) -> Result<bool> {
149151
let client = RapiReqwestClient::new(base_url, api_key);
@@ -184,6 +186,8 @@ impl TriggerTestRunInteractor {
184186
library_bundle,
185187
granted_permission,
186188
batch_isolation,
189+
front_camera,
190+
back_camera,
187191
)
188192
.await?;
189193

0 commit comments

Comments
 (0)