Showing posts with label Calabash-ios. Show all posts
Showing posts with label Calabash-ios. Show all posts

Monday, July 15, 2013

Calabash-ios on Windows

In the last post I discussed about setting up the Mac environment for running Calabash-ios tests from Xamarin studio. In Mac, we can run the calabash-tests on simulator easily by using the Fast Track steps if using Xcode or by using these steps if using Xamarin studio. To run on a device in mac we need to identify the device ip address  and use it in the terminal like this

DEVICE_ENDPOINT=http://192.168.1.146:37265 NO_LAUNCH=1 calabash-ios console

NO_LAUNCH=1 disables the simulator launch. Now if you launch the app in the device and run queries in the terminal it would work.

Running tests on Windows machine

On Windows machine we can run tests only on device and not on simulator(couldnt find a simulator for ios on windows yet).  You can setup Calabash framework on windows using gem install as specified in the calabash ios github wiki page.

Since we cannot build the Xamarin ios project completely on windows without a mac host, we assume that we have a .ipa file built from Mac setup which has the Calabash-framework force loaded. Copy the .ipa file built from Mac to Windows machine where you want to run tests. Connect the device to your windows machine and then open the .ipa file using itunes. It will list the app(say MyApp) under Apps category in itunes and then you can drag and copy it to the device(your device would be listed in the side pane and when you drag the app it will show the connected device and you can drop on the device name and it would install in device). Then you should be able to launch the app in the device and it would also have started the calabash-server. 
And , if you are following the cucumber.yml file(as mentioned in field-service-example), you can modify the ios profile like this,

ios: DEVICE_ENDPOINT=http://[ipofdevice]:37265 NO_LAUNCH=1 DEVICE=[udid] CALABASH_FULL_CONSOLE_OUTPUT=TRUE NO_STOP=1 OS=ios6 PLATFORM=ios -r features/support -r features/ios/support -r features/ios/helpers -r features/step_definitions -r features/ios/pages

and then in command prompt you can run something like(for login feature) cucumber -p ios features/login.feature .

NOTE: I haven't yet figured out how to use the bundle id and have the tests automatically start the app in device yet and if i do so, I will either update this post or enter a new blog to keep track of it.

Happy Testing :)

Saturday, July 13, 2013

Calabash-ios on Xamarin Studio

Calabash-ios is a popular testing framework. In one of my previous posts, I discussed how to setup Calabash-android on windows. Calabash-ios setup on mac is lot simpler to setup if you are using Xcode as out of the box the fast track calabash-ios setup Option is provided which configures the xcode for you. But if you happen to 
use Xamarin studio on Mac, then you have to do manual setup, but its easy to configure. 
Assuming you have successfully setup the Calabash-cucumber gem in your mac machine,
the following are the steps for Xamarin ios project.

1. Download the Calabash-framework in the project directory(i.e the path where your .csproj
file is present). In the Terminal, go to the project directory path and type calabash-ios download.
This would download the Calabash-framework directory which you would use in step 2.

. NOTE: I happen to download from their framework downloads link (calabash.framework-0.9.126.zip) 
and it didnt work correctly(as of July 13 2013).  Copy the downloaded folder to the project 
directory(i.e the path where your .csproj file is present)

2. In the Xamarin studio, on the IOS project of your app(say Myapp.ios.csproj), you have to 
configure the option to force load the calabash-framework. The reason that we have to do
this for calabash-ios is because the calabash server runs as part of the app itself(rather than
in android the instrumentation server will run on a seperate app). And its better you
configure this in Debug configuration so that release builds does not have this.


In the Additional mtouch arguments, configure
-gcc_flags "-framework CFNetwork -framework CoreGraphics -force_load $(ProjectDir)/calabash.framework/calabash -lstdc++"

3. Now when you run the app on the Iphone simulator, the test server would be started and you can confirm this from the following entry in the output window

2013-07-13 14:21:39.100 FieldServiceiOS[13911:23803] Bonjour Service Published: domain(local.) type(_http._tcp.) name(Calabash Server)

Optionally you can confirm that the server is working by running any query(say query("button") in the calabash-ios console from the Terminal. You would be able to see an output like this

My-MacBook-Pro:Myapp.iOS Me$ calabash-ios console
Running irb...
irb(main):001:0> query("button")
[
    [0] {
              "class" => "UIButton",
               "rect" => {
            "center_x" => 158,
                   "y" => 376,
               "width" => 150,
                   "x" => 83,
            "center_y" => 401.5,
              "height" => 51
        },
              "frame" => {
                 "y" => 358,
             "width" => 150,
                 "x" => 125,
            "height" => 51
        },
             "UIType" => "UIControl",
        "description" => "<UIButton: 0x163cce70; frame = (125 358; 150 51); opaque = NO; autoresize = LM+RM+BM; layer = <CALayer: 0x163cb7d0>>"
    }
]
irb(main):003:0>