1

I need to execute integration testing using Python code and Selenium HUB driver. I'm planning to use remote driver (I'm using Selenium HUB docker image on https://github.com/SeleniumHQ/docker-selenium).

I am unable to figure out how to create a persistent profile in the Selenium HUB image and recall from remote webdriver. I guess I need to first create the profile on Selenium HUB, than recall in the python code: chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('user-data-dir=##remotepath')

browser = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',desired_capabilities = chrome_options.to_capabilities())

browser.get('http://www.google.it')
session_id = browser.session_id

How can I create the "user data dir" profile on docker selenium hub image?

Thx

UPDATE

I run "chrome:\version" and I was able to identify the profile enter image description here

I was able to specify it in the 'user-data-dir' param but, after committing on docker, when re-launching the image, the path change. Is it there any way to make it persistent?

UPDATE 2

I've created a folder "/etc/opt/chrome/profile/maya"

I've created a test_policy.json file:

{
  "UserDataDir": "/etc/opt/chrome/profile/maya"
}

placed in this directory:

/etc/opt/chrome/policies/managed

When I try to execute the "chrome://policy/" I see this:

enter image description here

Indicating something is wrong: enter image description here

user3925023
  • 667
  • 6
  • 25

1 Answers1

1

You can add custom path to chrome using chrome://policy and later add that policy files to docker images.

  1. Try the policy setup manually to assert if this approach works for you. While trying make sure you created valid policy file. Detailed steps are here.

  2. Available policy list

  3. Adding Steps in docker file.

    3.1. Creating folder as mentioned in step-1

enter image description here

3.2. Copying the policy file tested in step-1

enter image description here

  1. Build the docker image and use it.

PS: This approach works for me as I did some customization in chrome. Let me know in case you need more information.

Akshay barahate
  • 649
  • 8
  • 23
  • If I want to continue use the Selenium docker image downloaded from Docker hub, can you pls confirm I can simply 1-create directory on /etc/opt - 2-upload "policies.json" under /etc/opt/chrome/policies/managed/ 3-execute a docker commit - do y think will it works? Do you have an example of a working policies.json only for UserDataDir? – user3925023 Aug 06 '19 at 15:42
  • As you will build your own Docker-selenium image. You have to push this customized image to docker hub and then you can pull and change will be there. do not expect this changes to be present in open source docker+selenium image present on docker hub – Akshay barahate Aug 06 '19 at 15:53
  • Docker commit can be work around in your case. I answered w.r.t to CI/CD practice. Keeping changes in docker file, building,pushing to repo, pulling and using it. For policies.json file . Please refer the link in step1. it is just a json file with policies you want.. – Akshay barahate Aug 07 '19 at 07:07
  • Looks like with chrome 76 there are some changes in policies. UserDataDir is missing in the policy list for chrome 76. Will check on this – Akshay barahate Aug 07 '19 at 15:27