Firefox-headless test on Javascript Pages explodes the number of processes

(Isma399) #1


we monitor some webapps in Javascript.
Previously, we used Selenium + PhantomJS, but this is deprecated.
So now, we use Selenium + Firefox-headless + Geckodriver

It seems that Selenium doesn’t handle the end of firefox process and the number of processes keeps growing.
For instance, 10 hours after beginning monitoring one of this type of Service, the number of processes reachs 700!
ps aux | grep firefox counts about 600 firefox processes

Here’s the script where you can see line 44 that end of process is therefore called.

# coding: utf-8

import BeautifulSoup
import sys
import re
import time
from optparse import OptionParser
import os
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver

argv = (sys.argv[1:])
parser = OptionParser()
parser.add_option("-s", "--service",
                  help="The service to check.")
parser.add_option("-g", "--grep",
                  help="The string to get in the javascript checked.")
(options, args) = parser.parse_args()
if not options.service_to_check or not options.string_to_grep:
    quit(' -s <service to checked> -g <string to grep>')

url = options.service_to_check
searched_word = options.string_to_grep

# Set the MOZ_HEADLESS environment variable, Firefox will start in headless mode.
os.environ['MOZ_HEADLESS'] = '1'

# Select your Firefox binary.
binary = FirefoxBinary('/usr/bin/firefox', log_file='/dev/null')

# Start selenium with the configured binary.
driver = webdriver.Firefox(firefox_binary=binary, log_path='/dev/null')

time.sleep(1)  # Needed to load page

html = driver.page_source
soup = BeautifulSoup.BeautifulSoup(html)
if, soup.text):
    print 'Find "' + searched_word + '" in ' + url + " | javascript_is_up=1"
    print "Alert : not found " + searched_word + " in " + url + " | javascript_is_up=0"

Maybe it’s not the good place to post this question but maybe you also monitor javascript app.
Thanks for any help or workaround.


The only explanation I have is that “driver.quit()” doesn’t kill the Firefox process properly. Can you verify this with some logging?

(Isma399) #3

Yes, I’ll give a try.