Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: launch AVD #50

Merged
merged 10 commits into from
Sep 10, 2024
Merged

feat: launch AVD #50

merged 10 commits into from
Sep 10, 2024

Conversation

itsspriyansh
Copy link
Contributor

@itsspriyansh itsspriyansh commented Jul 4, 2024

This PR adds functionality for launching an AVD. The workflow is triggered using the --emulator flag with the connect subcomamnd as shown below:

npx @nightwatch/mobile-helper android connect --emulator

Screencast.from.04-07-24.10.39.32.PM.IST.webm

@garg3133
Copy link
Member

garg3133 commented Jul 7, 2024

I think instead of using --avd we should use --emulator flag to trigger this workflow since we are actually connecting to an emulator environment and then choosing which AVD to run in that emulator. Also, "emulator" would be easier for users to remember and use when compared to "avd".

We could probably use --avd as a valued flag here using which users can pass the AVD name to run in the emulator with the command itself:

npx @nightwatch/mobile-helper android connect --emulator --avd nightwatch-android-11

# could also use the @ patter that the emulator binary provides
npx @nightwatch/mobile-helper android connect --emulator @nightwatch-android-11

@itsspriyansh
Copy link
Contributor Author

itsspriyansh commented Jul 8, 2024

@garg3133 I have updated the PR. Here I have used as keyword for valued option because we know that any boolean option will be handled by the verifyOptions function. Therefore only an option with string value will be bypassed.

@itsspriyansh
Copy link
Contributor Author

itsspriyansh commented Jul 17, 2024

In this PR, --avd flag is used to specify the name of the avd to launch. If user runs the following command then the functionality works fine.

npx @nightwatch/mobile-helper android connect --emulator --avd <avd_name>

but if user passes a command like the one below

npx @nightwatch/mobile-helper android connect --emulator --avd

an error will be shown since avd is passed here as a boolean option and not a valued option. And the verifyOptions function in this PR #51 throws error for any unrecognized boolean flag. Since avd is not defined in the AVAILABLE_SUBCOMMANDS object it will be considered as unknown. Even though this is incorrect usage to just pass the avd option without a value, I think we shouldn't show an error and just proceed with the script and prompt the user to select a device.

If the user passes a value along with the flag then no error is shown and everything works fine because in the verifyOptions function we are just checking the options that have the value true. In this case, the valued options are ignored.

@garg3133
Copy link
Member

Even though this is incorrect usage to just pass the avd option without a value, I think we shouldn't show an error and just proceed with the script and prompt the user to select a device.

You are correct here. If the user passes --avd only, we should proceed with the normal flow instead of throwing an error.

One question that I have here is - why are we only checking for boolean flags in verifyOptions and not all the possible flags? Why not add --avd to AVAILABLE_SUBCOMMANDS as well and verify it? We would anyway need it there to show in the help section, won't we?

@garg3133
Copy link
Member

In the verifyOptions, we just want to skip the flags that are set to false (which would mean that those flag wasn't actually passed with the command), otherwise we should verify all other flags.

@garg3133
Copy link
Member

@itsspriyansh Can you see what is remaining here?

@itsspriyansh
Copy link
Contributor Author

@garg3133 Sure. I have updated the PR.

@itsspriyansh
Copy link
Contributor Author

@garg3133 PR updated. Using spawnSync for now but we will replace it with spawnCommandSync once #57 is merged.

@garg3133 garg3133 merged commit 9d22827 into nightwatchjs:main Sep 10, 2024
2 checks passed
@garg3133
Copy link
Member

@itsspriyansh Since you were asking whether we should test subcommand scripts or not, the fix I did in the last commit of this PR would have been caught if we have tests because in those tests we would have tried passing different versions of --avd flag and it wouldn't have worked correctly for boolean or array avds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants