Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TickSpec AppInitializer.fs
namespace FsharpMvvmCross.UITests
open System
open System.IO
open Xamarin.UITest
open Xamarin.UITest.Queries
open NUnit.Framework
open TickSpec
open System.Reflection
open System.Runtime.ExceptionServices
module AppInitializer =
let mutable app: IApp = null
let droidProjectName = "Droid"
let apkName = "com.codingwithsam.FsharpMvvmCross.apk"
let apkPath = sprintf "../../../%s/bin/Debug/%s" droidProjectName apkName
let iOSProjectName = "iOS"
let ipaName = ""
let ipaPath = sprintf "../../../%s/bin/iPhoneSimulator/Debug/%s" iOSProjectName ipaName
let startApp (platform: Platform) =
if platform = Platform.Android then
.StartApp () :> IApp
// xcrun instruments -s devices
.StartApp () :> _
/// Class containing all BDD tests in current assembly as NUnit unit tests
type FeatureFixture () =
/// Test method for all BDD tests in current assembly as NUnit unit tests
member __.Bdd (scenario:Scenario) =
if scenario.Tags |> Seq.exists ((=) "ignore") then
raise (new IgnoreException("Ignored: " + scenario.ToString()))
let platform =
match scenario.Tags |> Seq.contains "android", scenario.Tags |> Seq.contains "ios" with
| true, true -> failwith "Can't run both ios and android. Check your spelling for the tags"
| false, false-> failwith "Must run with platform either ios or android. Add one of: @android, @ios, @android_ios"
| true, false -> Platform.Android
| false, true -> Platform.iOS <- AppInitializer.startApp platform
| ex ->
eprintf "Failed: %s\n%s" ex.Message ex.StackTrace
sprintf "Failed: %s\n%s" ex.Message ex.StackTrace |> Console.WriteLine
raise ex
/// All test scenarios from feature files in current assembly
static member Scenarios =
let enhanceScenarioName parameters scenarioName =
let replaceParameterInScenarioName (scenarioName:string) parameter =
scenarioName.Replace("<" + fst parameter + ">", snd parameter)
|> Seq.fold replaceParameterInScenarioName scenarioName
let splitTags (tags: string[]) =
|> (fun x -> x.Split("_"))
|> Array.concat
|> (fun x -> x.Replace("_", "").Trim().ToLower())
let isPlatform (name:string) tags (scenario:Scenario) feature =
if tags |> Seq.contains (name.ToLower()) then
let scenario =
{scenario with
Name = scenario.Name |> sprintf "%s: %s" name
Tags = tags |> Array.filter (fun x -> x = (name.ToLower())) }
(new TestCaseData(scenario))
.SetName(enhanceScenarioName scenario.Parameters scenario.Name)
.SetProperty("Feature", feature.Name.Substring(9))
.SetCategory(name) |> Some
else None
let createTestCaseData (feature:Feature) (scenario:Scenario) =
let tags = splitTags scenario.Tags
[isPlatform "Android"; isPlatform "iOS"]
|> List.choose (fun f -> f tags scenario feature)
|> Seq.foldBack (fun (tag:string) tests ->
tests |> (fun data -> data.SetProperty("Tag", tag))) scenario.Tags
let createFeatureData (feature:Feature) =
|> (createTestCaseData feature)
|> Seq.concat
let assembly = Assembly.GetExecutingAssembly()
let definitions = new StepDefinitions(assembly.GetTypes())
|> Seq.filter (fun (n:string) -> n.EndsWith(".feature") )
|> Seq.collect (fun n ->
definitions.GenerateFeature(n, assembly.GetManifestResourceStream(n))
|> createFeatureData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.