Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / testing / performance / hooks_recording.py
blob9fed95e9544ae02a84973628ae5a007b90cf109f
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 import json
5 import os
6 import platform
7 from pathlib import Path
9 from mozperftest.test.browsertime import add_option, add_options
11 # Uncomment the manual_login line if you need to do a manual login.
12 # The extra browsertime arguments get overwritten below so they
13 # need to be set here. The value is the time you need to do a login.
14 options = [
15 ("pageCompleteWaitTime", "10000"),
16 # ("browsertime.manual_login", 100000),
19 next_site = None
21 RECORDING_LIST = Path(Path(__file__).parent, "pageload_sites.json")
23 # Uncomment this to record tp7 desktop sites in CI or locally.
24 # This is still a WIP (Bug 1831310) and meant to be used by the
25 # perftest team.
26 # RECORDING_LIST = Path(Path(__file__).parent, "tp7_desktop_sites.json")
28 SCM_1_LOGIN_SITES = ("facebook", "netflix")
31 def before_iterations(kw):
32 global next_site
33 print("Setting up next site to record.")
35 with RECORDING_LIST.open() as f:
36 site_list = json.load(f)
37 # currently can't record websites that require user interactions(Logins)
38 if kw.get("android"):
39 site_list = site_list["mobile"]
40 else:
41 site_list = site_list["desktop"]
43 def __should_record(test):
44 # If a test page selection was provided, only select those
45 # tests and exclude all the others
46 specified_tests = kw["proxy_perftest_page"]
47 if specified_tests is not None:
48 if test.get("name") == specified_tests:
49 if test.get("login"):
50 print(f"WARNING: You selected a login test: {test.get('name')}")
51 return True
52 else:
53 return False
55 # Only perform login recordings in automation or when
56 # RAPTOR_LOGINS is defined
57 record = False
58 if not test.get("login") or test.get("login-test"):
59 record = True
60 if not (
61 "MOZ_AUTOMATION" in os.environ or "RAPTOR_LOGINS" in os.environ
62 ) and test.get("login-test"):
63 record = False
64 print(
65 f"Skipping login test `{test.get('name')}` "
66 f"because login info cannot be obtained."
69 # When pushing to Try, only attempt login recording using the
70 # taskcluster secrets that are associated with SCM level 1 as defined
71 # in `SCM_LVL_1_SITES`.
72 if test.get("login"):
73 if "MOZ_AUTOMATION" in os.environ.keys():
74 if (
75 os.environ.get("MOZ_SCM_LEVEL") == 1
76 and test.get("name") not in SCM_1_LOGIN_SITES
78 print(
79 f"Skipping login test `{test.get('name')}` "
80 f"Because SCM = `{os.environ.get('MOZ_SCM_LEVEL') }`"
81 f"and there is no secret available at this level"
83 return False
84 return True
85 elif "RAPTOR_LOGINS" in os.environ:
86 # Leave it to the user to have properly set up a local json file with
87 # the login websites of interest
88 return True
90 return record
92 sites = [test_site for test_site in site_list if __should_record(test_site)]
94 if not sites:
95 raise Exception("No tests were selected for recording!")
97 def next_site():
98 for site in sites:
99 yield site
101 next_site = next_site()
103 # Set the number of test-iterations to the number of builds
104 kw["test_iterations"] = len(sites)
105 return kw
108 def before_runs(env):
109 global next_site
110 print("Running before_runs")
111 add_options(env, options)
113 if next_site:
114 test_site = next(next_site)
115 print("Next site: %s" % test_site)
117 if env.get_arg("android"):
118 platform_name = "android"
119 app_name = env.get_arg("android-app-name").split(".")[-1]
120 else:
121 platform_name = platform.system().lower()
122 app_name = "firefox"
124 name = [
125 "mitm8",
126 platform_name,
127 "gve" if app_name == "geckoview_example" else app_name,
128 test_site["name"],
131 recording_file = "%s.zip" % "-".join(name)
133 env.set_arg("proxy-mode", "record")
134 env.set_arg(
135 "proxy-file",
136 recording_file,
139 add_options(env, options, overwrite=True)
140 add_option(env, "browsertime.url", test_site.get("test_url"))
141 add_option(env, "browsertime.screenshot", "true")
142 add_option(env, "browsertime.testName", test_site.get("name"))
143 add_option(env, "browsertime.testType", test_site.get("type", "pageload"))
144 add_option(
145 env, "browsertime.login", "true" if test_site.get("login") else "false"
148 prefs = test_site.get("preferences", {})
149 for pref, val in prefs.items():
150 add_option(env, "firefox.preference", f"{pref}:{val}")
152 # Add prefs that will attempt to remove cookie banners
153 add_option(
154 env, "firefox.preference", "cookiebanners.bannerClicking.enabled:true"
156 add_option(env, "firefox.preference", "cookiebanners.service.mode:2")
158 second_url = test_site.get("secondary_url", None)
159 if second_url:
160 add_option(env, "browsertime.secondary_url", second_url)
162 inject_deterministic = test_site.get("inject_deterministic", True)
163 env.set_arg("proxy-deterministic", inject_deterministic)
165 dismiss_cookie_prompt = test_site.get("dismiss_cookie_prompt", [])
166 if dismiss_cookie_prompt:
167 parsed_cmds = [
168 ":::".join([str(i) for i in item])
169 for item in dismiss_cookie_prompt
170 if item
172 add_option(
173 env, "browsertime.dismiss_cookie_prompt", ";;;".join(parsed_cmds)
176 cmds = test_site.get("test_cmds", [])
177 if cmds:
178 parsed_cmds = [":::".join([str(i) for i in item]) for item in cmds if item]
179 add_option(env, "browsertime.commands", ";;;".join(parsed_cmds))
181 print("Recording %s to file: %s" % (test_site.get("test_url"), recording_file))