在本地模拟远程网站以进行测试 [英] Simulating a remote website locally for testing

查看:807
本文介绍了在本地模拟远程网站以进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个浏览器扩展程序。扩展程序适用于我们无法控制的外部网站。

I am developing a browser extension. The extension works on external websites we have no control over.

我希望能够测试扩展程序。我面临的一个主要问题是在本地显示网站按原样。

I would like to be able to test the extension. One of the major problems I'm facing is displaying a website 'as-is' locally.

是否可以在本地按原样显示网站?

Is it possible to display a website 'as-is' locally?

我希望能够在本地提供完全的网站进行测试。这意味着我想模拟完全相同的HTTP数据,包括iframe广告等。

I want to be able to serve the website exactly as-is locally for testing. This means I want to simulate the exact same HTTP data, including iframe ads, etc.


  • 有一种简单的方法吗?

更多信息:

我是像我的系统尽可能密切关注远程网站。我想运行命令 fetch 例如,这将允许我在我的浏览器中访问该网站(没有上网)并得到完全相同的东西,否则我会(包括非来自单个域名的信息,谷歌广告等)。

I'd like my system to act as closely to the remote website as possible. I'd like to run command fetch for example which would allow me to go to the site in my browser (without the internet on) and get the exact same thing I would otherwise (including information that is not from a single domain, google ads, etc).

如果有帮助,我不介意使用虚拟机。

I don't mind using a virtual machine if this helps.

我认为这在测试中非常有用。特别是当我有一个错误时,我需要在具有许多随机因素(广告显示等)的网站中可靠地重现。

I figured this was quite a useful thing in testing. Especially when I have a bug I need to reliably reproduce in sites that have many random factors (what ads show, etc).

推荐答案

正如已经提到的,缓存代理应该为你做到这一点(BTW,这是最简单的解决方案)。有很多不同的实现,所以你只需要花一些时间选择一个合适的(根据我的经验,鱿鱼是一个很好的解决方案)。无论如何,我想强调另外两个有趣的选择:

As was already mentioned, caching proxies should do the trick for you (BTW, this is the simplest solution). There are quite a lot of different implementations, so you just need to spend some time selecting a proper one (according to my experience squid is a good solution). Anyway, I would like to highlight two other interesting options:

选项1: Betamax

Option 1: Betamax


Betamax是用于模拟外部HTTP资源(如Web服务和测试中的REST API。该项目的灵感来自Ruby的VCR库。 Betamax旨在通过拦截您的应用程序启动的HTTP连接并重放以前记录的响应来解决这些问题。

Betamax is a tool for mocking external HTTP resources such as web services and REST APIs in your tests. The project was inspired by the VCR library for Ruby. Betamax aims to solve these problems by intercepting HTTP connections initiated by your application and replaying previously recorded responses.

Betamax有两种版本。第一个是HTTP和HTTPS代理,它可以拦截以任何尊重Java的http.proxyHost和http.proxyPort系统属性的方式进行的流量。第二个是Apache HttpClient的简单包装。

Betamax comes in two flavors. The first is an HTTP and HTTPS proxy that can intercept traffic made in any way that respects Java’s http.proxyHost and http.proxyPort system properties. The second is a simple wrapper for Apache HttpClient.

BTW,Betamax为你提供了一个非常有趣的功能:

BTW, Betamax has a very interesting feature for you:


Betamax是一个测试工具,而不是符合规范的HTTP代理。它会忽略通常用于阻止代理缓存或存储HTTP流量的任何和所有标头。

Betamax is a testing tool and not a spec-compliant HTTP proxy. It ignores any and all headers that would normally be used to prevent a proxy caching or storing HTTP traffic.

选项2: Wireshark 和重播代理

Option 2: Wireshark and replay proxy

使用 Wireshark 并重播它。我想说实现所需的重放工具并不困难,但您可以使用名为 replayproxy <的可用解决方案/ a>

Grab all traffic you are interested in using Wireshark and replay it. This I would say it is not that hard to implement required replaying tool, but you can use available solution called replayproxy


Replayproxy从.pcap文件解析HTTP流
在端口3128上打开TCP套接字并作为HTTP代理进行侦听使用提取的HTTP响应作为缓存,同时拒绝所有未知URL请求。

Replayproxy parses HTTP streams from .pcap files opens a TCP socket on port 3128 and listens as a HTTP proxy using the extracted HTTP responses as a cache while refusing all requests for unknown URLs.

这种方法为您提供完全控制和位 - 到位精确模拟。

Such approach provide you with the full control and bit-to-bit precise simulation.

这篇关于在本地模拟远程网站以进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆