Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help on Hoverfly GUI localhost:8888 #369

Closed
MohitIndian opened this issue Feb 3, 2017 · 42 comments
Closed

Help on Hoverfly GUI localhost:8888 #369

MohitIndian opened this issue Feb 3, 2017 · 42 comments

Comments

@MohitIndian
Copy link

MohitIndian commented Feb 3, 2017

Please help me what to do next. As I am beginner to this topic.
I just logged in the GUI. But not getting any tab to explore more on it.
Thanks in advance !!!

image

@benjih
Copy link
Contributor

benjih commented Feb 3, 2017

Hey @MohitIndian,

Currently the GUI provided with Hoverfly is fairly minimal in functionality.

Hoverfly is mainly controlled using the companion application, hoverctl. This application is a command line utility to easily interacting with Hoverfly's Rest API.

@MohitIndian
Copy link
Author

Thanks benjih for your quick reply ...

I have gone through the Hoverfly documentation.
Can you tell me what to do next ?
Thanks in advance !!!
image

@tjcunliffe
Copy link
Contributor

Hi @MohitIndian - the best place to start after reading through the docs is the tutorials section.

The reference section contains information on the API, the simulation schema and CLI commands.

@MohitIndian
Copy link
Author

What is the prerequisite to start with Hoverfly ?
Any of the programming language or anything else ...

@benjih
Copy link
Contributor

benjih commented Feb 4, 2017

There are no prerequisites as long as you have the correct Hoverfly binary for your platform.

@MohitIndian
Copy link
Author

How can I run curl and export commands in windows

e.g.

curl http://hoverfly.io --proxy http://proxy-ip:port
export HTTP_PROXY="http://proxy-address:port"

Thanks in advance :)

@MohitIndian
Copy link
Author

Hi All,

Can I expect the reply on the above query ?

Thanks

@tjcunliffe
Copy link
Contributor

cURL binaries are available for most platforms, including Windows, from the cURL website. You will need to install cURL on your machine to execute many of the commands in the tutorials.

export FOO="BAR" is the method for setting environment variables from a MacOS or Linux shell. On Windows, environment variables can be set either via the GUI, or I believe by using setx FOO "BAR" from the command prompt. You will need to set the HTTP_PROXY environment variable on your machine to point to the Hoverfly proxy (http://localhost:8500 by default).

The tutorials in the documentation are written for Linux/MacOS environments, as the majority of Hoverfly users are currently on Linux/MacOS.

I will set aside some time soon to create some tutorials for Windows users.

@MohitIndian
Copy link
Author

Thanks tjcunliffe !!

I think cygwin will also help for curl command ?

Thanks

@benjih
Copy link
Contributor

benjih commented Feb 4, 2017

Yes, you can easily get curl through cygwin.

@MohitIndian
Copy link
Author

Is it necessary to have http://time.jsontest.com in the command ?
curl --proxy http://localhost:8500 http://time.jsontest.com

Can we put any other website for the same ?

Thanks,
Mohitkumar

@tjcunliffe
Copy link
Contributor

You don't have to use http://time.jsontest.com - that's just the example we use in the documentation examples.

@MohitIndian
Copy link
Author

MohitIndian commented Feb 6, 2017

Thanks tjcunliffe !!
Can you suggest me any other website instead of this ?

@MohitIndian
Copy link
Author

I was just implementing this example... Adding templates to a simulation

As per documentation, I have executed these commands...

hoverctl start
hoverctl mode capture
curl --proxy http://localhost:8500 http://echo.jsontest.com/foo/baz/bar/spam
hoverctl export simulation.json
hoverctl stop

Now, when I opened the json file, It looks like this ..

{
"data": {
"pairs": [],
"globalActions": {
"delays": [
{
"urlPattern": "echo\.jsontest\.com\/a\/b",
"httpMethod": "",
"delay": 2000
},
{
"urlPattern": "echo\.jsontest\.com\/b\/c",
"httpMethod": "GET",
"delay": 2000
},
{
"urlPattern": "echo\.jsontest\.com\/c\/d",
"httpMethod": "GET",
"delay": 3000
}
]
}
},
"meta": {
"schemaVersion": "v1",
"hoverflyVersion": "v0.10.0",
"timeExported": "2017-02-08T14:23:56+05:30"
}
}

but in the document, it is given that

image

In short, I havn't got the parameter "requestType" in my exported json file.
Please help me on it.

Thanks a lot ....

@tjcunliffe
Copy link
Contributor

The JSON you posted doesn't contain any request response pairs... it looks like you haven't captured anything. It looks like you have just followed the Applying different delays based on URI tutorial before following the Adding templates to a simulation tutorial.

I've just checked the steps in the tutorials and after completing them I have a simulation.json file with the delays and request response pairs: simulation.json.

If you follow the "Applying different delays based on URI" tutorial, then run the following commands:

hoverctl start
hoverctl mode capture
curl --proxy http://localhost:8500 http://echo.jsontest.com/foo/baz/bar/spam
hoverctl export my_simulation.json
hoverctl stop
cat my_simulation.json

you should see responses and requests in the JSON. Each request should have a requestType property.

@MohitIndian
Copy link
Author

MohitIndian commented Feb 9, 2017

Thanks tjcunliffe for Reply. I will check.

@MohitIndian
Copy link
Author

While implementing Using middleware to simulate network latency from documentation, I have executed the following commands:

hoverctl start
hoverctl mode capture
curl --proxy http://localhost:8500 http://time.jsontest.com
hoverctl mode simulate
hoverctl middleware --binary python --script middleware.py
curl --proxy http://localhost:8500 http://time.jsontest.com
hoverctl stop

but while going through this steps,
hoverctl middleware --binary python --script middleware.py.

I got an error msg="Hoverfly could not execute this

Please find the attached snapshot for the same.

image

@MohitIndian
Copy link
Author

Hi All,

Can I expect the reply on it ?

Thanks and Regards,
Mohitkumar

@tjcunliffe
Copy link
Contributor

This error indicates that Hoverfly cannot execute the binary specified. Please check that you have Python installed - you can do this by running python -V.

@mogronalol
Copy link
Contributor

It should probably output standard error from the binary as well.

@MohitIndian
Copy link
Author

Thanks a lot tjcunliffe and mogronalol !!!

@MohitIndian
Copy link
Author

Please help me as I am not clear what I am getting after this comand !!!

hoverctl middleware --binary python --script middleware.py

image

@MohitIndian
Copy link
Author

Any reply on this .....

Thanks and Regards,
Mohitkumar

@jxlampdx
Copy link

Hi There, I am having a similar error when attempted the hoverctl middleware --binary python --script middleware.py

I checked python is installed with the python -V command.

This is the actual command:

hoverctl middleware --binary /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python --script middleware.py

I am new to Mac, is the problem it is not resolving the relative path of /System/....?

image

Thanks!
Jenny

@benjih
Copy link
Contributor

benjih commented Feb 23, 2017

Hey @MohitIndian,

That message is just telling you that middleware has been successfully set. The output is just confirming which the middleware it will be executing.

@benjih
Copy link
Contributor

benjih commented Feb 23, 2017

Hey @jxlampdx,

I have tried to reproduce what you have provided and it has worked fine for me.

Could you please provide the middleware.py file that you are using? Could you also include the output of hoverctl logs after this error occurs.

@jxlampdx
Copy link

Hi @benjih, Thank for your reply. I got it working, the problem was the PATH. It's now producing the result in the middleware.py file! Awesome! :)

image

@JohnFDavenport
Copy link
Contributor

Good news, @jxlampdx I'll make a note to check our documentation. If you think it could have been more helpful, do say.

@jxlampdx
Copy link

Hi @benjih & Hoverfly fans,

Now that we got the command line middleware synthesis working, we like to be able to invoke this from our android/java and Swift mobile apps.

I see that there is Hoverfly Java binding. can you provide a quick sample of what the invocation looks like in the a Java app? Essentially what we like to do is:

In the Java app:

  1. Start hoverfly in simulation mode,
  2. Then curl -- proxy local host with real URL
  3. put hoverfly in simulate mode
  4. execute the hoverctl middleware script
  5. remain in simulation mode.
    5 have the mobile app calling the simulation and getting back what is in the middleware script

Thank in advance!
Jenny

@tommysitu
Copy link
Member

tommysitu commented Feb 24, 2017

Hi @jxlampdx,

hoverfly-java lets you capture and simulate API for testing in JAVA. The easiest way to get started is to add the following JUnit rule to your test:

@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.inCaptureOrSimulationMode("simulation.json");

The first run of your test will capture all HTTP requests to external services, and store the simulation.json into test resources folder. The next time you run it will use the recorded simulation.

More information can be found in the docs:
https://hoverfly-java.readthedocs.io/en/latest/

Supporting middleware in hoverfly-java is still in the pipeline. Feel free to give your comments or suggestions on this issue: SpectoLabs/hoverfly-java#7

@tommysitu
Copy link
Member

@jxlampdx I've provided a work-around to your problem, please check out my comment for this issue: SpectoLabs/hoverfly-java#7

@jxlampdx
Copy link

@tommysitu we will try the workaround and provide feedback. Thanks!

@MohitIndian
Copy link
Author

Hi @benjih and Team,

After executing this command,
hoverctl middleware --binary python --script middleware.py

I am getting this in console.

console

And I am getting this in middleware.log file
log

Kindly guide me know what to do next as I am trying to achieve this.

Hoverfly is to capture HTTP(S) traffic to create API simulations which can be used in testing.
Hoverfly stores captured traffic as simulations.

Thanks in advance.
Mohitkumar

@jxlampdx
Copy link

jxlampdx commented Mar 3, 2017

Hoverfly Team,
For an existing service for an api, we can capture/simulate/synthesized. Let say now we like to add some new services and test against that. Is there a way to accomplish this with Hoverfly without first adding these new services to the API.

The issue we are trying to solve is to enable the front end/client team to make progress and simulate new services without having to wait for backend team to make the modification.

thoughts?
Jenny

@JohnFDavenport
Copy link
Contributor

I am not entirely sure what you need but supposing your new API is similar to an existing one you could export the simulation and edit that and reimport it.

If you are thinking of something more extensive than that take a look at https://github.com/SpectoLabs/swagger-to-hoverfly

@jxlampdx
Copy link

jxlampdx commented Mar 6, 2017

@JohnFDavenport, I thought about modifying an existing simulation. Let me take a look at the swagger-to-hoverfly solution. Thanks John!

@jxlampdx
Copy link

jxlampdx commented Mar 6, 2017

Hoverfly Team,

If we like to edit a previously recorded simulation and essential create a new call. Are these the correct steps in doing so?

  1. modified a simulation file and save as new.
  2. start up Hoverfly -webserver in simulation mode.
  3. import the new simulation (successful).
  4. inject the middleware file to handle the response.
  5. when we issue the curl command to verify : curl -I http://localhost:8500/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking, got bad gateway error. I also attached our new simulation file. The assumption is it is matching by "path": "/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking",

Thanks!

simulation-createBooking4Room.json.zip

APC02SVFZ4GTFM:hoverfly_bundle_OSX_amd64 jlam1$ hoverctl middleware --binary python --script middleware-bookRoom.py
INFO[0000] Hoverfly middleware configuration has been set to
INFO[0000] Binary: python
INFO[0000] Script: #!/usr/bin/env python

import sys
import json
import logging
import random

logging.basicConfig(filename='middleware.log', level=logging.DEBUG)
logging.debug('Middleware "modify_request" called')

def main():
payload = sys.stdin.readlines()[0]

logging.debug(payload)

payload_dict = json.loads(payload)
payload_dict['response']['status'] = random.choice([200, 201])

if "response" in payload_dict and "body" in payload_dict["response"]:
	payload_dict["response"]["body"] = "{'Message': '{success: \"true\",  EventID: \"123456\"}'}\n"

print(json.dumps(payload_dict))

if name == "main":
main()
APC02SVFZ4GTFM:hoverfly_bundle_OSX_amd64 jlam1$ curl -I http://localhost:8500/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking
HTTP/1.1 502 Bad Gateway
Content-Type: text/plain
Req: /rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking
Resp:
Date: Mon, 06 Mar 2017 18:29:50 GMT
Content-Length: 119

APC02SVFZ4GTFM:hoverfly_bundle_OSX_amd64 jlam1$ hoverctl import simulation-createBooking4Room.json
INFO[0000] Successfully imported simulation from simulation-createBooking4Room.json
APC02SVFZ4GTFM:hoverfly_bundle_OSX_amd64 jlam1$ curl -I http://localhost:8500/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking
HTTP/1.1 502 Bad Gateway
Content-Type: text/plain
Req: /rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking
Resp:
Date: Mon, 06 Mar 2017 18:31:05 GMT
Content-Length: 119

APC02SVFZ4GTFM:hoverfly_bundle_OSX_amd64 jlam1$ curl -I http://localhost:8500/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking

@jxlampdx
Copy link

jxlampdx commented Mar 6, 2017

We got pass the 502 error and now getting a "there was an error when Matching". what should the requestType value be? currently it is "recording" and the error is "could not find recorded request, please record it first!"

We couldn't record as this is a new service and hoping to accomplish the call with just a modified simulation file. Is this doable with hoverfly?

@benjih
Copy link
Contributor

benjih commented Mar 7, 2017

Hey @jxlampdx,

Creating simulations that mock services yet to be created is definitely a use case we see Hoverfly supporting.

Having a look at your problem, I can see that your simulation is for a POST request with a JSON body attached. The matching problem you are seeing is because the curl request you are sending is a GET request without a body.

curl -X "POST" --data '{"Subject":"Architecture Meeting", "OrganizerEmail":"jlam@steelcase.com", "OrganizerUserUuid":"63", "Anonymous":"false"}' http://localhost:8500/rooms/a7155e79-842e-11e6-a1a5-000d3a321a2e/booking

You also mentioned the requestType. It is possible to define looser matching by setting the requestType to template and then removing unnecessary fields. This often helps keep the simulation leaner while also making it easier to match.

I have attached a modified version of your simulation, with the request being transformed into a loosely matching template. The reason for doing this was that your request recording had headers attached to it, meaning I would have had to configure my curl program to send the right headers (I'm using a slightly different version of curl so the request would never have matched as a recording).

simulation.json.zip

@jxlampdx
Copy link

jxlampdx commented Mar 7, 2017

@benjih Thanks! will give that a try. I also like the ability to wildcard match with the template approach.

@JohnFDavenport
Copy link
Contributor

All done then. Closing the issue as there are no further actions.

@SpectoLabs SpectoLabs locked and limited conversation to collaborators Mar 9, 2017
@JohnFDavenport
Copy link
Contributor

A reminder that questions should be posted here: https://groups.google.com/a/specto.io/forum/#!forum/hoverfly

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants