Skip to content
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

[🐛 Bug]: If LoggingPrefs is set, the profile gets lost [Java, Firefox] #10222

Closed
moossenm opened this issue Jan 5, 2022 · 8 comments
Closed

Comments

@moossenm
Copy link

moossenm commented Jan 5, 2022

What happened?

Hi,
i think i found a bug in the latest 4.1.1 Java Version:

I have following piece of code working with v3.x:

FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
String downloadDir = "/path/to/my/dir/";
profile.setPreference("browser.download.dir", downloadDir);
options.addPreference("browser.download.dir", downloadDir);
options.setLogLevel(FirefoxDriverLogLevel.TRACE);
LoggingPreferences logs = new LoggingPreferences();
Level level = Level.ALL;
logs.enable(LogType.DRIVER, level);
logs.enable(LogType.CLIENT, level);
logs.enable(LogType.BROWSER, level);
logs.enable(LogType.SERVER, level);
logs.enable(LogType.PERFORMANCE, level);
logs.enable(LogType.PROFILER, level);
options.setCapability(CapabilityType.LOGGING_PREFS, logs);
options.setProfile(profile);
new FirefoxDriver(options);

as said, this works with v3.x, but in v4.x the profile is not transferred to firefox, the configuration entry browser.download.dir remains unset.
and if i remove the line

options.setCapability(CapabilityType.LOGGING_PREFS,  logs);

then it works fine again.

how can it be that this breaks the profile?
am i doing something wrong here?

i see also the same behaviour using a grid.

many thanks
Michael

How can we reproduce the issue?

FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
String downloadDir = "/path/to/my/dir/";
profile.setPreference("browser.download.dir", downloadDir);
options.addPreference("browser.download.dir", downloadDir);
options.setLogLevel(FirefoxDriverLogLevel.TRACE);
LoggingPreferences logs = new LoggingPreferences();
Level level = Level.ALL;
logs.enable(LogType.DRIVER, level);
logs.enable(LogType.CLIENT, level);
logs.enable(LogType.BROWSER, level);
logs.enable(LogType.SERVER, level);
logs.enable(LogType.PERFORMANCE, level);
logs.enable(LogType.PROFILER, level);
options.setCapability(CapabilityType.LOGGING_PREFS, logs);
options.setProfile(profile);
new FirefoxDriver(options);

Relevant log output

1641376474543	geckodriver	INFO	Listening on 127.0.0.1:51609
1641376480277	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-no-remote" "-profile" "C:\\Users\\moossenm\\AppData\\Local\\Temp\\rust_mozprofileJd5B9U"
1641376480749	Marionette	INFO	Marionette enabled
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\moossenm\\AppData\\Local\\Temp\\rust_mozprofileJd5B9U\\search.json.mozlz4", (void 0)))
1641376483121	Marionette	INFO	Listening on port 50851
1641376483410	RemoteAgent	WARN	TLS certificate errors will be ignored for this session

Operating System

Windows 10, RedHat7

Selenium version

Java 4.1.1

What are the browser(s) and version(s) where you see this issue?

Firefox 95.0.2

What are the browser driver(s) and version(s) where you see this issue?

GeckoDriver 0.30.0

Are you using Selenium Grid?

4.1.0

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

@moossenm, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@pujagani
Copy link
Contributor

@moossenm Thank you for sharing the details! I was able to reproduce the problem. I am trying to look into why the setCapability method is not doing the job. Meanwhile, the example below works.

package com.company;

import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;

import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;

import java.util.logging.Level;

public class FirefoxProfileNotWorking {
  public static void main(String args[]) throws InterruptedException {
    FirefoxOptions options = new FirefoxOptions();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.page", 1);
    profile.setPreference("browser.startup.homepage", "http://google.com");
    options.setLogLevel(FirefoxDriverLogLevel.TRACE);
    LoggingPreferences logs = new LoggingPreferences();
    Level level = Level.ALL;
    logs.enable(LogType.DRIVER, level);
    logs.enable(LogType.CLIENT, level);
    logs.enable(LogType.BROWSER, level);
    logs.enable(LogType.SERVER, level);
    logs.enable(LogType.PERFORMANCE, level);
    logs.enable(LogType.PROFILER, level);
    options.setProfile(profile);
    //options.setCapability(LOGGING_PREFS, logs);
    options.merge(new ImmutableCapabilities(CapabilityType.LOGGING_PREFS, logs));

    FirefoxDriver driver = new FirefoxDriver(options);

    System.out.println(driver.getCapabilities());
    Thread.sleep(5000);
    driver.get("http://www.yahoo.com");
    Thread.sleep(5000);
    driver.quit();
  }
}

The print statement prints the following capabilities:
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 95.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20211218203254, moz:debuggerAddress: localhost:60232, moz:geckodriverVersion: 0.30.0, moz:headless: false, moz:processID: 66809, moz:profile: /var/folders/gf/wjxc6bv113b..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 20.5.0, proxy: Proxy(), se:cdp: ws://localhost:60232/devtoo..., se:cdpVersion: 85, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

Whereas the if setCapability is used the following capabilities are printed:
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 95.0.2, goog:loggingPrefs: {browser: ALL, client: ALL, driver: ALL, performance: ALL, profiler: ALL, server: ALL}, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20211218203254, moz:geckodriverVersion: 0.30.0, moz:headless: false, moz:processID: 66714, moz:profile: /var/folders/gf/wjxc6bv113b..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 20.5.0, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

setCapability is adding goog:loggingPrefs: {browser: ALL, client: ALL, driver: ALL, performance: ALL, profiler: ALL, server: ALL} and that is causing the issue. The next step for me is to fix that and I am working on it. Meanwhile, please try the example shared. Thank you!

@moossenm
Copy link
Author

@pujagani many thanks for dealing with this.

Just one question:

I see goog:loggingPrefs: ..., but should not it be called moz:loggingPrefs??

@pujagani
Copy link
Contributor

moz:loggingPrefs throws an error, I don't think that is the appropriate capability name. Will debug and figure out more regarding the same.

@pujagani
Copy link
Contributor

@moossenm Can you please share the logs displayed on your console when the snippet is shared in #10222 (comment) worked with 3.x?
Based on what I understand currently, the snippet I shared works only because the setCapability is commented and not because .merge is used. The merge has no effect unless the instance returned by it is used and in that case, the same issue happens with the goog:loggingPrefs. Even if I modify the code that does it and use that in my project, it does not work. It seems like all the logs are printed only due to "options.setLogLevel(FirefoxDriverLogLevel.TRACE);" as far as I understand.

package com.company;

import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;

import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;

import java.util.logging.Level;

public class FirefoxProfileNotWorking {
  public static void main(String args[]) throws InterruptedException {
    FirefoxOptions options = new FirefoxOptions();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.page", 1);
    profile.setPreference("browser.startup.homepage", "http://google.com");
    options.setLogLevel(FirefoxDriverLogLevel.TRACE);
    LoggingPreferences logs = new LoggingPreferences();
    Level level = Level.ALL;
    logs.enable(LogType.DRIVER, level);
    logs.enable(LogType.CLIENT, level);
    logs.enable(LogType.BROWSER, level);
    logs.enable(LogType.SERVER, level);
    logs.enable(LogType.PERFORMANCE, level);
    logs.enable(LogType.PROFILER, level);

    options.setProfile(profile);
   // options.setCapability(LOGGING_PREFS, logs);

// do not work
   options = options.merge(new ImmutableCapabilities(CapabilityType.LOGGING_PREFS, logs));

    FirefoxDriver driver = new FirefoxDriver(options);

    System.out.println(driver.getCapabilities());
    Thread.sleep(5000);
    driver.get("http://www.yahoo.com");
    Thread.sleep(5000);
    driver.quit();
  }
}

Can you please share the logs that you expect to see? This will help me debug better. Thank you!

@pujagani
Copy link
Contributor

Also, the reason I ask is, I think the loggingPreferences API was never supported by GeckoDriver.
Please refer to the links below for details on the same:

https://bugzilla.mozilla.org/show_bug.cgi?id=1453962

mozilla/geckodriver#284 (comment)

mozilla/geckodriver#1682

mozilla/geckodriver#284 (comment)

However, you can use BiDi APIs offered by Selenium to get console logs.

@diemol diemol closed this as completed in c8da7c2 May 30, 2022
@diemol
Copy link
Member

diemol commented May 30, 2022

I added extra checks on some helper classes that were adding erroneously the goog:loggingPrefs part. This should not take any effect on Firefox anymore.

elgatov pushed a commit to elgatov/selenium that referenced this issue Jun 27, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants