Simulating a remote website locally for testing

后端 未结 4 1013
清酒与你
清酒与你 2021-02-06 02:37

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 pr

相关标签:
4条回答
  • 2021-02-06 02:45

    This service http://www.json-gen.com provides mock for html, json and xml via rest. By this way, you can test your frontend separately from backend.

    0 讨论(0)
  • 2021-02-06 02:47

    I don't know if there is an easy way, but there is a way.

    You can set up a local webserver, something like IIS, Apache, or minihttpd.

    Then you can grab the website contents using wget. (It has an option for mirroring). And many browsers have an option for "save whole web page" that will grab everything, like images.

    Ads will most likely come from remote sites, so you may have to manually edit those lines in the HTML to either not reference the actual ad-servers, or set up a mock ad yourself (like a banner image).

    Then you can navigate your browser to http://localhost to visit your local website, assuming port 80 which is the default.

    Hope this helps!

    0 讨论(0)
  • 2021-02-06 02:55

    I assume you want to serve a remote site that's not under your control. In that case you can use a proxy server and have that server cache every response aggressively. However, this has it's limits. First of all you will have to visit every site you intend to use through this proxy (with a browser for example), second you will not be able to emulate form processing.

    Alternatively you could use a spider to download all content of a certain website. Depending on the spider software, it may even be able to download JavaScript-built links. You then can use a webserver to serve that content.

    0 讨论(0)
  • 2021-02-06 02:59

    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:

    Option 1: Betamax

    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 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 has a very interesting feature for you:

    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.

    Option 2: Wireshark and replay proxy

    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 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.

    0 讨论(0)
提交回复
热议问题