【问题标题】:No log entries found for BrowserMobProxy With Robot Framework没有找到带有机器人框架的 BrowserMobProxy 的日志条目
【发布时间】:2017-03-23 02:24:01
【问题描述】:

我已经在机器人框架中编写了这个脚本。

Set Selenium Implicit Wait    10
## Init BrowserMob Proxy
${file}    Join Path    ${EXECDIR}    browsermob-proxy-2.1.4    bin    browsermob-proxy.bat
File Should Exist    ${file}
Start Local Server    ${file}

# Create dedicated proxy on BrowserMob Proxy
${BrowserMob_Proxy}=    Create Proxy

# Configure Webdriver to use BrowserMob Proxy
${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method    ${options}    add_argument      --proxy\=${BrowserMob_Proxy}
Create WebDriver    Chrome    chrome_options=${options}

New Har    google
Go To    ${PAGE_URL}
Title Should Be    Google
${har}=     Get Har As Json
Create File     ${EXECDIR}${/}file.har     ${har}

Close All Browsers
Stop Local Server

但是当我尝试通过 HAR 分析器进行验证时,它返回错误说在文件中找不到日志条目。

处理 HAR 文件时发现的错误: 在文件中找不到日志条目。

har 的结果:

{"log": {"comment": "", "entries": [], "version": "1.2", "pages": [{"pageTimings": {"comment": ""}, "comment": "", "title": "google", "id": "google", "startedDateTime": "2017-03-23T10:26:27.317+08:00"}], "creator": {"comment": "", "version": "2.1.4", "name": "BrowserMob Proxy"}}}

【问题讨论】:

  • 浏览器部分能用吗? IE。谷歌页面是否成功加载?谷歌只能通过代理访问还是直接连接也可以?
  • 浏览器成功,可以访问google了。两者都可以访问谷歌。
  • 如果我尝试使用 --proxy-server 那么我无法访问该页面。

标签: python python-2.7 robotframework browsermob-proxy


【解决方案1】:

从描述中可以清楚地看出,您尝试访问的 URL 可以通过代理访问,也可以不通过代理访问。代理的目的是将服务器作为记录/操作浏览器与其目的地之间流量的一种手段。

以下代码示例已经过测试并确认可以工作。这是stackoverflow post 中的一个变体。我在您的示例中看到的唯一区别是 --proxy 应该是 --proxy-server

Open Chrome Using Create WebDriver Keyword
        ${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
        Call Method    ${options}    add_argument    --proxy-server\=localhost:8080
        Create WebDriver    Chrome    chrome_options=${options}
        Go To    https://stackoverflow.com

在聊天中进行了一些讨论后,我们得出除了上述之外,还可以使用以下构造设置代理端口:

&{port}    Create Dictionary    port=8084
${BrowserMob_Proxy}=    Create Proxy    ${port}

知道代理与 BrowserMob 运行在同一主机上,并且代理端口已知,现在可以指定 ChromeOptions:

Call Method    ${options}    add_argument    --proxy-server\=localhost:8084

然后可以将其与 HAR 生成代码相结合。

【讨论】:

  • 感谢您的回答。我已经尝试过使用该选项,但它在 chrome 上返回错误。 This site can’t be reached The webpage at https://stackoverflow.com/ might be temporarily down or it may have moved permanently to a new web address. ERR_TUNNEL_CONNECTION_FAILED
  • 您是否验证了直接在浏览器中配置的代理是否正常工作?
  • 到达这个错误This site can’t be reached The webpage at http://localhost:8080/ might be temporarily down or it may have moved permanently to a new web address. ERR_NO_SUPPORTED_PROXIES
  • localhost地址是我自己代理的地址。在您的示例中,这应该是 ${BrowserMob_Proxy}。您只需将参数名称更改为--proxy-server,并强调您自己的示例中缺少的-server 部分。
  • 看来端口配置不正确。
猜你喜欢
  • 2018-12-04
  • 2016-02-02
  • 1970-01-01
  • 2020-07-10
  • 2015-09-28
  • 2014-09-29
  • 2018-02-03
  • 2019-02-18
  • 2018-05-01
相关资源
最近更新 更多