david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

console (in)visible? #7

Closed stuart-little closed 3 years ago

stuart-little commented 3 years ago

I cannot seem to be able to get this to work. The docs say that the console option can make the latter visible, but if I run

my $firefox = Firefox::Marionette->new(
    console => 1,
    visible => 1,
    sleep_time_in_ms => 2000,
    )->go($url);

I see no console. Am I supposed to pass something other than a 1 there? The documentation is a bit unclear on how to actually turn this on..

stuart-little commented 3 years ago

Minimal working example:

#!/usr/bin/env perl
use warnings;
use v5.12;

use Firefox::Marionette;

my $firefox = Firefox::Marionette->new(
    console => 1,
    visible => 1,
    );

sleep;

A browser window opens, but there's simply no console there.

david-dick commented 3 years ago

That's a little disappointing. The console parameter simply adds "--jsconsole" to the command line arguments when starting firefox.

Can you send me your operating system, the output of "firefox --version" and the output of "firefox --help"?

stuart-little commented 3 years ago
$ uname -a
---
Linux system76-pc 5.12.0-76w-wg #1 SMP Sun Apr 25 22:29:09 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ firefox --version
---
Mozilla Firefox 88.0

firefox --help produces longer output, so I've pasted it here.

There is a --jsconsole option. If I run firefox --jsconsole in a terminal I get just the console, with a bunch of errors about not being able to find favicons and such. In fact, you can see a screenshot here.

Oh, and one more thing: the har option works just fine. If I instantiate the object with har => 1 then I do get the devtools, open on the inspector tab.

david-dick commented 3 years ago

Okay. That's going to be difficult for me to get running in a vm. If you run your sample code again, but add (debug => 1) to the new method parameters, you should be able to see the complete command line that the module exec's. Could you try running that command line in a shell and see if you get the same result as you are getting when you run the code?

If that works, we can check what combination of command line arguments are required to get the console and the browser window to both open.

stuart-little commented 3 years ago

If I simply add debug => 1 to the options I showed above I get the following in the console:

<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 692:[1,1,null,{"sessionId":"5fa3be51-26e6-4e75-b6f5-76f96de0f474","capabilities":{"browserName":"firefox","browserVersion":"88.0","platformName":"linux","platformVersion":"5.12.0-76w-wg","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210415204500","moz:headless":false,"moz:processID":995879,"moz:profile":"/tmp/firefox_marionette_local_qc2xifM8P53/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]

I've grepped: there's no trace of the string js in there, let alone jsconsole. So it seems the console => 1 options is simply being ignored.

david-dick commented 3 years ago

actually, it looks like i can download https://pop.system76.com/ (which i am assuming is your OS?). I'll see if i can replicate the issue.

stuart-little commented 3 years ago

It's Ubuntu 20.04.

Your precise command line (that I copy-pasted from your post above) gives me back

<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 692:[1,1,null,{"sessionId":"67bf74ae-9995-479b-9c74-0d333b0d23a8","capabilities":{"browserName":"firefox","browserVersion":"88.0","platformName":"linux","platformVersion":"5.12.0-76w-wg","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210415204500","moz:headless":false,"moz:processID":998442,"moz:profile":"/tmp/firefox_marionette_local_DC88dhghFdG/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
>> 143:[0,2,"WebDriver:Navigate",{"sessionId":"67bf74ae-9995-479b-9c74-0d333b0d23a8","url":"https://www.google.com","value":"https://www.google.com"}]
<< 25:[1,2,null,{"value":null}]
>> 50:[0,3,"Marionette:Quit",{"flags":["eAttemptQuit"]}]
<< 46:[1,3,null,{"cause":"shutdown","forced":false}]
david-dick commented 3 years ago

okay. something weird is going on. i'll get back to you.

stuart-little commented 3 years ago

Thanks!

By the way, we'd better not get too hung up on the precise flavor of Linux-based OS. Here's what I'm getting on Arch (my other laptop):

$ perl -Ilib -MFirefox::Marionette -e 'my $firefox = Firefox::Marionette->new( debug => 1, console => 1, visible => 1)->go(q[https://www.google.com])->quit();'
<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 695:[1,1,null,{"sessionId":"4046f4a5-b117-4fa2-a86a-4522df9bd684","capabilities":{"browserName":"firefox","browserVersion":"88.0.1","platformName":"linux","platformVersion":"5.10.25-1-lts","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210504152106","moz:headless":false,"moz:processID":2171225,"moz:profile":"/tmp/firefox_marionette_local_Dm4OFjZaSr0/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
>> 143:[0,2,"WebDriver:Navigate",{"sessionId":"4046f4a5-b117-4fa2-a86a-4522df9bd684","url":"https://www.google.com","value":"https://www.google.com"}]
<< 25:[1,2,null,{"value":null}]
>> 50:[0,3,"Marionette:Quit",{"flags":["eAttemptQuit"]}]
<< 46:[1,3,null,{"cause":"shutdown","forced":false}]
david-dick commented 3 years ago

Okay. I can't reproduce this issue. Can you run the following bits of code? I want to see if firefox itself is aware of different windows, even though they cannot be seen.

$ perl -Ilib -MFirefox::Marionette -MData::Dumper -e 'my $firefox = Firefox::Marionette->new( debug => 1, visible => 1); print Dumper($firefox->chrome_window_handles());'

$ perl -Ilib -MFirefox::Marionette -MData::Dumper -e 'my $firefox = Firefox::Marionette->new( debug => 1, console => 1, visible => 1); print Dumper($firefox->chrome_window_handles());'

When the console window is active, it should show two separate handles

stuart-little commented 3 years ago

Sure looks to me like a single window handle both times..

First one:

<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 695:[1,1,null,{"sessionId":"017c3bc7-1c02-4445-8460-bcfa3539f5e1","capabilities":{"browserName":"firefox","browserVersion":"88.0.1","platformName":"linux","platformVersion":"5.10.25-1-lts","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210504152106","moz:headless":false,"moz:processID":2179268,"moz:profile":"/tmp/firefox_marionette_local_6c3V6a9ku3U/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
>> 40:[0,2,"WebDriver:GetChromeWindowHandles"]
<< 17:[1,2,null,["20"]]
>> 50:[0,3,"Marionette:Quit",{"flags":["eAttemptQuit"]}]
<< 46:[1,3,null,{"cause":"shutdown","forced":false}]
$VAR1 = '20';

Second one:

<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 695:[1,1,null,{"sessionId":"a2b26114-49ed-4914-b611-b566881e4efb","capabilities":{"browserName":"firefox","browserVersion":"88.0.1","platformName":"linux","platformVersion":"5.10.25-1-lts","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210504152106","moz:headless":false,"moz:processID":2179752,"moz:profile":"/tmp/firefox_marionette_local_MD1GrGMPuK5/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
>> 40:[0,2,"WebDriver:GetChromeWindowHandles"]
<< 17:[1,2,null,["20"]]
>> 50:[0,3,"Marionette:Quit",{"flags":["eAttemptQuit"]}]
<< 46:[1,3,null,{"cause":"shutdown","forced":false}]
$VAR1 = '20';
david-dick commented 3 years ago

Are you using snaps or buildah/docker or any other sort of container/virtualisation technology?

stuart-little commented 3 years ago

No: the two OSs are just plain installed on the two laptops, nothing fancy. Firefox is whatever the OS provides, on each computer (Ubuntu 20.04 on one, Arch on the other).

I do run perl through perlbrew on both (v5.33.9), but I've tested with the system perl too, on both machines (5.32 on Arch and the older 5.30 on Ubuntu). The results are the same every time: even when I run your second command line, with the console => 1 option, I still get back the single handle $VAR1 = '20'.

stuart-little commented 3 years ago

By the way, this may be an aside (I didn't want to open a new issue, but can if you think there's a point to it):

Is it possible to send keys, such as Control or Shift (rather than just text, as per the docs)?

This came up as I was trying to find a workaround to the present issue we're discussing here.

In Python's Selenium Webdriver I can do something like this to open the console inside a window:

with webdriver.context(webdriver.CONTEXT_CHROME):
        win = webdriver.find_element(By.ID, "main-window")
        win.send_keys(Keys.LEFT_CONTROL + Keys.LEFT_SHIFT + 'k')

That will find the main window in CHROME context and send it the combo Ctrl+Shift+k, opening the console and giving me focus inside it (I've tested that I can then further send keys to that console, etc.).

Is such a thing possible in Firefox::Marionette?

stuart-little commented 3 years ago

Hang on a minute! I apologize: the command I was running,

perl -Ilib -MFirefox::Marionette -MData::Dumper -e 'my $firefox = Firefox::Marionette->new( debug => 1, console => 1, visible => 1); print Dumper($firefox->chrome_window_handles());'

was still using my CPAN-installed version: I did not understand you wanted me to run it inside the cloned repo..

If I run it there (i.e. clone this repo, move into its directory and run the command) then I do get two window handles:

<< 50:{"applicationType":"gecko","marionetteProtocol":3}
>> 73:[0,1,"WebDriver:NewSession",{"capabilities":{"requiredCapabilities":{}}}]
<< 693:[1,1,null,{"sessionId":"2bdbf33b-e79b-4c72-b982-41672af9a092","capabilities":{"browserName":"firefox","browserVersion":"88.0","platformName":"linux","platformVersion":"5.12.0-76w-wg","acceptInsecureCerts":false,"pageLoadStrategy":"normal","setWindowRect":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"strictFileInteractability":false,"unhandledPromptBehavior":"dismiss and notify","rotatable":false,"moz:accessibilityChecks":false,"moz:buildID":"20210415204500","moz:headless":false,"moz:processID":1122403,"moz:profile":"/tmp/firefox_marionette_local_2_MmhEzugTK/profile","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
>> 40:[0,2,"WebDriver:GetChromeWindowHandles"]
<< 22:[1,2,null,["20","22"]]
$VAR1 = '20';
$VAR2 = '22';
>> 50:[0,3,"Marionette:Quit",{"flags":["eAttemptQuit"]}]
<< 46:[1,3,null,{"cause":"shutdown","forced":false}]

So something seems to be off in the CPAN version.

stuart-little commented 3 years ago

More evidence that the current github version is fine: if I run my original "minimal example" with

perl -Ilib <path-to-script>

inside the repo directory I do get the console.

david-dick commented 3 years ago

okay. that's something. i'm flat out at work atm. i might get some more time tomorrow. file another bug for the special keys, that looks like a good feature request.

What version number was the malfunctioning CPAN version?

stuart-little commented 3 years ago

I'm seeing 0.98 on one of the computers. The other one I've already updated to 1.05, which works fine.

So I just had a stale version.. When I moved to perlbrew I kept the system-installed version, which the perlbrew installation defaulted to.

In short: there's nothing wrong at all, except for my failure to update my modules :).

david-dick commented 3 years ago

okay, so it's okay to close this one then?

stuart-little commented 3 years ago

Absolutely, and thank you!