Thursday, 12 April 2012

iOS - Integrating KIF Tests with Jenkins CI


Below is the script I use in Jenkins to kick off my automated GUI tests, which are performed using KIF which was developed by Square. KIF serves as an excellent start for running and automating GUI testing. I had to make a small change to KIF to support entering text into text fields which weren't empty; KIF didn't seem to handle this so I made a fix in a fork, located at my KIF.


One of the problems I had initially was that whilst the build would be marked as successful or a failure correctly, there was no feedback on which of the GUI tests failed. My script below solves this problem by outputting the feedback from KIF if and only if the GUI tests fail; if they are successful there is no need to see them in my opinion.


Your script would need to be adapted to contain the correct details for your project/workspace/scheme/target of course, but hopefully this will serve as a good guide.


Waxsim is the required bridging application needed to support integration between KIF and Jenkins. Waxsim has been installed on the server, running under /Applications/waxsim - if you have it installed elsewhere then update the reference accordingly.


#!/bin/sh
#kill simulator if running
killall -s "iPhone Simulator" &> /dev/null
if [ $? -eq 0 ]; then
    killall -KILL -m "iPhone Simulator"
fi


echo "About to build GUI tests scheme"


xcodebuild -scheme "GUITests" -workspace "xxx.xcworkspace" -configuration Debug -sdk "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/" build CONFIGURATION_BUILD_DIR="/var/hudson/workspace/$JOB_NAME/build" 


echo "About to run waxsim - a long delay here might suggest something is obstructing the view of the simulator on build slave"


/Applications/waxsim "/var/hudson/workspace/$JOB_NAME/build/GUITests.app" > /tmp/KIF-$$.out 2>&1


# WaxSim hides the return value from the app, so to determine success we search for a "no failures" line


echo "Testing finished"


# count the number of times "TESTING FINISHED: 0 failures" is found - 0 means that there was a failure
success=`exec grep -c "TESTING FINISHED: 0 failures" /tmp/KIF-$$.out`


# if there was a failure, show what waxsim was hiding and crucially return with a non-zero exit code
if [ "$success" = '0' ]
then 
    cat /tmp/KIF-$$.out
    echo "==========================================="
    echo "GUI Tests failed"
    echo "==========================================="
    exit 1
else
    echo "==========================================="
    echo "GUI Tests passed"
    echo "==========================================="
fi

Tuesday, 10 April 2012

Script to Kill iPhone Simulator if Running

Instructions to end the iPhone Simulator process if it is running.

As part of a CI setup, it is typical to have multiple iOS build jobs running on an individual build slave. As you can only have a single instance of the iPhone Simulator, you might find some of your jobs fail because another job has started the simulator, and you can't get access to it.

What seems like a sensible approach here, is to kill the simulator if it is already running, meaning your build job is guaranteed to start from a known state. If you attempt to close the simulator when it isn't running, however, you will end up with an error, along the lines of "No matching processes belonging to you were found". That's why you need to check if the process is running first, before attempting to close it.

The following script checks if the simulator is running, and if it is, ends the process. You can do this at the start of each build job.


#!/bin/sh
#kill simulator if running
killall -s "iPhone Simulator" &> /dev/null
if [ $? -eq 0 ]; then
    killall -m -KILL "iPhone Simulator"
fi




And in case you were wondering; this works for the iPad simulator too. The process is the same so the script above works unedited.


If you have any problems getting this going, drop me a comment below.

Thursday, 9 February 2012

Rotating BlackBerry Playbook Simulator

I'll keep this one short and snappy.

If you want to change from the default 'landscape' mode, click and hold the mouse from the bottom right hand edge of the simulator (just anywhere in the black section will do) and drag towards the centre of the screen, and release.

Saturday, 7 January 2012

Could Not Reconnect All Network Drives in Windows 7

I often see the notification balloon popping up from system tray to tell me that my network drives could not reconnect. I typically see this after I've first turned on my computer or after I've booted from Hibernation.



When I open Computer, I can see my network drives, but they are shown with a red cross indicating that there is indeed a problem with the connection to them. Applications which rely on data from these network drives cannot obtain their data, and fail in their own ways. The particularly annoying aspect of this is that there absolutely no problem with the network connection to these drives. Simply double clicking on the drives will open them up and restore the connection. All applications will function correctly thereafter... until the next time I boot up the machine.

Below is a workaround you can use to ensure your remote drives are available for use when you turn on your PC. For my environment, I'm running Windows 7 64-bit and have a Synology DS411J which is a NAS drive. But really, this should work for connecting any remote network drive.

Tuesday, 13 December 2011

Android - ProgressDialog without Dimming Screen

By default, when Android's ProgressDialog is shown, the rest of the screen is dimmed automatically. This is pretty useful in most cases, but sometimes you want to keep the content in the background clear and visible too.

This is possible albeit not overly obvious. It turns out that when ProgressDialog is constructed, it has a flag set specifying that behind the dialog should be dimmed. As passing in 0 to the constructor of the dialog as the chosen style doesn't work, you actually have to create the object, and then remove the offending flag manually.

An example follows, where this is an Activity:

Monday, 12 December 2011

Android - Show Soft Keyboard When Activity Starts

This morning I needed to have a soft keyboard (AKA, the on-screen keyboard) showing when an activity launched. Why? Well it was login screen for my app, and the input text field would have focus by default so there was no need for the user to tap on the field prior to the keyboard appearing.

I came across code-based solutions which didn't work for me unfortunately.

The solution was thankfully available using a manifest-based approach.


Tuesday, 6 December 2011

Android - Get body of HTTP Response as String


Making HTTP requests in Android often results in the same type of boiler plate code being produced. One in particular that annoys me is having to get the response body as in InputStream and using BufferedReader and the likes.


Bundled along with Android is the org.apache.http libraries, which provide classes for easy interaction for common HTTP-related activities.


The following snippet shows how to perform an HTTP GET on a URI, and turn the response body into a string. In my case, I take the string and turn into a JSON object, but you might parse as XML or whatever.


DefaultHttpClient http = new DefaultHttpClient();
HttpGet httpMethod = new HttpGet();
httpMethod.setURI(new URI(SERVER_URI_GOES_HERE));
HttpResponse response = http.execute(httpMethod);
int responseCode = response.getStatusLine().getStatusCode();
switch(responseCode)
{
    case 200:
        HttpEntity entity = response.getEntity();
if(entity != null)
{
String responseBody = EntityUtils.toString(entity);
                 
        }
        break;
}