https://github.com/Valve/fingerprintjs2を使用して、匿名のサイト訪問者の一意の ID を作成しています。
問題は、同時に複数のユーザー セッションをシミュレートしたいので、そのようにテストを実行することです。
nosetests --processes=8 --process-timeout=120
また、2 つのノードを使用したより現実的なテスト アプローチのためにセレン グリッドを使用しています。
@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 インスタンスを一意にする方法はありますか?