Combine E2E testing with HTTP web services testing - web-services

Can I catch HTTP request\response from the protractor, I want to create E2E tests with validation of the web services using JSON.

You can only capture request, response through a proxy. Selenium-webdriver doesn't support this feature since it is limited to only browser simulation. One of the most well known proxies for inspecting request, response is browsermob-proxy. You can either directly use its API or use the node client browsermob-node. Once You have a proxy running, you can set driver capabilities in your protractor config like below
capabilities: {
'proxy': {
'proxyType': 'manual',
'httpProxy': 'hostname.com:1234'
}
}

Related

Testing Applications for use of Web Services

1) Is it possible using burp suite/ ZAP or any other web testing tools to find out
if an application is making calls to web services?
2) As SOAP web services reply in XML is it also possible to view the responses of
the HTML request to distinguish between use of REST web services?
Thanks
Yes, this is normally possible.
You need to configure the application to use the interactive proxy (Burp, Zap, etc.) as its proxy. Most applications will use your system proxy settings.
Once the proxy is configured, you can see a full history of HTTP interactions (in Burp: Proxy > HTTP History). This includes requests and responses, which will clearly indicate a SOAP or REST service.

What are the advantage of using RequestsClient() over APIClient()?

I am writing unittest for Django-rest-framework API endpoints. In version 3.5, they have added RequestsClient(). Documentation says -
Rather than sending any HTTP requests to the network, this interface will coerce all outgoing requests into WSGI, and call into your application directly.
From my understanding, I think RequestsClient() is useful for the network request from different servers. Not sure if it has any advantage in the same server? Also Is there any advantage of using RequestsClient() over APIClient() ?
Is there any advantage of using RequestsClient() over APIClient()
This is a higher lever of test. RequestsClient will test against your stack from the WSGI layer which APIClient bypasses.
This also means that tests that uses authentication or CSRF will be looking more like what happens with real requests.
If you're not sure, use the standard APIClient.
RequestsClient is useful if either:
You intend to most be interacting with the API from another Python service and want your tests to work at the same level.
You want to write tests in a way that allows you to also run them against a live or staging environment.

SoapUI: Create mock service with pass-through behavior for selected methods

While developing a web application I have the following use case:
a 3rd party Web Service with quite a lot of methods is deployed on a test server A (with a single endpoint, e.g. http://3rdPartyServer/3rdPartySvc?WSDL)
a new method is about to be implemented in the near future, but I need to use it now
the rest of the methods are used throughout my code extensively
So I would like to do the following:
Create a mock service in SoapUI locally, based on the new WSDL which includes the new WS method (i.e. a superset of the WS methods currently on server A)
point my local application server to use the SoapUI mock service endpoint
mock only the response of the new WS method (create a dummy response for it in SoapUI)
let the other WS method calls to reach server A and return whatever it returns normally (i.e. use SoapUI as a proxy for these calls)
I've gone through the SoapUI documentation regarding service mocking and have used it numerous times, but could not find an option for such "pass-through" behavior.
When you read in your WSDL, the endpoint will point to your server.
Open your service, and select the service endpoint.
Add a second endpoint, to point to your mock. SoapUI has little bit of documentation showing this here. Only step "2. Getting Started" applies, not step 3!
In each of your tests, where you are using the mocked method, you will need to select the mock endpoint. Further discussion is here.

Junit Test to test Http Outbound endpoint in Mule Flow

I have a basic Mule ESB application with a basic flow like:
"Http Inbound endpoint (request-response mode) -> logger -> HTTP Outbound Endpoint (request-response mode) -> Java component"
Query: How do I write a junit test case to test the above flow. As can be seen, I have a HTTP Outbound Endpoint (request-response mode) which refers to some big application which does lots of processing and then returns a response. Do I mock this HTTP outbound endpoint?
I don't want to test only the HTTP Outbound Endpoint (request-response mode) individually. I want to junit test the flow as a whole.
Thanks in Advance.
Jai Shammi Raj Kulkarni
You can create a test flow with an HTTP Inbound Endpoint and a test:component for setting the payload, and add the flow file to your test configuration files. However, I prefer to use the Confluex Mock HTTP API to test applications with HTTP Outbound Endpoints. It sets up a mock HTTP server at localhost, where you can respond to different calls with specified data and response codes, so you can run all kinds of failure scenarios as well. Set up the mock server in a #Before annotated method in your FunctionalTestCase class and stop it in the #After method, so it will be available for the test methods.
Mule documentation gives some basic information on how to create functional test cases: http://www.mulesoft.org/documentation/display/current/Functional+Testing
public void httpEndpoint() throws IOException
{
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://localhost:8085/api/search");
HttpResponse response = client.execute(httpGet);
assertNotNull(response);
}
Have you checked Munit?
https://github.com/mulesoft/munit/wiki/First-Munit-test-with-Mule-code
https://github.com/mulesoft/munit/wiki
Also check this:
http://www.mulesoft.org/documentation/display/current/Introduction+to+Testing+Mule

Spring Web Services: Redirect Web Service Request

I have different Spring Web Services, which are included into the context by the
Endpoint Annotation, so there are no dependencies despite the Annotation (no interface etc.). Therefore, no "context" information is present.
Now I want to chain a web service request, ie. an Endpoint is called which itself should call a web service on the same server. I can use Spring's WebServiceTemplate, however, I need the current server url for this request.
Is there any way how this url can be injected during application startup into the Endpoints? Since the Endpoints do not extend some class, there is no way to get this information anywhere inside the Endpoints, also the request parameters do not have this information (these are simple JAXB-classes, which are marshalled on request).
I believe the best option is to send the URL as part of the request.
This also enables you to dynamically change the URL to a third server later.