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

Migrate Android Java E2E tests from App Center to Browserstack #22117

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

carzh
Copy link
Contributor

@carzh carzh commented Sep 17, 2024

Description

  • removed installing AppCenter + pipeline step that runs AppCenter Espresso tests
  • added script for running AppCenter tests

Motivation and Context

App Center is getting deprecated in the next year + we have upcoming Android work that depends on working E2E testing.

@carzh carzh marked this pull request as ready for review September 18, 2024 03:58
@carzh carzh requested a review from a team as a code owner September 18, 2024 03:58
args = parser.parse_args()


def post_response_to_json(response):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the name is post_reponse_to_json but this function is also called with a GET response. maybe response_to_json would be a more general name.

def upload_apk_parse_json(post_url, apk_path):
with open(apk_path, "rb") as apk_file:
response = requests.post(post_url, files={"file": apk_file}, auth=(args.id, args.token))
return post_response_to_json(response.text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also check response.status_code? e.g., this method might be useful:
https://docs.python-requests.org/en/latest/api/#requests.Response.raise_for_status

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also a response method for parsing json which may simplify things:
https://docs.python-requests.org/en/latest/api/#requests.Response.json


import requests

parser = argparse.ArgumentParser("Upload and run BrowserStack tests")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually want to put the script logic to execute inside the check if __name__ == '__main__'. then, it only gets executed when the script is called directly and not in other contexts, like when the script is imported by something else.

more details here: https://docs.python.org/3/library/__main__.html

parser = argparse.ArgumentParser("Upload and run BrowserStack tests")

parser.add_argument("--id", type=str, help="BrowserStack user ID")
parser.add_argument("--token", type=str, help="BrowserStack token")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this value secret?

passing it on the command line might be fine in the context of a CI pipeline where it is redacted from logs, but command line arguments are generally not hidden. e.g., when running locally, the command line arguments will be visible to other processes and also in the command history.

some alternatives are to pass the secret value via stdin or in an environment variable.

if we don't expect to run this script much locally, this is less of a concern.


parser.add_argument("--id", type=str, help="BrowserStack user ID")
parser.add_argument("--token", type=str, help="BrowserStack token")
parser.add_argument("--test_platform", type=str, help="Testing platform, i.e., XCUITest or Espresso")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there are two valid options, can we just constrain them here to catch typos earlier and with an obvious error message?
e.g., choices=['espresso', ...]

@carzh carzh force-pushed the carzh/browserstack-android-test branch from 2347315 to 1a2ae52 Compare September 18, 2024 21:00
Comment on lines +75 to +76
--id $(browserstack_username) \
--token $(browserstack_access_key) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there WIP documentation somewhere that provides the high level details of how this all works and where these values are defined so that we know how to update them in the future?

Comment on lines +31 to +32
if "error" in json_response:
raise Exception(json_response["error"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there specific json properties we can check for 'error' instead of matching across the entire response?


def upload_apk_parse_json(post_url, apk_path):
with open(apk_path, "rb") as apk_file:
response = requests.post(post_url, files={"file": apk_file}, auth=(args.id, args.token))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we configure specific timeouts based on the operation? I can imagine apk upload may take longer than what the default timeout (assuming there is one) allows for.

Comment on lines +73 to +74
while tests_status == "running":
time.sleep(30)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have an overall timeout for this loop?

)
print("=" * 30)
if tests_status != "passed":
raise Exception("Tests failed. Go to the link above for more details.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: include the link directly as there could (in theory) be other output when the CI runs that makes 'above' unclear.

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.

3 participants