Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

python 3.x - webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?

As the documentation states, you can call webdriver.FirefoxProfile() with the optional argument of profile_directory to point to the directory of a specific profile you want the browser to use. I noticed it was taking a long time to run this command, so when I looked into the code, it looked like it was copying the specified profile Problem is, it takes an extremely long time for the profile to copy (something like >30 minutes, didn't have the patience to wait for it to finish.)

I'm using a hybrid of userscripts and selenium to do some automation for me, so to setup a new profile every single time I want to test out my code would be burdensome.

Is the only way to change this behaviour to edit the firefox_profile.py itself (if so, what would be the best way to go about it?)?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per the current implementation of GeckoDriver with Firefox using the FirefoxProfile() works as follows :

  • If case of initiating a Browsing Session through a new Firefox Profile as follows :

    from selenium import webdriver
    
    myprofile = webdriver.FirefoxProfile()
    driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:UtilityBrowserDriversgeckodriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()
    
  • A new rust_mozprofile gets created on the run as follows :

    1521446301607   mozrunner::runner   INFO    Running command: "C:\Program Files\Mozilla Firefox\firefox.exe" "-marionette" "-profile" "C:\Users\ATECHM~1\AppData\Local\Temp\rust_mozprofile.xFayqKkZrOB8"
    
  • Of-coarse on a successful closure (i.e. successful invocation of driver.quit()) the temporary rust_mozprofile.xFayqKkZrOB8 gets deleted/destroyed completely.

  • Again in case of initiating a Browsing Session through an existing Firefox Profile() as follows :

    from selenium import webdriver
    
    myprofile = webdriver.FirefoxProfile(r'C:UsersAtechM_03AppDataRoamingMozillaFirefoxProfilesmoskcpdq.SeleniumTest')
    driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:UtilityBrowserDriversgeckodriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()
    
  • Similarly a new rust_mozprofile gets created on the run as follows :

    1521447102321   mozrunner::runner   INFO    Running command: "C:\Program Files\Mozilla Firefox\firefox.exe" "-marionette" "-profile" "C:\Users\ATECHM~1\AppData\Local\Temp\rust_mozprofile.2oSwrQwQoby9"
    
  • Similarly in this case as well on a successful closure (i.e. successful invocation of driver.quit()) the temporary rust_mozprofile.2oSwrQwQoby9 gets deleted/destroyed completely.

  • So the timespan you are observing is the time needed for a FirefoxProfile() to scoop out a new rust_mozprofile.

Perhaps as per your question timespan for profile to copy (something like >30 minutes) is a pure overhead. So it won't be possible to use a Firefox Profile without making a copy of rust_mozprofile.


Solution

  • Upgrade Selenium Client to current levels Version 3.11.0.
  • Upgrade GeckoDriver to current GeckoDriver v0.20.0 level.
  • Upgrade Firefox version to Firefox Quantum v59.0.1 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Firefox base version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Firefox Quantum.
  • Execute your @Test.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...