From 3f6e4aaf9d7d8c6a70a577deb8b3a02fe688c965 Mon Sep 17 00:00:00 2001 From: Benjamin Forehand Jr Date: Wed, 29 May 2024 22:53:17 +0000 Subject: [PATCH] Bug 1899415 - Update Android smoke test generator for experiments. r=aaronmt DONTBUILD Differential Revision: https://phabricator.services.mozilla.com/D211936 --- .../SurveyExperimentIntegrationTest.kt | 2 - .../generate_smoke_tests.py | 38 ++++++++++++++----- .../fenix/experimentintegration/pytest.ini | 2 +- .../experimentintegration/variables.yaml | 29 +++++++++++++- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/SurveyExperimentIntegrationTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/SurveyExperimentIntegrationTest.kt index 146f48678292..524979fda902 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/SurveyExperimentIntegrationTest.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/SurveyExperimentIntegrationTest.kt @@ -92,7 +92,5 @@ class SurveyExperimentIntegrationTest { }.clickNoThanksSurveyButton { verifyTabCounter("0") } - - checkExperimentExists() } } diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py index a9066021a0c0..ddc5445044c2 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py @@ -1,8 +1,20 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import argparse import subprocess from pathlib import Path import yaml +parser = argparse.ArgumentParser("Options for android apk downloader") + +parser.add_argument( + "--test-files", nargs="+", help="List of test files to generate tests from" +) +args = parser.parse_args() + def search_for_smoke_tests(tests_name): """Searches for smoke tests within the requested test module.""" @@ -21,16 +33,16 @@ def search_for_smoke_tests(tests_name): code = file.read().split(" ") code = [item for item in code if item != ""] + # Gets the class name from the path e.g.: .ui/HomescreenTest.kt + class_name = f"{file_name.name.strip('kt').strip('.').split('/')[-1]}" + + # This is a custom annotation found in fenix/customannotations/SmokeTest.kt for count, item in enumerate(code): - if "class" in item or "@SmokeTest" in item: + if "@SmokeTest" in item: locations.append(count) for location in locations: - if len(test_names) == 0: - class_name = code[location + 1] - test_names.append(class_name) - else: - test_names.append(f"{class_name}#{code[location+3].strip('()')}") + test_names.append(f"{class_name}#{code[location+3].strip('()')}") return test_names @@ -72,10 +84,16 @@ def test_smoke_{test_name}(setup_experiment, gradlewbuild): if __name__ == "__main__": - test_modules = None + test_modules = [] + args = parser.parse_args() + if args.test_files: + test_modules = args.test_files + else: + with open("variables.yaml", "r") as file: + tests = yaml.safe_load(file) + test_modules = [test for test in tests.get("smoke_tests")] create_test_file() - with open("variables.yaml", "r") as file: - test_modules = yaml.safe_load(file) - for item in test_modules.get("smoke_tests"): + print(f"Created tests for modules: {test_modules}") + for item in test_modules: tests = search_for_smoke_tests(item) generate_smoke_tests(tests) diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/pytest.ini b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/pytest.ini index b95f3fef333a..b7f76b751648 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/pytest.ini +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/pytest.ini @@ -3,6 +3,6 @@ addopts = --verbose --html=results/index.html --self-contained-html --variables= log_cli = true log_cli_level = info markers = - smoke: Smoke tests + smoke_test: Smoke tests messaging_survey: Survey message experiments messaging_homescreen: homescreen message experiments diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/variables.yaml b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/variables.yaml index 2b8cf67b837e..112d91f149bc 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/variables.yaml +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/variables.yaml @@ -7,4 +7,31 @@ urls: prod_server: "https://experimenter.services.mozilla.com" telemetry_server: "http://172.25.58.187:5000" smoke_tests: - - "AddressAutofillTest" + - AddressAutofillTest + - BookmarksTest + - CookieBannerBlockerTest + - CrashReportingTest + - CreditCardAutofillTest + - CustomTabsTest + - DownloadTest + - EnhancedTrackingProtectionTest + - FirefoxSuggestTest + - HistoryTest + - HomeScreenTest + - LoginsTest + - MainMenuTest + - MediaNotificationTest + - OnboardingTest + - PDFViewerTest + - RecentlyClosedTabsTest + - SearchTest + - SettingsDeleteBrowsingDataTest + - SettingsAddonsTest + - SettingsGeneralTest + - SettingsHomepageTest + - SettingsSearchTest + - SitePermissionsTest + - SponsoredShortcutsTest + - TabbedBrowsingTest + - TextSelectionTest + - TopSitesTest