Tests.cs 2.1 KB

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