Tests.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 MyWeather.UITests
  8. {
  9. [TestFixture (Platform.Android)]
  10. [TestFixture (Platform.iOS)]
  11. public class Tests
  12. {
  13. IApp app;
  14. Platform platform;
  15. public Tests (Platform platform)
  16. {
  17. this.platform = platform;
  18. }
  19. [SetUp]
  20. public void BeforeEachTest ()
  21. {
  22. app = AppInitializer.StartApp (platform);
  23. }
  24. [Test]
  25. public void A_AppLaunches ()
  26. {
  27. app.Screenshot ("First screen.");
  28. app.Repl ();
  29. }
  30. [Test]
  31. public void B_GetWeatherSuccess()
  32. {
  33. app.Screenshot ("First screen.");
  34. app.ClearText(x => x.Marked("EntryCity"));
  35. app.Screenshot ("Screen Cleared");
  36. app.EnterText(x => x.Marked("EntryCity"), "Cleveland,OH");
  37. app.Screenshot ("Enter Cleveland");
  38. app.Tap (x => x.Marked ("LabelUseCity"));//dismiss keyboard
  39. app.Tap(x => x.Marked("ButtonGetWeather"));
  40. app.Screenshot ("Click Get Weather");
  41. app.WaitForElement (x => x.Marked ("IsBusyIndicator"));
  42. app.Screenshot ("Is Loading");
  43. app.WaitForNoElement (x => x.Marked ("IsBusyIndicator"));
  44. app.Screenshot ("Done Loading");
  45. app.WaitForElement (x => x.Marked ("LabelBigTemp"));
  46. app.Screenshot ("Display Weather");
  47. var results = app.Query (x => x.Marked ("LabelTempBig"));
  48. int test = 0;
  49. var passed = int.TryParse (results [0].Text.Replace("°", ""), out test);
  50. Assert.IsTrue (passed, "Didn't Display Result");
  51. }
  52. [Test]
  53. public void C_EntryCityDisablesWhenSwitchedOff()
  54. {
  55. app.Screenshot ("First screen.");
  56. app.Tap(x => x.Marked("SwitchUseCity"));
  57. app.Screenshot ("Switch off use city");
  58. var results = app.Query(x => x.Marked("EntryCity"));
  59. Assert.IsFalse (results [0].Enabled, "Entry was not disabled when toggled off");
  60. }
  61. [Test]
  62. public void D_GetWeatherButtonDisabledNoCitySpecified()
  63. {
  64. app.Screenshot ("First screen.");
  65. app.ClearText(x => x.Marked("EntryCity"));
  66. app.Screenshot ("Screen Cleared");
  67. var results = app.Query(x => x.Marked("ButtonGetWeather"));
  68. Assert.IsFalse (results [0].Enabled, "Button was not disabled when city was cleared");
  69. }
  70. }
  71. }