【问题标题】:Fingerprinting issue with parallel selenium tests并行硒测试的指纹问题
【发布时间】:2016-04-01 13:59:29
【问题描述】:

我正在使用 https://github.com/Valve/fingerprintjs2 为匿名网站访问者创建唯一 ID。

问题是我想同时模拟多个用户会话,所以我以这种方式运行测试

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

另外,我正在使用 selenium 网格进行更真实的测试方法,其中包含两个节点 - 一个具有多个 firefox 实例,另一个具有 chrome 实例。

 @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

问题是 - 甚至 webdriver 每次测试都打开新浏览器 - 它返回相同的指纹

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

即使我更改了用户代理字符串

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")
    ...

指纹仅因浏览器不同而不同,而测试用例或测试则不同。

有没有办法让 webdriver 实例在浏览器指纹方面是唯一的?

【问题讨论】:

    标签: python selenium fingerprinting fingerprintjs2


    【解决方案1】:

    据我所知,browser fingerprint 创建的技术是为了区分浏览器,即使客户端清除了cookies 并重新启动会话。所以你在这里描述的是预期的。

    我建议你玩DesiredCapabilities,每次启动浏览器时设置一些随机分辨率,例如:

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

    Firefox Profile:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      相关资源
      最近更新 更多