【问题标题】:Google analytics automation testing谷歌分析自动化测试
【发布时间】:2017-07-22 01:56:40
【问题描述】:

问题是,我们有一个网站可以根据用户的操作触发多个事件,我们想使用自动化脚本模拟这些场景,还需要了解是否在幕后引发了 Google Analytics 事件。

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

【问题讨论】:

    标签: google-analytics automation google-analytics-api google-analytics-sdk


    【解决方案1】:

    安装Chrome Extension Source Viewer。转到analytics debugger extension in the store 并使用扩展源查看器下载扩展的 zip 文件。打开 background.js 并编辑debug = false(当前为第 4 行)为

    debug = true
    

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

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

    test.py
    env/
        bin/
            ga_tracker.crx
    

    这是 python selenium 测试,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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多