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

Add --standalone flag in the tool. #18

Open
garg3133 opened this issue Dec 10, 2023 · 8 comments
Open

Add --standalone flag in the tool. #18

garg3133 opened this issue Dec 10, 2023 · 8 comments
Labels
good first issue Good for newcomers

Comments

@garg3133
Copy link
Member

If the --standalone flag is used, the tool should not download anything extra which might be related to Nightwatch or testing.

@itsspriyansh
Copy link
Contributor

itsspriyansh commented Feb 23, 2024

@garg3133
I wanted to confirm if this issue corresponds to this statement in the readme file.

Although this tool is designed with Nightwatch in mind, it can also be used as a standalone tool to download all the required Android SDKs needed to get the Android Emulator setup and running with Android v11.

If yes, then will the right approach be to add standalone key inside scripts in package.json?

"scripts": { "standalone": "npm install --save-dev <dependency-names>" }

I also wanted to confirm the required dependencies for this. So far I assume the dependencies appium-adb axios download inquirer minimist untildify which should be required.

@garg3133
Copy link
Member Author

I wanted to confirm if this issue corresponds to this statement in the readme file.

Yes.

If yes, then will the right approach be to add standalone key inside scripts in package.json?

No. I'm not talking about an NPM script command but the commands that are implemented in the tool itself. Run npx @nightwatch/mobile-helper --help to see a list of available commands.

So, in this issue, we want to add support for a --standalone flag in the android command, so that only the tools required for standalone usage are downloaded by this package. We do not want to create any new package for standalone usage.

I'd suggest you to first try running the tool yourself and play around with it, everything will be more clear to you then.

@itsspriyansh
Copy link
Contributor

@garg3133
Please let me know if I am getting this right.
Apart from working as a testing tool, mobile-helpter-tool can also serve as a utility to download Android SDKs required to set up emulator. For this, we need to pass --standalone flag as a CLI argument when npx @nightwatch/mobile-helper android is run.

Minimist is used for parsing CLI arguments so we have to add standalone in boolean array so that we can check weather it was passed as argument or not.

src/index.ts

    const {_: args, ...options} = minimist(argv, {
      boolean: ['install', 'setup', 'help', 'appium', 'standalone'],
      alias: {
        help: 'h',
        mode: 'm',
        browsers: ['b', 'browser'],
        setup: ['install', 'i']
      }
    });

We also need to add standalone key in AVAILABLE_OPTIONS object.

src/commands/android/constants.ts

export const AVAILABLE_OPTIONS: AvailableOptions = {
  help: {
    alias: ['h'],
    description: 'Help for android command.'
  },
  setup: {
    alias: ['install', 'i'],
    description: 'Automatically setup all the missing requirements.'
  },
  mode: {
    alias: ['m'],
    description: 'Verify/setup requirements for real-device or emulator. Available args: "real", "emulator", "both"'
  },
  browsers: {
    alias: ['browser', 'b'],
    description: 'Browsers to setup on Android emulator. Available args: "chrome", "firefox", "both", "none"'
  },
  appium: {
    alias: [],
    description: 'Make sure the final setup works with Appium out-of-the-box.'
  },
  standalone: {
    alias: ['sa'],
    description: 'Downloads everything required for setting up emulator and running Android v11 without any other additional files'
  }
};

We can handle the downloading logic with conditional statements in run function in src/commands/android/index.ts

if (this.options.standalone) {
    // download logic here
    return true
}

@garg3133
Copy link
Member Author

@itsspriyansh You're going in the right direction.

Apart from working as a testing tool, mobile-helpter-tool can also serve as a utility to download Android SDKs required to set up emulator. For this, we need to pass --standalone flag as a CLI argument when npx @nightwatch/mobile-helper android is run.

@nightwatch/mobile-helper is not a testing tool, it is "only" used to download Android SDKs. But while doing so, it might also download some additional requirements which are specific for "testing", so we just want to avoid downloading those when the tool is run in --standalone mode.

We can handle the downloading logic with conditional statements...

Yes, although you need to re-write the whole download logic, you just need to modify the code based on what we want and don't want to download in the standalone mode.

@itsspriyansh
Copy link
Contributor

itsspriyansh commented Feb 24, 2024

@garg3133 I have gone through Android setup script and its related function. I have some doubts regarding this.
When using --standalone flag, we will download SDKs to get emulator running. Setting up browser is also necessary for this. And the sdk binaries also seem necessary for this.

However I am not sure about Android Debug Bridge, since it is important for communicating with emulator but I am not sure if it is strictly required only for setting up the emulator.

Apart from this I do not see anything specific in the android setup script that is downloading anything extra related to Nightwatch and testing. Please let me know whatever I am missing out.

@garg3133
Copy link
Member Author

@itsspriyansh ADB is also necessary otherwise while you'd have an Emulator setup up, you won't be able to do much with it (like install new app, etc.).

Setting up browser can be optional in --standalone mode and user can choose whether to do it or not (setting up browser is only necessary for Nightwatch because it is going to do automation on browsers only). Additionally, this tool also installs a chromedriver binary if Chrome is being set up, which is not required in --standalone mode.

What'd be helpful here is if you can document all the cases with which the tool is run and what are all the tools/binaries are downloaded/installed in each case and in what order. Like just go through code and keep documenting that if we have these conditions, then first this will be installed, then this will be checked and installed, etc. Such a document will greatly help in understanding the codebase without going back and forth in the file all the time.

@itsspriyansh
Copy link
Contributor

@garg3133 I had raised PR. Please let me know if the changes are correct.

@garg3133
Copy link
Member Author

@itsspriyansh Thanks. I'll try to look at it tomorrow.

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

No branches or pull requests

2 participants