New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Implement Firefox testing with CDP #12971
Conversation
96a5531
to
64b2722
Compare
1ebbbc9
to
d1f1fd3
Compare
b0973c9
to
295c0d2
Compare
New Firefox (firefox-70.0-1.fc31.x86_64 and current nightly) breaks propagation of new contexts. I cannot think of any workaround for this since this is a core functionality that we need. I reported it here. I can either enforce firefox <= 69 in CI or block on that. |
25d5c46
to
05460a1
Compare
uuu, fancy! Only one failure, but it is currently broken |
#13113 landed, this needs a rebase now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this amazing work! As usual, I have a lot of smaller nitpicks, and I'd like to know the next steps for firefox-cdp-driver.js. But let's get this in soon, so that we can split out the work of enabling the remaining tests between multiple persons.
test/common/cdp.py
Outdated
@@ -52,6 +70,8 @@ def __init__(self, lang=None, verbose=False, trace=False, inject_helpers=[]): | |||
self.verbose = verbose | |||
self.trace = trace | |||
self.inject_helpers = inject_helpers | |||
self.browser = "chromium" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would find it nicer to correctly initialize it right here. Something like os.environ.get("TEST_BROWSER", "chromium")
test/common/cdp.py
Outdated
@@ -74,7 +94,9 @@ def invoke(self, fn, **kwargs): | |||
# frame support for Runtime.evaluate(): map frame name to | |||
# executionContextId and insert into argument object; this must not be quoted | |||
# see "Frame tracking" in cdp-driver.js for how this works | |||
if fn == 'Runtime.evaluate' and self.cur_frame: | |||
# Also Firefox always needs context, cannot work with default context. | |||
# TODO: it should be fairly simple for chromium to always work with contexts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you just not try yet, or does this actively break right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did small edit in chrome driver and now this was dropped
test/common/cdp.py
Outdated
@@ -155,6 +212,9 @@ def start(self): | |||
# can fail when a test starts multiple browsers; only show the first one | |||
cdp_port = p | |||
|
|||
if "TEST_BROWSER" in os.environ: | |||
self.browser = os.environ["TEST_BROWSER"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop this, see above.
test/common/cdp.py
Outdated
elif self.browser == "firefox": | ||
subprocess.Popen(["firefox", "--headless", "--no-remote", "-CreateProfile", "blank"], env=env).communicate() | ||
p = subprocess.Popen("ls ~/.mozilla/firefox", shell=True, stdout=subprocess.PIPE, env=env) | ||
in_profile = p.communicate()[0].decode("utf-8").split("\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use os.listdir() here. Also, writing ~
here makes me terribly nervous -- we set $HOME
here, but let's not use os.path.expanduser()
here or ~, but explicitly sef._browser_home
to make sure that we don't write into the real user home.
test/common/cdp.py
Outdated
if item.endswith("blank"): | ||
handler = os.path.join(handler, item, "handlers.json") | ||
userjs = os.path.join(userjs, item, "user.js") | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you don't really need to read the whole directory in the first place? How is that different to simply doing os.path.join(sef._browser_home, "blank")
? (And then tacking on the two *.json, of course).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path looks something like ~/.mozilla/firefox/ldsyl7au.blank/
. I could use glob
though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, sorry -- I misread the code. Yes, glob seems fine indeed.
test/verify/check-sosreport
Outdated
download_dir = tempfile.mkdtemp() | ||
self.addCleanup(shutil.rmtree, download_dir) | ||
b.cdp.invoke("Page.setDownloadBehavior", behavior="allow", downloadPath=download_dir) | ||
for f in glob.glob(os.path.join(b.cdp.download_dir, '*')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but more robust to do that with os.listdir()
. But why does that need to be cleaned in the first place? Every test case starts with a fresh Browser and thus CDP object, and thus a new empty download dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this was thinko since it is created in CDP init and this it is clean for every test.
test/verify/check-menu
Outdated
# HACK: We cannot test axe on Firefox since `axe.run()` returns promise | ||
# and Firefox CDP cannot wait for it to resolve | ||
if b.cdp.browser != "firefox": | ||
self.check_axe("Test-navigation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this hack into the check_axe()
definition itself, instead of into every call (well, two right now, but we'll get more)
fa7ef06
to
7ba5f00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! Just a nitpick, but not crucial to force-push just for that. Let's see what the tests say.
@martinpitt I had to repush as after rebase one test needed a small tweak. Can you please reapprove? |
testPrivateKeys fails an awful lot here. That doesn't ring a bell, I rather retry that one. |
|
Fixed in #13131 |
Firefox CDP is only partially implemented and some major features are missing. Also
chrome-remote-interface
misses some features on Firefox. Therefore I've created new cdp-driver which contains some hacks and workarounds. Since it uses very small subset of cdp protocol, it could be used for chrome as well, but lets keep also the proper driver and hopefully one day we can use that one for all browsers.How to run this: (see note below)
prerequisite: Firefox browser (tested with current F31 Firefox build
69.0.1-3
)TEST_BROWSER=firefox ./test/verify/check-pages TestPages.testBasic -vt
TODO:
1 2