Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. using NUnit.Framework;
  2. using System;
  3. using Xamarin.UITest;
  4. using Xamarin.UITest.Android;
  5. using Xamarin.UITest.Queries;
  6. using System.Threading;
  7.  
  8.  
  9.  
  10. namespace AutoSage
  11. {
  12. [TestFixture()]
  13. public class Test
  14. {
  15.  
  16. AndroidApp app;
  17.  
  18. [SetUp]
  19. public void SetUp()
  20. {
  21. app = ConfigureApp.Android
  22. .ApiKey("YOUR API KEY")
  23. .ApkFile(@"PATH TO APK")
  24. .StartApp();
  25. }
  26.  
  27.  
  28. [Test]
  29. public void A_Login()
  30. {
  31. Login();
  32. }
  33.  
  34. [Test]
  35. public void B_AddContact()
  36. {
  37. Login();
  38. AddContact();
  39. }
  40.  
  41. [Test]
  42. public void C_NewInvoice()
  43. {
  44. Login();
  45. AddContact();
  46. NewInvoice();
  47. }
  48.  
  49. public void Login()
  50. {
  51. //Wait for screen to load and take screenshot
  52. Thread.Sleep(9000);
  53. app.Screenshot("When I am logged into the app");
  54.  
  55. //Tap Login on main screen
  56. AppResult mainLogin = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.UILink'"))[1];
  57. app.TapCoordinates(mainLogin.Rect.CenterX, mainLogin.Rect.CenterY);
  58. Thread.Sleep(7000);
  59. app.Screenshot("And I clicked Login");
  60.  
  61. //Sign in with google
  62. while (app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.auth_additional'")).Length == 0)
  63. app.ScrollDown();
  64. AppResult googleLogin = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'.UILink'"))[1];
  65.  
  66. //Tap google sign in
  67. app.TapCoordinates(googleLogin.Rect.CenterX, googleLogin.Rect.CenterY);
  68. app.Screenshot("Then I click 'Sign in with google'");
  69.  
  70.  
  71. //Enter email
  72. AppResult emailEntry = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Email'"))[0];
  73. app.TapCoordinates(emailEntry.Rect.CenterX, emailEntry.Rect.CenterY);
  74. app.EnterText("test@gmail.com");
  75. app.Screenshot("Then I enter in my email address");
  76.  
  77. //Enter Password
  78. Thread.Sleep(1000);
  79.  
  80. while (app.IsItThere(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Passwd'")) == false)
  81. {
  82. app.ScrollDown();
  83. }
  84.  
  85. AppResult pwdEntry = app.Query(x => x.Id("NoResourceEntry-42").Raw("webView css:'#Passwd'"))[0];
  86. app.TapCoordinates(pwdEntry.Rect.CenterX, pwdEntry.Rect.CenterY);
  87. Thread.Sleep(1000);
  88. app.EnterText("test");
  89. Thread.Sleep(2000);
  90. app.Screenshot("Then I enter in my password");
  91.  
  92. //Tap Sign In
  93. while (app.IsItThere(x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'")) == false)
  94. {
  95. app.ScrollDown();
  96. }
  97.  
  98. app.ScrollDownEnough(x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'"));
  99. app.WaitForThenTap(
  100. x => x.Id("NoResourceEntry-42").Raw("webView css:'#signIn'"),
  101. "Then I press the Sign In button");
  102.  
  103. if (app.IsItThere(x => x.Text("Confirm")) == true)
  104. {
  105. app.WaitForElement(x => x.Text("Never"));
  106. app.Tap(x => x.Text("Never"));
  107. }
  108.  
  109. //Wait for pin screen & allow slower devices to catch up
  110. app.WaitForElement(x => x.Class("sage.sageone.sageonemobile.android.view.PinButtonRenderer"),"Timed out waiting for PIN screen", new TimeSpan (0, 0, 0, 10), null, null);
  111. app.Screenshot("Then I am asked to Enter my pin number");
  112.  
  113. //Enter Pin
  114. AppResult pinButton = app.Query(x => x.Class("sage.sageone.sageonemobile.android.view.PinButtonRenderer"))[0];
  115.  
  116. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  117. app.Screenshot("Then I enter my PIN");
  118.  
  119. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  120. app.Screenshot("Then I enter my PIN");
  121.  
  122. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  123. app.Screenshot("Then I enter my PIN");
  124.  
  125. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  126. app.Screenshot("Then I enter my PIN");
  127.  
  128. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  129. app.Screenshot("Then I enter my PIN");
  130.  
  131. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  132. app.Screenshot("Then I enter my PIN");
  133.  
  134. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  135. app.Screenshot("Then I enter my PIN");
  136.  
  137. app.TapCoordinates(pinButton.Rect.CenterX, pinButton.Rect.CenterY);
  138. app.Screenshot("Then I enter my PIN");
  139.  
  140.  
  141. //to keep screen alive
  142. Thread.Sleep(4000);
  143. app.TapCoordinates(10, 10);
  144.  
  145. //And logged in
  146. app.WaitForElement(x => x.Text("New Contact"), "Timed out logging in", new TimeSpan(0, 0, 25), null, null);
  147. app.Screenshot("And I am logged in");
  148.  
  149. }
  150.  
  151. public void AddContact()
  152. {
  153.  
  154. //Add Contact
  155. app.WaitForThenTap(
  156. x => x.Text("New Contact"),
  157. "Then I add a new contact");
  158.  
  159. //find coordinates and tap to give focus, then enter text.
  160. AppResult firstName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
  161. app.TapCoordinates(firstName.Rect.CenterX, firstName.Rect.CenterY);
  162. app.EnterText("John");
  163. app.Screenshot("Then I enter the first name");
  164.  
  165. //find coordinates and tap to give focus, then enter text.
  166. AppResult lastName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[1];
  167. app.TapCoordinates(lastName.Rect.CenterX, lastName.Rect.CenterY);
  168. app.EnterText("Doe");
  169. app.Screenshot("Then I enter the last name");
  170.  
  171. app.Tap(x => x.Text("Save"));
  172. app.Screenshot("Then I save the contact");
  173.  
  174. app.WaitForElement(x => x.Text("Contact Details"));
  175. app.Tap(x => x.Text("Contact Details"));
  176. app.Screenshot("Then I navigate back to the home screen");
  177.  
  178. }
  179.  
  180. public void NewInvoice()
  181. {
  182. // new invoice
  183. app.WaitForThenTap(x => x.Text("New Invoice"), "Then I create a new invoice");
  184.  
  185. AppResult contactName = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
  186. app.TapCoordinates(contactName.Rect.CenterX, contactName.Rect.CenterY);
  187. app.EnterText("j");
  188. app.Screenshot("Then I start to type the customer's name");
  189.  
  190. app.WaitForThenTap(x => x.Text("John Doe"), "Then I tap the contacts name");
  191.  
  192. app.WaitForThenTap(x => x.Text("Add Item"), "Then I add an item");
  193.  
  194. AppResult addItem = app.Query(x => x.Class("xamarin.forms.platform.android.EntryEditText"))[0];
  195. app.TapCoordinates(addItem.Rect.CenterX, addItem.Rect.CenterY);
  196. Thread.Sleep(1000);
  197. app.EnterText("Awesome Description");
  198. app.Screenshot("Then I enter an item");
  199.  
  200. app.WaitForThenTap(x => x.Text("Save"), "Then I save the item");
  201.  
  202. app.WaitForThenTap(x => x.Text("Save"), "Then I save the invoice");
  203.  
  204. app.WaitForThenTap(x => x.Id("action_bar_title"), "Then I navigate back to the home screen");
  205. }
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement