angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Error connecting to Firefox when launched with a profile. #5259

Open JasonRhoades opened 5 years ago

JasonRhoades commented 5 years ago

Bug report

For our application, we need to have a specific addon running in Firefox. To do this, we set it up in the default profile, and then try to run the tests. However, when the profile argument is present, while Firefox is launched, webdriver never manages to connect to it.

Running against Selenium server, the following console output appears:

15:37:04.896 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "firefox",
  "count": 1,
  "moz:firefoxOptions": {
    "args": [
      "-P \"Default\""
    ]
  }
}
15:37:04.897 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
1560454625139   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-P \"Default\"" "-foreground" "-no-remote"

1560454626372   Marionette  INFO    Listening on port 36321
console.error: BroadcastService: 
  receivedBroadcastMessage: handler for
  remote-settings/monitor_changes
  threw error:
  Message: Error: Polling for changes failed: http://%(server)s/dummy/blocklist//buckets/monitor/collections/changes/records?_expected=%221560429929334%22 is not a valid URL..
  Stack:
    remoteSettingsFunction/remoteSettings.pollChanges@resource://services-settings/remote-settings.js:203:13

Exiting due to channel error.

However, when the -P "Default" argument is removed, Firefox launches and the test goes through successfully:

16:22:05.238 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "firefox",
  "count": 1,
  "moz:firefoxOptions": {
  }
}
16:22:05.240 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
1560457325447   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.Ln4a7OYWXpdO"
1560457325874   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1560457325874   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1560457325874   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1560457327645   Marionette  INFO    Listening on port 33373
16:22:07.714 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
16:22:07.773 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 46a8a57a-5e90-4b71-92bd-eede904d9d84 (org.openqa.selenium.firefox.GeckoDriverService)

This also happens running with DirectConnect. Running with a profile and the given add-on actually does work with Chrome, but we have a requirement to test against Firefox.

config.ts:

import { Config } from 'protractor';

export let config: Config = {
    rootPath: 'http://localhost:4200',
    //directConnect: true,
    specs: ['src/**/*.spec.js'],
    SELENIUM_PROMISE_MANAGER: false,
    seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        browserName: 'firefox',

        'moz:firefoxOptions': {
            args: ['-P "Default"']
        }
    }
};
dantran commented 5 years ago

maybe related to this https://github.com/mozilla/geckodriver/issues/1559 and your firefox DOA

Sobi33 commented 5 years ago

is this issue currently open or do we have something to work around ?

rjendoubi commented 3 years ago

Not sure if it's related (looks like our environments are very different) but I was having a similar issue in Python. When trying to instantiate a Firefox driver with a specified profile dir, it would hang, and eventually fail with "Exiting due to channel error" written to geckodriver.log. When running exactly the same code without specifying a profile dir (so a random, temporary one is created), it ran fine.

After a lot of searching I came across this comment in another thread:

it's a problem with the custom profile. You will have to add a fixed Marionette port to the profile's preferences (prefs.js) and then force geckodriver via services args to make connect to that port.

Sure enough, once I specified a port for Marionette, starting up with a specified profile just started working :star2: For me, this meant adding the following to my instantiation of the driver:

opts = FirefoxOptions()
opts.add_argument("-profile")
opts.add_argument(str(PROFILE_LOCATION)]:

driver = Firefox(
    executable_path=DRIVER_EXECUTABLE_PATH,
    options=opts,
    service_args=["--marionette-port", "2828"],       # <-- This was the key part I was missing
)

In fairness, if I had been more attentive in copying the code for specifying the profile to use from the docs in the first place, I wouldn't have encountered the issue :man_shrugging:

Would love to know why. Per that comment I had a look in the prefs.js of a couple of the profiles I was trying to use. The only mention of Marionette in there was the line user_pref("marionette.enabled", true); Presumably if one doesn't specify a profile, then some part of the stack (Selenium? geckodriver itself?) creates the temporary profile and wires up a Marionette port automatically... would be nice if it did that also when specifying a custom profile which doesn't otherwise specify a Marionette port.

Anyway, hope this might help you out :sun_with_face: Would be interested to see what the JS equivalent looks like.