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 SCM_1_LOGIN_SITES
= ("facebook", "netflix")
26 def before_iterations(kw
):
28 print("Setting up next site to record.")
30 with RECORDING_LIST
.open() as f
:
31 site_list
= json
.load(f
)
32 # currently can't record websites that require user interactions(Logins)
34 site_list
= site_list
["mobile"]
36 site_list
= site_list
["desktop"]
38 def __should_record(test
):
39 # If a test page selection was provided, only select those
40 # tests and exclude all the others
41 specified_tests
= kw
["proxy_perftest_page"]
42 if specified_tests
is not None:
43 if test
.get("name") in specified_tests
:
45 print(f
"WARNING: You selected a login test: {test.get('name')}")
50 # Only perform login recordings in automation or when
51 # RAPTOR_LOGINS is defined
53 if not test
.get("login") or test
.get("login-test"):
56 "MOZ_AUTOMATION" in os
.environ
or "RAPTOR_LOGINS" in os
.environ
57 ) and test
.get("login-test"):
60 f
"Skipping login test `{test.get('name')}` "
61 f
"because login info cannot be obtained."
64 # When pushing to Try, only attempt login recording using the
65 # taskcluster secrets that are associated with SCM level 1 as defined
66 # in `SCM_LVL_1_SITES`.
68 if "MOZ_AUTOMATION" in os
.environ
.keys():
70 os
.environ
.get("MOZ_SCM_LEVEL") == 1
71 and test
.get("name") not in SCM_1_LOGIN_SITES
74 f
"Skipping login test `{test.get('name')}` "
75 f
"Because SCM = `{os.environ.get('MOZ_SCM_LEVEL') }`"
76 f
"and there is no secret available at this level"
80 elif "RAPTOR_LOGINS" in os
.environ
:
81 # Leave it to the user to have properly set up a local json file with
82 # the login websites of interest
87 sites
= [test_site
for test_site
in site_list
if __should_record(test_site
)]
90 raise Exception("No tests were selected for recording!")
96 next_site
= next_site()
98 # Set the number of test-iterations to the number of builds
99 kw
["test_iterations"] = len(sites
)
103 def before_runs(env
):
105 print("Running before_runs")
106 add_options(env
, options
)
109 test_site
= next(next_site
)
110 print("Next site: %s" % test_site
)
112 if env
.get_arg("android"):
113 platform_name
= "android"
114 app_name
= env
.get_arg("android-app-name").split(".")[-1]
116 platform_name
= platform
.system().lower()
122 "gve" if app_name
== "geckoview_example" else app_name
,
126 recording_file
= "%s.zip" % "-".join(name
)
128 env
.set_arg("proxy-mode", "record")
134 add_options(env
, options
, overwrite
=True)
135 add_option(env
, "browsertime.url", test_site
.get("test_url"))
136 add_option(env
, "browsertime.screenshot", "true")
137 add_option(env
, "browsertime.testName", test_site
.get("name"))
138 add_option(env
, "browsertime.testType", test_site
.get("type", "pageload"))
140 env
, "browsertime.login", "true" if test_site
.get("login") else "false"
143 prefs
= test_site
.get("preferences", {})
144 for pref
, val
in prefs
.items():
145 add_option(env
, "firefox.preference", f
"{pref}:{val}")
147 second_url
= test_site
.get("secondary_url", None)
149 add_option(env
, "browsertime.secondary_url", second_url
)
151 inject_deterministic
= test_site
.get("inject_deterministic", True)
152 env
.set_arg("proxy-deterministic", inject_deterministic
)
154 dismiss_cookie_prompt
= test_site
.get("dismiss_cookie_prompt", [])
155 if dismiss_cookie_prompt
:
157 ":::".join([str(i
) for i
in item
])
158 for item
in dismiss_cookie_prompt
162 env
, "browsertime.dismiss_cookie_prompt", ";;;".join(parsed_cmds
)
165 cmds
= test_site
.get("test_cmds", [])
167 parsed_cmds
= [":::".join([str(i
) for i
in item
]) for item
in cmds
if item
]
168 add_option(env
, "browsertime.commands", ";;;".join(parsed_cmds
))
170 print("Recording %s to file: %s" % (test_site
.get("test_url"), recording_file
))