gpt4 book ai didi

python - 并行 Selenium 测试的指纹问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:22 25 4
gpt4 key购买 nike

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

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

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

此外,我还使用 selenium grid 来实现具有两个节点的更真实的测试方法 - 一个具有多个 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

问题是 - 即使网络驱动程序每次测试都会打开新的浏览器 - 它返回相同的指纹

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 实例在浏览器指纹识别方面具有唯一性?

最佳答案

据我所知,浏览器指纹技术是为了区分浏览器而创建的,即使客户端清除了cookie并重新启动了 session 。所以你在这里描述的情况是预期的。

我建议您尝试使用DesiredCapability,每次启动浏览器时设置一些随机分辨率,例如:

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);

关于python - 并行 Selenium 测试的指纹问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com