CalculatorTests.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using NUnit.Framework;
  5. using Xamarin.UITest;
  6. using Xamarin.UITest.Queries;
  7. namespace Calculator.UITests
  8. {
  9. [TestFixture]
  10. public class CalculatorTests
  11. {
  12. static readonly Func<AppQuery, AppQuery> TwoButton = c => c.Marked("Digit2");
  13. static readonly Func<AppQuery, AppQuery> PlusButton = c => c.Marked("Operator+");
  14. static readonly Func<AppQuery, AppQuery> EqualsButton = c => c.Marked("OperatorEquals");
  15. private IApp _app;
  16. [SetUp]
  17. public void SetUp()
  18. {
  19. switch (TestEnvironment.Platform)
  20. {
  21. case TestPlatform.Local:
  22. var appFile =
  23. new DirectoryInfo(Path.Combine("..", "..", "testapps"))
  24. .GetFileSystemInfos()
  25. .OrderByDescending(file => file.LastWriteTimeUtc)
  26. .First(file => file.Name.EndsWith(".app") || file.Name.EndsWith(".apk"));
  27. _app = appFile.Name.EndsWith(".app")
  28. ? ConfigureApp.iOS.AppBundle(appFile.FullName).StartApp() as IApp
  29. : ConfigureApp.Android.ApkFile(appFile.FullName).StartApp();
  30. break;
  31. case TestPlatform.TestCloudiOS:
  32. _app = ConfigureApp.iOS.StartApp();
  33. break;
  34. case TestPlatform.TestCloudAndroid:
  35. _app = ConfigureApp.Android.StartApp();
  36. break;
  37. }
  38. }
  39. [Test]
  40. public void TheTwoPlusTwoIsFourTest()
  41. {
  42. _app.WaitForElement(c => c.Marked("OperatorEquals"));
  43. _app.Tap(TwoButton);
  44. _app.Tap(PlusButton);
  45. _app.Tap(TwoButton);
  46. _app.Tap(EqualsButton);
  47. _app.Screenshot("When I get the result value");
  48. AppResult[] results = _app.WaitForElement(c => c.Marked("DisplayValue").Text("4"));
  49. Assert.IsTrue(results.Any());
  50. }
  51. }
  52. }