Bug 1782184 - Move first load prompts handling code under interactive tests r=perftest-reviewers,kshampur

The cookie prompt handling code was initially added under `test_cmds` but it got in conflict with the interactive sites code (the prompts are for pageload sites while the interactive sites are a different type).
This patch is adding a new section in the json that is specially for handling the cookie prompts for pageload sites. We have to handle prompts for the login sites. but we don't currently encounter those prompts on CI and locally the login code doesn't work ATM. So this affects local site recording from Europe.

Differential Revision: https://phabricator.services.mozilla.com/D153748
This commit is contained in:
Alex Ionescu 2022-08-09 14:55:55 +00:00
Родитель 03cc630a3f
Коммит 6ce6e42c08
3 изменённых файлов: 107 добавлений и 73 удалений

Просмотреть файл

@ -147,6 +147,17 @@ def before_runs(env):
inject_deterministic = test_site.get("inject_deterministic", True)
env.set_arg("proxy-deterministic", inject_deterministic)
dismiss_cookie_prompt = test_site.get("dismiss_cookie_prompt", [])
if dismiss_cookie_prompt:
parsed_cmds = [
":::".join([str(i) for i in item])
for item in dismiss_cookie_prompt
if item
]
add_option(
env, "browsertime.dismiss_cookie_prompt", ";;;".join(parsed_cmds)
)
cmds = test_site.get("test_cmds", [])
if cmds:
parsed_cmds = [":::".join([str(i) for i in item]) for item in cmds if item]

Просмотреть файл

@ -3,7 +3,10 @@
{
"login": false,
"name": "allrecipes",
"test_url": "https://www.allrecipes.com/"
"test_url": "https://www.allrecipes.com/",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='onetrust-reject-all-handler']"]
]
},
{
"login": false,
@ -18,28 +21,46 @@
{
"login": false,
"name": "bing",
"test_url": "https://www.bing.com/"
"test_url": "https://www.bing.com/",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='bnp_btn_reject']"]
]
},
{
"login": false,
"name": "bing-search-restaurants",
"test_url": "https://www.bing.com/search?q=restaurants+in+exton+pa+19341"
"test_url": "https://www.bing.com/search?q=restaurants+in+exton+pa+19341",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='bnp_btn_reject']"]
]
},
{
"login": false,
"name": "booking",
"test_url": "https://www.booking.com/"
"test_url": "https://www.booking.com/",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='onetrust-pc-btn-handler']"],
["click.byXpathAndWait", "/html/body/div[5]/div[3]/div[3]/div[1]/button"]
]
},
{
"login": false,
"name": "cnn",
"test_url": "https://cnn.com",
"secondary_url": "https://www.cnn.com/weather"
"secondary_url": "https://www.cnn.com/weather",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='onetrust-pc-btn-handler']"],
["click.byXpathAndWait", "/html/body/div[14]/div[3]/div[3]/div[1]/button[2]"]
]
},
{
"login": false,
"name": "cnn-ampstories",
"test_url": "https://cnn.com/ampstories/us/why-hurricane-michael-is-a-monster-unlike-any-other"
"test_url": "https://cnn.com/ampstories/us/why-hurricane-michael-is-a-monster-unlike-any-other",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='onetrust-pc-btn-handler']"],
["click.byXpathAndWait", "/html/body/div[14]/div[3]/div[3]/div[1]/button[2]"]
]
},
{
"login": false,
@ -119,7 +140,11 @@
{
"login": false,
"name": "web-de",
"test_url": "https://web.de/magazine/politik/politologe-glaubt-grossen-koalition-herbst-knallen-33563566"
"test_url": "https://web.de/magazine/politik/politologe-glaubt-grossen-koalition-herbst-knallen-33563566",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='edit-purpose-settings']"],
["click.byXpathAndWait", "//*[@id='save-purpose-settings']"]
]
},
{
"login": false,
@ -129,12 +154,18 @@
{
"login": false,
"name": "youtube",
"test_url": "https://m.youtube.com"
"test_url": "https://m.youtube.com",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[2]/ytm-consent-bump-v2-renderer/div/div[2]/div[3]/c3-material-button[2]/button/div/div"]
]
},
{
"login": false,
"name": "youtube-watch",
"test_url": "https://www.youtube.com/watch?v=COU5T-Wafa4"
"test_url": "https://www.youtube.com/watch?v=COU5T-Wafa4",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[2]/ytm-consent-bump-v2-renderer/div/div[2]/div[3]/c3-material-button[2]/button/div/div"]
]
}
],
"desktop": [
@ -147,16 +178,18 @@
{
"login": false,
"name": "bing-search",
"test_url": "https://www.bing.com/search?q=barack+obama"
"test_url": "https://www.bing.com/search?q=barack+obama",
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[1]/div[1]/div/div[2]/div[2]/button[2]/a"]
]
},
{
"login": false,
"name": "buzzfeed",
"test_url": "https://www.buzzfeed.com/",
"secondary_url": "https://www.buzzfeed.com/quizzes",
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[2]/div/button[2]"],
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[3]/div[2]/button"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[2]/div/button[2]"]
]
},
{
@ -172,9 +205,9 @@
"media.allowed-to-play.enabled": false,
"media.block-autoplay-until-in-foreground": true
},
"test_cmds": [
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='onetrust-pc-btn-handler']"],
["click.byXpathAndWait", "/html/body/div[13]/div[2]/div/section/div[17]/button[2]"]
["click.byXpathAndWait", "/html/body/div[13]/div[3]/div[3]/div[1]/button[2]"]
]
},
{
@ -182,18 +215,16 @@
"name": "ebay",
"test_url": "https://www.ebay.com/",
"secondary_url": "https://www.ebay.com/deals",
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[5]/div[1]/div[2]/div[2]/div[2]/a"],
["click.byXpathAndWait", "/html/body/div[4]/div/div[2]/section[3]/section/button"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "//*[@id='gdpr-banner-decline']"]
]
},
{
"login": false,
"name": "espn",
"test_url": "http://www.espn.com/nba/story/_/page/allstarweekend25788027/the-comparison-lebron-james-michael-jordan-their-own-words",
"test_cmds": [
["click.byXpathAndWait", "//*[@id='onetrust-pc-btn-handler']"],
["click.byXpathAndWait", "/html/body/div[10]/div[2]/div[3]/div[1]/button"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[10]/div[2]/div/div/div[3]/button"]
]
},
{
@ -206,11 +237,7 @@
"login": true,
"name": "facebook",
"test_url": "https://www.facebook.com",
"secondary_url": "https://www.facebook.com/marketplace/?ref=bookmark",
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[3]/div[2]/div/div/div/div/div[3]/button[1]"],
["click.byXpathAndWait", "/html/body/div[3]/div[2]/div/div/div/div/div[3]/button[1]"]
]
"secondary_url": "https://www.facebook.com/marketplace/?ref=bookmark"
},
{
"login": true,
@ -240,7 +267,7 @@
"login": true,
"name": "google",
"test_url": "https://www.google.com/search?hl=en&q=barack+obama&cad=h",
"test_cmds": [
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[3]/div[3]/span/div/div/div/div[3]/button[1]/div"],
["click.byXpathAndWait", "/html/body/c-wiz/div/div/div/div[2]/form/div/button/div[2]"]
]
@ -260,7 +287,7 @@
"login": true,
"name": "google-mail",
"test_url": "https://mail.google.com/",
"test_cmds": [
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div/div/span[2]/a[2]"]
]
},
@ -281,9 +308,8 @@
"name": "imgur",
"test_url": "https://imgur.com/gallery/m5tYJL6",
"inject_deterministic": false,
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[2]/div/button[2]"],
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[3]/div[2]/button"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[1]/div/div/div/div[2]/div/button[2]"]
],
"secondary_url": "https://imgur.com/gallery/L13Ci",
"preferences": {
@ -311,12 +337,8 @@
"name": "microsoft",
"test_url": "https://www.microsoft.com/en-us/",
"secondary_url": "https://support.microsoft.com/en-us",
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[1]/div/div/div[2]/div/div/div/div[2]/button[2]"],
["click.byXpath", "/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/div/form/dl/dt[2]/div/div/div[2]/label"],
["click.byXpath", "/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/div/form/dl/dt[3]/div/div/div[2]/label"],
["click.byXpath", "/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/div/form/dl/dt[4]/div/div/div[2]/label"],
["click.byXpathAndWait", "/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/div/div[2]/button[1]"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[3]/div[1]/div/div/div[2]/div/div/div/div[2]/button[2]"]
]
},
{
@ -330,9 +352,8 @@
"name": "nytimes",
"test_url": "https://www.nytimes.com/2020/02/19/opinion/surprise-medical-bill.html",
"secondary_url": "https://www.nytimes.com/section/opinion/columnists",
"test_cmds": [
["click.byXpathAndWait", "/html/body/div/div/div[2]/div/div[2]/div/div/div[1]/div[3]/div[3]/a"],
["click.byXpathAndWait", "//*[@id='opt-out-of-new-york-times-nonessential-trackers']"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div/div[2]/main/div[3]/div[2]/div/div[2]/button[2]"]
]
},
{
@ -362,7 +383,7 @@
"name": "reddit",
"test_url": "https://www.reddit.com/r/technology/comments/9sqwyh/we_posed_as_100_senators_to_run_ads_on_facebook/",
"secondary_url": "https://www.reddit.com/r/technology/",
"test_cmds": [
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[1]/div/div[2]/div[3]/div[1]/section/div/section/section/form[1]/button"]
]
},
@ -385,9 +406,9 @@
"media.allowed-to-play.enabled": false,
"media.block-autoplay-until-in-foreground": true
},
"test_cmds": [
["click.byXpathAndWait", "/html/body/div[1]/div/div[2]/div[1]/div/div/div[3]/div/button/div/div/div"],
["click.byXpathAndWait", "/html/body/div[3]/div/div/div/div/div/div[1]/div[2]/div/button/div/div"]
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[1]/div/div[2]/div[1]/div/div/div/div[3]/div/button"],
["click.byXpathAndWait", "/html/body/div[3]/div/div/div/div/div/div[1]/div[2]/div[2]/button"]
]
},
{
@ -400,9 +421,9 @@
"name": "wikia",
"test_url": "https://marvel.fandom.com/wiki/Black_Panther",
"secondary_url": "https://marvel.fandom.com/wiki/Celestials",
"test_cmds": [
"dismiss_cookie_prompt": [
["click.byXpathAndWait", "/html/body/div[6]/div/div/div[2]/div[1]"],
["click.byXpathAndWait", "/html/body/div[7]/div/div/div[2]/div[2]"]
["click.byXpathAndWait", "/html/body/div[6]/div/div/div[2]/div[2]"]
]
},
{
@ -421,12 +442,8 @@
"name": "youtube",
"test_url": "https://www.youtube.com",
"secondary_url": "https://www.youtube.com/watch?v=JrdEMERq8MA",
"test_cmds ": [
["click.byXpathAndWait", "/html/body/ytd-app/ytd-consent-bump-v2-lightbox/tp-yt-paper-dialog/div[4]/div[2]/div[5]/div[2]/ytd-button-renderer[1]/a"],
["click.byXpath", "/html/body/c-wiz/div/div/div/div[2]/div[2]/div[2]/div/div[2]/div[1]/div/button"],
["click.byXpath", "/html/body/c-wiz/div/div/div/div[2]/div[3]/div[2]/div/div[2]/div[1]/div/button"],
["click.byXpath", "/html/body/c-wiz/div/div/div/div[2]/div[4]/div[2]/div[2]/div/div[2]/div[1]/div/button"],
["click.byXpathAndWait", "/html/body/c-wiz/div/div/div/div[2]/form/div/button/div[2]"]
"dismiss_cookie_prompt ": [
["click.byXpathAndWait", "/html/body/ytd-app/ytd-consent-bump-v2-lightbox/tp-yt-paper-dialog/div[4]/div[2]/div[6]/div[1]/ytd-button-renderer[1]/a"]
]
},
{

Просмотреть файл

@ -332,11 +332,34 @@ async function perform_live_login(context, commands) {
await login(context, commands, final_button);
}
async function dismissCookiePrompt(input_cmds, context, commands) {
context.log.info("Searching for cookie prompt elements...");
let cmds = input_cmds.split(";;;");
for (let cmdstr of cmds) {
let [cmd, ...args] = cmdstr.split(":::");
context.log.info(cmd, args);
let result = await commands.js.run(
`return document.evaluate("` +
args +
`", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;`
);
if (result) {
context.log.info("Element found, clicking on it.");
await run_command(cmdstr, context, commands);
} else {
context.log.info(
"Element not found! The cookie prompt may have not appeared, please check the screenshots."
);
}
}
}
async function pageload_test(context, commands) {
let testUrl = context.options.browsertime.url;
let secondaryUrl = context.options.browsertime.secondary_url;
let testName = context.options.browsertime.testName;
let input_cmds = context.options.browsertime.commands || "";
let dismissPrompt = context.options.browsertime.dismiss_cookie_prompt || "";
context.log.info(context.options.browsertime);
// If the user has RAPTOR_LOGINS configured correctly, a local login pageload
// test can be attempted. Otherwise if attempting it in CI, only sites with the
@ -362,26 +385,9 @@ async function pageload_test(context, commands) {
await commands.wait.byTime(1000);
await commands.measure.start(testUrl);
if (input_cmds) {
context.log.info("Searching for cookie prompt elements...");
let cmds = input_cmds.split(";;;");
for (let cmdstr of cmds) {
let [cmd, ...args] = cmdstr.split(":::");
context.log.info(cmd, args);
let result = await commands.js.run(
`return document.evaluate("` +
args +
`", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;`
);
if (result) {
context.log.info("Element found, clicking on it.");
await run_command(cmdstr, context, commands);
} else {
context.log.info(
"Element not found! The cookie prompt may have not appeared, please check the screenshots."
);
}
}
await commands.wait.byTime(40000);
if (dismissPrompt) {
await dismissCookiePrompt(dismissPrompt, context, commands);
}
commands.screenshot.take("test_url_" + testName);