Towards better software

Xamarin Calabash Help

  • Sept. 13, 2016

I recently test drove Calabash Cucumber tests on a Xamarin project.  I downloaded an open source Xamarin project and followed the help available on the Xamarin website, but no luck. The help on the Xamarin website is a good starting place - I recommend going through it carefully.

I found that the site didn't tell me how to configure my project to actually run Cucumber tests. I ended up downloading the example project to understand what I was missing. That turned out to be the Xamarin Test Cloud Agent package.

To add it, navigate to Project -> Add NuGet Packages... within Xamarin Studio and search for Test Cloud.  Add the Xamarin Test Cloud Agent to your project.

Add NuGet Package

Once that package is added you will need to initialize Calabash when your application runs.  That is done by added a few lines of code to the FinishedLaunching() function in AppDelegate.cs as follows:

//Override FinishedLaunching. This executes after the app has started.
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
	#if DEBUG

	//isAuthenticated can be used for an auto-login feature, you'll have to implement this
	//as you see fit or get rid of the if statement if you want.
        //We are already authenticated, so go to the main tab bar controller;
        var tabBarController = GetViewController(MainStoryboard, "MainTabBarController");
        SetRootViewController(tabBarController, false);
        //User needs to log in, so show the Login View Controlller
        var loginViewController = GetViewController(MainStoryboard, "LoginPageViewController") as LoginPageViewController;
        loginViewController.OnLoginSuccess += LoginViewController_OnLoginSuccess;
        SetRootViewController(loginViewController, false);
    return true;

From there you should be able to create and run tests by following the Xamarin Calabash examples.  I had trouble getting started on the tests and I found that examining the Calabash source code for the built in story phrases was very helpful.


Good luck!