Search code examples
xamarincalabashxamarin.uitest

Using Calabash with something else than Ruby


Is it possible to use the Xamarin Calabash with a programming language something other than Ruby, for example C#?

I want to automate tests for mobile devices.


Solution

  • If you want Ghekin as a language to describe your tests, you can use Specflow on top of Xamarin.UITest.

    http://specflow.org/getting-started/

    You can see an example here: https://github.com/smstuebe/xamarin-testing-demo/tree/master/Todo.Tests.UI.Specflow

    A test would then look like this.

    Feature: Todo
        In order to remember what I have to do
        As a user
        I want to maintain tasks in a list
    
    Scenario: Add a task
        When I enter "Added Task" 
        And I press add
        Then the task "Added Task" should be added to the list
    

    The step definitions then use Xamarin.UITest

    [Binding]
    public sealed class TodoPageSteps
    {
        private TodoPage _page;
        private IApp _app;
    
        public TodoPageSteps()
        {
            _page = new TodoPage();
            _app = FeatureContext.Current.Get<IApp>("App");
        }
    
        [When(@"I enter ""(.*)""")]
        public void WhenIEnter(string task)
        {
            _app.Tap(_page.AddEntry);
            _app.EnterText(_page.AddEntry, task);
        }
    
        [When(@"I press add")]
        public void WhenIPressAdd()
        {
            _app.Tap(_page.AddButton);
        }
    
        [Then(@"the task ""(.*)"" should be added to the list")]
        public void ThenTheTaskShouldBeAddedToTheList(string task)
        {
            _app.WaitForElement(_page.LabelOfTask(task));
        }
    }