0

问题是,我们有一个网站根据用户的行为触发多个事件,我们希望使用自动化脚本来模拟这些情况,并且需要了解Google Analytics事件是否已在现场引发。谷歌分析自动化测试

只是好奇,市场上是否有任何工具可以帮助我们实现自动化。谢谢!

回答

0

安装Chrome Extension Source Viewer。转至analytics debugger extension in the store并使用Extension Source Viewer下载该扩展的zip文件。打开background.js和编辑debug = false(4号线目前),以

debug = true 

的Chrome浏览器去扩展窗口,打开开发模式(在该窗口中复选框)。使用Pack Extension按钮并选择刚刚编辑的文件夹以创建名为ga_tracker.crx的文件。

将该文件放入您的项目中。例如,我将它复制到我的virtualenv中。

test.py 
env/ 
    bin/ 
     ga_tracker.crx 

这是python selenium test,test.py.如果将其放在其他位置,请编辑add_extension的路径。

import re 
from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 

class FindTest(): 

    def test(self): 

     self.chrome_options = webdriver.ChromeOptions() 
     self.chrome_options.add_extension('env/bin/ga_tracker.crx') 
     self.driver = webdriver.Chrome(chrome_options=self.chrome_options) 
     self.driver.get('https://www.localsbarguide.com') 
     for entry in self.driver.get_log('browser'): 
      print(entry) 
      for entry in context.driver.get_log('browser'): 
       if 'https://www.google-analytics.com/analytics_debug.js' in entry['message']: 
        my_regex = re.escape('title') + r".*." + re.escape('The Premiere Drink Special & Happy Hour resource | Locals Bar Guide San Francisco') 
        if re.search(my_regex, entry, re.IGNORECASE): 
         print('Found GA event with expected title.') 

     self.driver.quit() 

runtest = FindTest() 
runtest.test()