Search code examples
pythonseleniumfingerprintingfingerprintjs2

Fingerprinting issue with parallel selenium tests


I'm using https://github.com/Valve/fingerprintjs2 to create unique ids for anonymous site visitors.

Problem is i want to simulate multiple users sessions at the same time, so i'm run tests that way

nosetests --processes=8 --process-timeout=120

Also i'm using selenium grid for more realistic testing approach with two nodes - one with multiple firefox instances and another with chrome ones.

 @classmethod
 def setUpClass(cls):
    cls.sessions_ids = set([])

 def setUp(self):
    self.driver = webdriver.Remote(
        command_executor='http://localhost:4444/wd/hub',
        desired_capabilities={
            "browserName": "firefox", #chrome
            "platform": "ANY",
        }
    )
    self.driver.set_page_load_timeout(30)

 def test_anon_session(self):
    self.driver.get("http://localhost:8000/")
    wait = WebDriverWait(self.driver, 10)
    wait.until(
        lambda driver: self.driver.execute_script(
            "return jQuery.active == 0"
        )
    )
    sessionId = # getting sessionId (fingerprint2 js result)
    self.sessions_ids.add(sessionId)

 def test_anon_session_other_page(self):
    self.driver.get("http://localhost:8000/delivery")
    ...

@classmethod
def tearDownClass(cls):
    # 2 is a tests_count
    assert len(cls.sessions_ids) == 2, "Non unique sessions %r" % cls.sessions_ids

Problem is - even webdriver is opening new browser each test - it returning same fingerprint

Non unique sessions firefox set([u'c0509e372ee0906cb0120edd5b349620'])

Even if i change user-agent string

def test_delivery_page_different_user_agent(self):
    profile = FirefoxProfile()
    profile.set_preference("general.useragent.override", "CatchBot/2.0; +http://www.catchbot.com")
    driver = Remote(
        command_executor='http://localhost:4444/wd/hub',
        desired_capabilities={
            "browserName": "chrome",
            "platform": "ANY",
        },
        browser_profile=profile,
    )
    driver.set_page_load_timeout(30)
    driver.get("http://localhost:8000/delivery")
    ...

Fingerprint only differs for different browsers, but not test cases or tests.

Is there are a way to make webdriver instance be unique in terms of browser fingerprinting?


Solution

  • As far as I know browser fingerprint technologies created in order to distinguish between browsers even if client cleared cookies and restarted session. So what you described here is expected.

    I would suggest you play around with DesiredCapabilities, set some random resolution each time you start browser e.g:

    driver.manage().window().setSize(new Dimension(1024, 768)) 
    

    or Firefox Profile:

    DesiredCapabilities dc=DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile();
    dc.setCapability(FirefoxDriver.PROFILE, profile);
    Webdriver driver =  new FirefoxDriver(dc);