While running UI Espesso tests I would like to also verify if the app is making correct http requests (e.g triggered by a button press). Currently using OkHttpClient client to make the requests.
Did you try something? I like to use Wiremock to mock http requests and check that the app have done the correct request. You must use the standalone version or you will get some issues with HttpClient.
For more information see http://wiremock.org/index.html
Related
I'm working on a multilayer Android app where I have to intercept HTTP requests, modify one of the headers, execute and return responses. I can't change a way of creating requests, but I can change the API base URL used for requests. The approach I chose was writing a proxy listening on a specific port and doing a man-in-the-middle job:
taking requests,
applying required changes to HTTP requests,
executing it and
returning response.
I applied SparkJava as an HTTP server and OkHttpClient as an HTTP client. It worked like a charm until I found it works only on Android 8 and newer. There is a problem with missing ThreadLocal<S> ThreadLocal.withInitial (Supplier<? extends S> supplier) in API prior to 26 that SparkJava's backend - Jetty, uses).
I guess I will try to look for other HTTP server framework working fine in older API and reimplement my proxy.
In the meantime, does this approach seem to be ok? Or maybe there is another way of proxying HTTP requests in Android app that would allow modifying headers having only an option of changing base API URL?
All ideas much appreciated.
PS. I know that in a typical app this kind of proxying would make a security issue, but this is not a concern in this case.
i'm trying to test Android app using Espresso FW and I stucked on the problem with doing async HTTP request.
How can i test the case that app (activity) is waiting for processing request and after the response is received is displayed next activity with result or error message?
I tried to find any solution how to do it in the Espresso with testing against the data from the test server, but without luck.
Many thanks for any advice, example or link.
I struggled with this for a few days. If your app is using retrofit to handle HTTP requests, you can add this one line:
.setExecutors(AsyncTask.THREAD_POOL_EXECUTOR, new MainThreadExecutor())
to your RestAdaptor.Builder. This moves all of the HTTP requests into the AsyncTasks pool which is then handled by espresso.
I found the original answer here: http://www.michaelevans.org/blog/2015/08/03/using-espresso-for-easy-ui-testing/
I think the problem is in app architecture.
You should use some Dependency Injection library to inject mock service with mock data in your application in test mode.
When you inject "test" implementation ( mocks) when you testing. U will avoid problems with not network availability or you can simulate network availability by your test implementation.
I am re-implementing an existing worklight system. We have already have a hybrid version. We have decided to re-implement the Client side in pure native. The native client seems work fine.
However, the server seems to be quite unstable - sometimes we don't get a server response after invoking an adapter, sometimes we do get. I have checked the DDMS/Android console. And a Error/Exception was found. Any comments would be appreciated!
com.worklight.common.Logger$SendLogsRequestListener(4274): Logger$SendLogsRequestListener.onFailure in Logger.java:1726 :: Failed to POST data from file /data/data/${APP_NAME}/files/analytics.log.0.send due to: HTTP response code: 500
On a successful adapter call or WLClient connection to the server, the client will attempt to automatically send logs to the server. It looks like something bad is happening on the autosend for adapters. A temporary workaround would be to disable this auto sending behavior by calling
WL.Logger.setAutoSendLogs(false)
But you can only use this call if you do not wish for logs to be sent automatically. If you do wish to have this working properly, I'd suggest opening a PMR so that it can be determined if this is an error in your application or an actual defect.
I have packaged a Sencha Touch 2 app with PhoneGap for Android. I can't get the ajax requests to work on my native application. When I handle the request through the browser on http://mydomain.com/mysenchaapp/android/assets/www/ it works fine, however, when I run my app through the emulator as a native app my request fails. I think it would be helpful if I could get fiddler to work on handling native apps' request as well, but I haven't been able to figure that out either. Any help is appreciated.
On a native application you can use cross-domain get requests without using JSONP. I got it to work. My problem accessing the servlet was another issue.
You can't use Ajax for Cross-Domain GET requests, you should use JSONP instead. Take a look at the documentation for Ext.data.JsonP.request(), You can however use Ajax to make a post if i'm not mistaken. This comes in handy when uploading something like a base64 string (which is too big for a GET request)
In the docs on server response extras, I find this:
When network problems prevent or interrupt a license check, the Android Market client notifies the application by returning a "RETRY" response code to the Policy's processServerResponse() method. In the case of system problems, such as when the application is unable to bind with Android Market's ILicensingService implementation, the LicenseChecker library itself calls the Policy processServerResonse() method with a "RETRY" response code.
Unfortunately, RETRY is not listed one of the listed response codes that the server returns, and when I look at the LVL source code, it appears that the Android Market client actually returns one of the server response codes and it is the LicenseValidator class in the library that decides when to turn that into a RETRY response status.
Furthermore, in the section on implementing a custom policy, there's this in the guidelines:
Note that the Android Market client automatically retries failed requests, so in most cases there is no need for your Policy to retry them.
I find this confusing. Does the client simply report one of the documented server response codes, or does it do more? If the device is in airplane mode, for instance, does a custom policy need to deal with RETRY or with ERROR_CONTACTING_SERVER? Should the policy (or application) deal with retries, or does the client do it automatically?