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/.
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.
15 ("pageCompleteWaitTime", "10000"),
16 # ("browsertime.manual_login", 100000),
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
26 # RECORDING_LIST = Path(Path(__file__).parent, "tp7_desktop_sites.json")
28 SCM_1_LOGIN_SITES
= ("facebook", "netflix")
31 def before_iterations(kw
):
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)
39 site_list
= site_list
["mobile"]
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
:
50 print(f
"WARNING: You selected a login test: {test.get('name')}")
55 # Only perform login recordings in automation or when
56 # RAPTOR_LOGINS is defined
58 if not test
.get("login") or test
.get("login-test"):
61 "MOZ_AUTOMATION" in os
.environ
or "RAPTOR_LOGINS" in os
.environ
62 ) and test
.get("login-test"):
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`.
73 if "MOZ_AUTOMATION" in os
.environ
.keys():
75 os
.environ
.get("MOZ_SCM_LEVEL") == 1
76 and test
.get("name") not in SCM_1_LOGIN_SITES
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"
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
92 sites
= [test_site
for test_site
in site_list
if __should_record(test_site
)]
95 raise Exception("No tests were selected for recording!")
101 next_site
= next_site()
103 # Set the number of test-iterations to the number of builds
104 kw
["test_iterations"] = len(sites
)
108 def before_runs(env
):
110 print("Running before_runs")
111 add_options(env
, options
)
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]
121 platform_name
= platform
.system().lower()
127 "gve" if app_name
== "geckoview_example" else app_name
,
131 recording_file
= "%s.zip" % "-".join(name
)
133 env
.set_arg("proxy-mode", "record")
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"))
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
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)
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
:
168 ":::".join([str(i
) for i
in item
])
169 for item
in dismiss_cookie_prompt
173 env
, "browsertime.dismiss_cookie_prompt", ";;;".join(parsed_cmds
)
176 cmds
= test_site
.get("test_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
))