docker - selenium/standalone-firefox-debug - how to start Firefox with a specified profile?

瀏覽次數:1,267 次
跳到第一則未讀訊息

gbajson

未讀,
2017年8月30日 下午1:26:402017/8/30
收件者:Selenium Users
Hi,
does anyone of you know how to execute selenium/standalone-firefox-debug docker container with a firefox profile from a specified directory?

I see that:
 - there is a possibility to pass a variable to /opt/selenium/selenium-server-standalone.jar through a variable ${SE_OPTS}, and
 - geckodriver-0.18 may use { moz:firefoxOptions:  "args": ["-profile", "/path/to/profile"] }


I added this option into /opt/selenium/config.json as follows, but it didn't help, firefox is still started with a profile from a temporary directory.
Details below:

{
  "capabilities": [
    {
      "version": "55.0",
      "browserName": "firefox",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver",
      "applicationName": "",
      "moz:firefoxOptions": {
         "args": ["-profile", "/home/seluser/firefox_profile"],
      }

  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 1,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "nodePolling": 5000,
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
}


seluser     26    12  1 17:20 ?        00:00:00 Xvfb :99 -screen 0 1200x900x24 -ac +extension RANDR -nolisten tcp -auth /tmp
seluser     33    12 12 17:20 ?        00:00:01 java -jar /opt/selenium/selenium-server-standalone.jar -sessionTimeout 86400
seluser     49     6  0 17:20 ?        00:00:00 fluxbox -display :99.0
seluser    132    33  0 17:20 ?        00:00:00 /opt/geckodriver-0.18.0 --port=12244
seluser    158   132 23 17:20 ?        00:00:02 /usr/bin/firefox -marionette -profile /tmp/rust_mozprofile.PicUpmYauNQ7


Best regards,
gbajson



Krishnan Mahadevan

未讀,
2017年8月30日 下午1:29:592017/8/30
收件者:seleniu...@googlegroups.com

Why do you want to start the node with a firefox profile?

With Selenium2 and onwards, the firefox profile is no longer an attribute of the test environment (the docker container in your case) but it’s an attribute of the test code.

 

So you should be passing in the firefox profile via the FirefoxOptions using a code snippet such as below (Please feel free to change it to use the URL of the Selenium server running in the docker container):

 

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.remote.RemoteWebDriver;

public class DynamicFirefoxProfile {
   
public static void main(String[] args) {
        RemoteWebDriver driver =
null;
        ProfilesIni profilesIni =
new ProfilesIni();
       
//Pass a new value via the JVM argument -Dprofile
        //For e.g., to load a profile named "selenium" use -Dprofile=selenium
       
String profileName = System.getProperty("profile", "IdontExist");
        FirefoxProfile profile = profilesIni.getProfile(profileName);
        FirefoxOptions options =
new FirefoxOptions();
       
if (profile != null) {
            options.setProfile(profile);
        }
       
try {
            driver =
new FirefoxDriver(options);
            driver.get(
"http://www.google.com");
        }
finally {
           
if (driver != null) {
                driver.quit();
            }
        }
    }
}

 

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4dc1ba3b-8866-4270-8b90-e821bd287386%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gbajson

未讀,
2017年9月1日 凌晨3:08:582017/9/1
收件者:Selenium Users
Thanks for your response.
You provided a good solution, but for some other problem.

I need to use docker container selenium/standalone-firefox-debug.
Documentation for this container is available there: https://github.com/SeleniumHQ/docker-selenium/tree/master/StandaloneFirefoxDebug

I bind a directory with my Firefox profile into docker container, as /home/seluser/firefox_profile.
I'd like to use this profile once docker container stops it's work.


So far I tried the following:

1. Extended /opt/firefox-55.0/browser/application.ini by line:

Profile=/home/seluser/firefox_profile
but I don't know how to pass argument "-app /opt/firefox-55.0/browser/application.ini" into application.


2. Extended /opt/selenium/config.json by moz:firefoxOptions:

$ cat config.json

{
  "capabilities": [
    {
      "version": "55.0",
      "browserName": "firefox",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver",
      "applicationName": "",
      "moz:firefoxOptions": {
         "args": ["-profile", "/home/seluser/firefox_profile"]
      }

  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 1,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "nodePolling": 5000,
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
}


3. I changed /usr/bin/firefox with the following script to enforce Firefox execution with argument "-profile /home/seluser/firefox_profile", but selenium crashes with the following exception:

#!/bin/bash
/opt/firefox-55.0/firefox -profile /home/seluser/firefox_profile $@




selenium.common.exceptions.WebDriverException: Message: connection refused
Build info: version: '3.5.0', revision: '8def36e068', time: '2017-08-10T23:00:22.093Z'
System info: host: 'd028f85a10e8', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-514.26.2.el7.x86_64', java.version: '1.8.0_131'
Driver info: driver.version: unknown
remote stacktrace: stack backtrace:
   0:           0x5787ed - backtrace::backtrace::trace::h59229d13f6a8837d
   1:           0x578942 - backtrace::capture::Backtrace::new::h23089c033eded8f0
   2:           0x4463cc - webdriver::error::WebDriverError::new::hd11f864b1fdf4510
   3:           0x450591 - geckodriver::marionette::MarionetteHandler::create_connection::h6f7058fccafe4367
   4:           0x425c32 - <webdriver::server::Dispatcher<T, U>>::run::h8f5348b8f5f7c053
   5:           0x40b22c - std::panicking::try::do_call::hb67c6fb6bcd96195
   6:           0x5dc20a - panic_unwind::__rust_maybe_catch_panic
                        at /checkout/src/libpanic_unwind/lib.rs:98
   7:           0x41b943 - <F as alloc::boxed::FnBox<A>>::call_box::h4100941edc372034
   8:           0x5d48a4 - alloc::boxed::{{impl}}::call_once<(),()>
                        at /checkout/src/liballoc/boxed.rs:650
                         - std::sys_common::thread::start_thread
                        at /checkout/src/libstd/sys_common/thread.rs:21
                         - std::sys::imp::thread::{{impl}}::new::thread_start
                        at /checkout/src/libstd/sys/unix/thread.rs:84
Stacktrace:
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance (Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0 (W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2 (W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24 (ProtocolHandshake.java:360)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance (Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel (ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel (AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential (FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst (ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:363)


Regards,
gbajson

⇜Krishnan Mahadevan⇝

未讀,
2017年9月1日 凌晨3:27:312017/9/1
收件者:Selenium Users
Irrespective of whether you use Docker or a regular grid environment that runs in a remote machine, I guess the philosophy is still the same. 

Firefox profiles are no longer an attribute of the execution environment. They are now an attribute of the test code.
I guess that is why WebDriver provides you with the mechanism of attaching a profile to a desired capability, serializing it over the wire and then sending them over to the node that is supposed to spin off the firefox browser, so that the browser can be spun off with the profile that matches in contents with your local profile.

That's my understanding.

If you resort to sending in the profile, then you don't need to mount your directory as a shared folder in your container.

If that still doesn't make sense, then I guess I am not completely understanding your usecase wherein you want to do this.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0c601112-6657-4809-a4fc-9d273a6961ed%40googlegroups.com.

gbajson

未讀,
2017年9月1日 凌晨4:05:492017/9/1
收件者:Selenium Users
Hi Krishan

finally I solved my problem and understood how to pass capabilities into geckodriver.

capabilities=DesiredCapabilities.FIREFOX                                                   
capabilities["moz:firefoxOptions"] = {"args": ["-profile", "/home/seluser/firefox_profile"]}
driver = webdriver.Remote(command_executor='http://' + ip + ':4444/wd/hub',desired_capabilities=capabilities)

Now firefox is started with the correct path:

seluser    156   120  2 07:58 ?        00:00:10 /usr/bin/firefox -marionette -profile /home/seluser/firefox_profile


Thanks for your help, advices and hints,

Best regards,
Grzegorz

Diego Fernando Molina

未讀,
2017年9月4日 凌晨4:04:162017/9/4
收件者:Selenium Users
The disadvantage of using a Firefox profile via capabilities is that it always get sent over to the hub for each test, and if the profile is big, this will slow down your tests. 

We also wrote an entry in the Docker-Selenium wiki to address this, https://github.com/SeleniumHQ/docker-selenium/wiki/How-to-use-a-Firefox-custom-profile 

At the end it is a matter of taste.

Cheers,

Diego

gbajson

未讀,
2017年10月19日 上午9:14:352017/10/19
收件者:Selenium Users
Hi Diego,
thanks for your response.

I created firefox profile and followed and executed selenium with -Dwebdriver.firefox.profile=seluser, but firefox starts with the new profile in /tmp.
I'd like to execute firefox with the profile in /home/seluser/.mozilla/firefox/firefox_profile.

Processes running in the docker container:
seluser     28    11  1 12:58 ?        00:00:01 java -Dwebdriver.firefox.profile=seluser -jar /opt/selenium/selenium-server-standalone.jar -log /tmp/selenium.log
seluser    134    28  0 12:58 ?        00:00:00 /opt/geckodriver-0.19.0 --port=13093
seluser    176   134  3 12:58 ?        00:00:05 /usr/bin/firefox -marionette -profile /tmp/rust_mozprofile.ERKuowd3r3rp


Below there is a content of my profile.ini:

seluser@ff935dd5df77:~/.mozilla/firefox$ cat /home/seluser/.mozilla/firefox/profile.ini
[General]
StartWithLastProfile=1

[Profile0]
Name=seluser
IsRelative=1
Path=firefox_profile


My profile exists in the following location:

seluser@ff935dd5df77:~/.mozilla/firefox$ ls -ld /home/seluser/.mozilla/firefox/firefox_profile/
drwxr-xr-x 15 seluser 1001 4096 Oct 19 12:52 firefox_profile/


Regards,
Grzegorz

Martynas Jusevičius

未讀,
2018年1月27日 晚上11:21:482018/1/27
收件者:Selenium Users
Hi,

I am having this exact problem. Has anyone found a solution?

Martynas Jusevičius

未讀,
2018年1月29日 下午4:24:012018/1/29
收件者:Selenium Users
Is it possible that your profile uses cert9.db/key4.db storage? I observed that it does not work, but cert8.db/key3.db does.


On Thursday, October 19, 2017 at 3:14:35 PM UTC+2, gbajson wrote:
回覆所有人
回覆作者
轉寄
0 則新訊息