/uitest-specflow-example

A cross-platform example of using SpecFlow with UITest

Primary LanguageC#

UITest SpecFlow example

This project demonstrates how to use SpecFlow with Xamarin.UITest and is based on the the page object pattern example.

Running these tests on your Mac

  1. Add "Straight8's SpecFlow Integration" extension to Visual Studio for Mac
    • Go to the "Visual Studio" menu and click "Extensions..."
    • Search for "SpecFlow" and install
    • You might also want the "FileNesting" extension to help keep everything tidy
    • Restart Visual Studio
  2. Clone this repo
  3. Build
  4. Run*

*If you want to run this on a physical iOS device, you will need to clone and build the app from source in order to get an IPA file that is compatible with your device.

SpecFlow Implementation

  1. Create a new SpecFlow NUnit Library Project (under Other -> Miscellaneous in the new project dialogue).

  2. Remove all the NuGet packages and reinstall SpecFlow.NUnit version 1.1.1, SpecFlow version 2.1.0, and NUnit version 2.6.4.

    Note: the version numbers are very important. Until Test Cloud supports NUnit 3, your tests will not run unless you use these exact versions.

  3. Manually add the following files to your project (making sure to change the namespaces to match your own):

  4. Use the SpecFlow file templates to add a new feature file.

    • This will add two files to your project: MyTest.Feature and MyTests.feature.cs.
    • The first file is where you will write your scenarios for this feature and the second file is an autogenerated backing file that you cannot edit directly.
    • You will want to add another empty class file to your project and name it MyTestsFeature.cs (the same name as the partial class in MyTests.feature.cs)
    • Replace the class definition in this file with:
      [TestFixture(Platform.Android)]
      [TestFixture(Platform.iOS)]
      public partial class MyTestsFeature : BaseTestFixture
      {
          public MyTestsFeature(Platform platform)
              : base(platform)
          {
          }
      }
      This makes sure that your app gets set up properly before each test and lets NUnit find all your tests to run.
  5. Add a step definition file for each page in your app. Each step will call the corresponding method in the corresponding page object.

  6. Follow the page object pattern to build pages that interact with your app.

Contributors