How to test android app web service calls with robotium? - android

I have developed an android app on which i want to run the robotium test cases. The first problem i have is, In my app i am using so many web service calls to interact with the server, Whenever the app hits the server i am displaying a progress dialog, Now i want to make wait the robotium until the app get response from the server but i can make wait for some time using waitForDialogToClose(), Actually i want to make it wait exactly till it get some response or error from the server. How to do it..??
And the Second problem is i am doing some uploading data(eg. file or image) to server and i am displaying progress bar for it, In this case i want to make wait robotium until my progress bar reaches it max value. Please help..
Regards,
Ram.

Robotium is a black box testing framework : you test an app from the UI layer and it can even run without any knowledge of the code of the app under test.
For this reason, from robotium you can't plug a listener in your model or rest client and wait till the response comes into your app. So, you have two options :
relaying on the UI as you do, waiting for a given state to appear in the UI, as you suggested with a dialog, or the content of a list, whatever.
wait for some time before continuing the test, a time at which you are pretty sure data will be there. But this is more risky and will fail more often.
Some unit tests would be nice to test your rest client (or equivalent), then if you could mock it and run your ui tests disconnected it would be nicer. But all this require a large amount of design work, worth it but complex for a small app and a beginner in java. Maybe you would be better testing only your UI and keeping in mind that your tests are not perfect.

Related

Is there way to make sure some task finish before user put the app on sleep or terminate the app in Xamarin Forms on Android and iOS?

I am trying to make the UX as smooth as possible by not letting user to wait for the delay for each of the HTTP request finish with server.
I want to stack-up all these tasks and run them in background while user stay in the app, finish them before the app completely goes the sleep mode or terminate the app.
I looked up Android do have Job Scheduler, but it seems platform specified and not available in Xamarin Forms and iOS.
The only solution I am currently thinking is to save each http request task into some json and execute them when user start up the app.
I am not so familiar with Android/iOS development, I am not sure if there is any limitation doing in such way.
Is there any way to do so with some library or service natively?

Android: Not Able to display Offerwall NativeX W3i

I am working on a game - it requires to implement offer-Wall.
The problem is from within the game I am not able to display the offer-Wall.
My game at the time of loading the splash makes some connections (login, creating sessions etc) with own game server. Once this is done im not able to display the offer-wall.
If I Comment the in-game server connections the offer-wall works good.
And the offe-rwall being used is NativeX (W3i earlier)
But I could display the same offer-wall correctly from another test App.
Seems like Once the game is connected to the game server, no other connections are alowed Or they are put on hold. Any help with this please.
Thanks in Advance.
The NativeX MonetizationSDK requires initialization on the UI Thread.
Make sure that after you are making the network calls to your server you get back on the UI Thread before initializing and calling the SDK.

Measure application response time/wait for next activity ready in Android?

I am developing an automated test suite to get the timing information for some Android applications (whose source code I do not have access to).
I haven't decided whether to use MonkeyRunner or Robotium yet. My main concern is after I perform an action on the UI (say typed an URL), how to determine when Android has fulfilled my request, all of the next activity's components are ready for use and I am ready to get the result and take the next action (say the page I requested is fully loaded, or email is fully opened).
For web-browser this is simple, I can just use onProgressChaged() or onPageFinished(). But I am looking for a more general way which works for all applications. I think Instrumentation.waitForIdleSync() or Instrumentation.waitForIdle() might be my best bet here.
However, as far as the documentation I read about MonkeyRunner and Robotium, none of them seem to integrate with waitForIdle well. In Robotium I could send some input and then get the output, but there doesn't seem to be a simple way for me to know when the output is ready, and maybe invoke a callback at that point. MonkeyRunner is similar in this aspect, too.
So I wonder is there a simple way for me to know what time my request has been fulfilled (as perceived by the user) without re-implementing Robotium functionality all by my own?
Thanks a lot.
This can be very tricky and entirely dependent on what exactly you asked monkeyrunner to do.
For example, if you have a monkeyrunner script, and issued a command to launch calculator app, you can have a python subprocess monitoring adb logcat -b events output to determine whether calculator app has been launched or not. If you are asking to press a button in the calculator, you can have a sleep of 1 or 2 seconds.
But there is no direct way to determine whether android has processed your event or not. Simply because, every operation differs and takes its own time.
You can put asserts in robotium and then use system.nanoseconds() before and after like a timer.
This might be a easy way to get timing information

Mobile app responsive until client establish connection with server

Is there a known / common pattern of how a mobile application should behave from the point it is launched (more the case of fast launch from suspended mode) until the point a connection with the server is establish and ready?
I'll try to explain, when the app comes from suspended mode, the UI is quickly shown, but for the connection it usually takes a bit more time to re-connect with the server.
Even more, a lot of time the app needs to re-login with the server so it will take some more time.
My question is, how responsive should the app be at that time?
Of course blocking the all UI is a bad idea, but should I for example block the buttons that trigger some network activity until the login phase is finished?
I have the EXACT same issue with my App. A secure app that has to ping a server for login credentials after a programmer defined time-out or the user choosing to exit. I've found it to be better, from my very limited experience, to show a simple progress dialog that informs the user the App is connecting to the server for secure logon. My UI isn't blocked completely. The progress bar spins because the login process is always in an AsyncTask(Asynchronous Task). I hope this applies to you in some ways. I choose to make the dialog completely Modal so all other buttons beneath it aren't active. I also inflate my dialog to completely fill the screen to stop anyone who might have just picked up another person's phone from seeing sensitive data on the screen.
You should do the server connection thing on other thread or use GCD.
In that way the main thread will be responsive and it will act accordingly on establishing connection with server.

How to manage Android- to external device communication via web API?

I'm building a program which interfaces with a device which runs its own internal web server. I communicate with the device via a web API.
Basically what happens is that a GUI is presented to the user, where the user can make certain modifications to the device. These changes are communicated to the device, and results are returned through XML. The device needs to converse with the program in the background more or less continually (say every 15s or so) to update certain values to the user.
My structure that I'm envisioning is something like this:
UI - Main - Networking - XML Parser.
I'm looking for advice on how to manage these. I understand the UI thread should be separate to provide a smooth experience to users. I also understand that the networking should be at least an asynchronous task. I'm not so sure about how to handle their interaction, and make sure things are happening smoothly and effectively.
My idea is that Main will handle passing data around, telling the networker to send specific messages or changes, passing the returned XML to the parser, and then passing the parsed values to UI for handling.
I'm curious though for advice beyond that.
Have a look at creating a service that is created with your Activity. Without knowing the details of your plan, a Service looks like the optimal solution to perform all the heavy work.
UPDATE:
You could have the calls to web API run in a Service and, when needed, update the UI through an interface. You would have to instruct the Service to run on its own thread, so thread safety is an issue, but less trouble in the long run than using an AsyncTask.
Have a thought about using Google C2DM.
In your case,
Pros -> Less battery use, coordinated network traffic, Don't have to run a continues service and doesn't have the potential of being killed when the device runs out of resources.
Cons -> You have to post the results manually back to your internal server, and server should know which request the device is replying to. Communication is disconnected and may not be real-time. Requires a google account on the device and Google market.

Categories

Resources