-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Migrate Android Java E2E tests from App Center to Browserstack #22117
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
09db4d6
add browserstack script + modified android java test yaml
carzh 3d6c230
updated device handling
carzh 4cd317e
adapted script to be extensible to apple test
carzh 1a2ae52
lint + forgot to update flags in yaml
carzh 9582b79
restructured python script + swapped to environment variables instead…
carzh 421f820
removed check for error in JSON dict
carzh 3a1dc6f
applied suggestions to make yml file cleaner
carzh cfbaf37
Merge remote-tracking branch 'msft/main' into carzh/browserstack-andr…
carzh be677ff
applied suggestions: switched to pathlib.path, added check for env va…
carzh c7a2d52
applied suggestions: added script timeouts + added more docs
carzh d0d4a0a
lintrunner
carzh eab66f6
Update tools/python/upload_and_run_browserstack_tests.py
carzh 32febe9
Update tools/python/upload_and_run_browserstack_tests.py
carzh cd8bd54
added rel tag for paths & updated help dialogue for apk path args to …
carzh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import argparse | ||
|
||
import json | ||
import time | ||
|
||
import requests | ||
|
||
parser = argparse.ArgumentParser("Upload and run BrowserStack tests") | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
parser.add_argument("--id", type=str, help="BrowserStack user ID") | ||
parser.add_argument("--token", type=str, help="BrowserStack token") | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
parser.add_argument("--test_platform", type=str, help="Testing platform, i.e., XCUITest or Espresso") | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
parser.add_argument("--app_apk_path", type=str, help="Path to the app APK") | ||
parser.add_argument("--test_apk_path", type=str, help="Path to the test suite APK") | ||
parser.add_argument( | ||
"--devices", | ||
type=str, | ||
nargs="+", | ||
help="List of devices to run the tests on. For more info, " | ||
"see https://www.browserstack.com/docs/app-automate/espresso/specify-devices", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
def post_response_to_json(response): | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if len(response) == 0: | ||
raise Exception("No response from BrowserStack") | ||
try: | ||
json_response = json.loads(response) | ||
print("JSON response: ", json.dumps(json_response, indent=2)) | ||
if "error" in json_response: | ||
raise Exception(json_response["error"]) | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return json_response | ||
except Exception as e: | ||
print("response received: ", response) | ||
raise Exception("Invalid JSON response from BrowserStack") from e | ||
|
||
|
||
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)) | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return post_response_to_json(response.text) | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
upload_app_json = upload_apk_parse_json( | ||
f"https://api-cloud.browserstack.com/app-automate/{args.test_platform}/v2/app", args.app_apk_path | ||
) | ||
upload_test_json = upload_apk_parse_json( | ||
f"https://api-cloud.browserstack.com/app-automate/{args.test_platform}/v2/test-suite", args.test_apk_path | ||
) | ||
|
||
headers = {} | ||
|
||
json_data = { | ||
"devices": args.devices, | ||
"app": upload_app_json["app_url"], | ||
"testSuite": upload_test_json["test_suite_url"], | ||
} | ||
|
||
build_response = requests.post( | ||
"https://api-cloud.browserstack.com/app-automate/" + args.test_platform + "/v2/build", | ||
headers=headers, | ||
json=json_data, | ||
auth=(args.id, args.token), | ||
) | ||
|
||
build_response_json = post_response_to_json(build_response.text) | ||
|
||
# GET TEST RESULTS | ||
|
||
tests_status = "running" | ||
|
||
while tests_status == "running": | ||
time.sleep(30) | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
test_response = requests.get( | ||
"https://api-cloud.browserstack.com/app-automate/{test_platform}/v2/builds/{build_id}".format( | ||
test_platform=args.test_platform, build_id=build_response_json["build_id"] | ||
), | ||
auth=(args.id, args.token), | ||
) | ||
|
||
test_response_json = post_response_to_json(test_response.text) | ||
|
||
tests_status = test_response_json["status"] | ||
|
||
print("=" * 30) | ||
print( | ||
"Test suite details: ", | ||
"https://app-automate.browserstack.com/dashboard/v2/builds/" + build_response_json["build_id"], | ||
) | ||
print("=" * 30) | ||
if tests_status != "passed": | ||
raise Exception("Tests failed. Go to the link above for more details.") | ||
carzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.