Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.62 KB | None | 0 0
  1. using NUnit.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using Newtonsoft.Json;
  5. using Xamarin.UITest;
  6.  
  7. namespace fieldapp.UITests
  8. {
  9. [TestFixture(Platform.Android)]
  10. [TestFixture(Platform.iOS)]
  11.  
  12. public class Tests
  13. {
  14. IApp app;
  15. private readonly Platform _platform;
  16. private const string testUser = "intern280";
  17. private const string testPass = "pO$LoW94";
  18.  
  19. public Tests(Platform platform)
  20. {
  21. this._platform = platform;
  22. }
  23.  
  24. private object Invoke(string method, object val = null)
  25. {
  26. if (_platform == Platform.iOS)
  27. {
  28. return app.Invoke($"{method}:", val ?? "").ToString();
  29. }
  30. return app.Invoke(method, val);
  31. }
  32.  
  33. [SetUp]
  34. public void BeforeEachTest()
  35. {
  36. app = AppInitializer.StartApp(_platform);
  37. Invoke("SetTestFlag");
  38. }
  39.  
  40. [Test]
  41. public void TestLogin()
  42. {
  43. takeScreenshot("Given that I'm on the login screen, and I click the choose server button");
  44. ClickButtonWithServers();
  45. takeScreenshot("Then I should see a list of the available servers");
  46. SelectServerTP();
  47. takeScreenshot("When I click on the server from the list, then I should be back on the login screen, and selected server should be visible under 'Server' label");
  48. AssertLabelHasText("choseServerButtonTest", "thinkproject!", "The correct selected server is not visible in Server label!");
  49. TestWriteLoginAndPassword(testUser, testPass);
  50. takeScreenshot("When I fill in the correct login and password, and I tap the login button");
  51. ClickLoginButton();
  52. app.WaitForElement("projectslistViewTest", "Projects list did not appear!", timeout: TimeSpan.FromSeconds(300));
  53. takeScreenshot("Then I should be succesfully logged in and see the list of the projects");
  54. }
  55.  
  56. [Test]
  57. public void TestProgressIndicator()
  58. {
  59. ClickButtonWithServers();
  60. SelectServerTP();
  61. AssertLabelHasText("choseServerButtonTest", "thinkproject!", "The correct selected server is not visible in Server label!");
  62. TestWriteLoginAndPassword(testUser, testPass);
  63. takeScreenshot("Given that I input the correct credentials on the login screen, when I tap the login button");
  64. ClickLoginButton();
  65. app.WaitForElement("progressPageTest", "Progress indicator did not appear!", timeout: TimeSpan.FromSeconds(30));
  66. takeScreenshot("Then I should see the progress indicator");
  67. app.WaitForElement("projectslistViewTest", "Projects list did not appear!", timeout: TimeSpan.FromSeconds(350));
  68. takeScreenshot("And then I should see the list of the projects");
  69. }
  70.  
  71. [Test]
  72. public void TestLoginWrongCredentials()
  73. {
  74. ClickButtonWithServers();
  75. SelectServerTP();
  76. AssertLabelHasText("choseServerButtonTest", "thinkproject!", "The correct selected server is not visible in Server label!");
  77. TestWriteLoginAndPassword("A", "B");
  78. takeScreenshot("Given that I input the wrong credentials on the login screen, and I tap the login button");
  79. ClickLoginButton();
  80. AssertLabelHasText("messageLabelTest", "Login failed", "Error message not displayed");
  81. takeScreenshot("Then I should see an error message that login has failed");
  82. }
  83.  
  84. [Test]
  85. public void TestLoginIncorectValues()
  86. {
  87. WriteStringToUsername(" ");
  88. takeScreenshot("Given that I input incorrect values (in this case empty login and password) on the login screen, and I tap the login button");
  89. ClickLoginButton();
  90. AssertLabelHasText("messageLabelTest", "Invalid login or password", "Error message not displayed");
  91. takeScreenshot("Then I should see an error message about invalid login or password");
  92. }
  93.  
  94. [Test]
  95. public void TestLoginAndChooseProject()
  96. {
  97. app.WaitForElement("choseServerButtonTest", "Choose server button did not appear!");
  98. TestWriteLoginAndPassword(testUser, testPass);
  99. ClickLoginButton();
  100. takeScreenshot("Given that I have successfully logged in");
  101. app.WaitForElement("projectslistViewTest", "Projects list did not appear!", timeout: TimeSpan.FromSeconds(300));
  102. takeScreenshot("Then I should see the list of the projects. When I tap the project name");
  103. app.Tap("Template für FotoPusher");
  104. app.WaitForElement("documentsTypelistViewTest", "Document types list did not appear!", timeout: TimeSpan.FromSeconds(10));
  105. takeScreenshot("Then I should see the list of types of documents in the project");
  106. }
  107.  
  108. [Test]
  109. public void TestLoginAndChooseDocumentType()
  110. {
  111. LoginAndChooseProject();
  112. takeScreenshot("Given that I have chosen the project, and I tap the document type");
  113. app.Tap("Photo Documentation");
  114. app.WaitForElement("documentsListViewTest", "Document List did not appear!", timeout: TimeSpan.FromSeconds(10));
  115. takeScreenshot("Then I should see the list of documents in the given category");
  116. }
  117.  
  118. [Test]
  119. public void TestAddNewDocument()
  120. {
  121. LoginAndChooseDocumentType();
  122. takeScreenshot("Given that I'm on the Document List screen, and I tap the ADD button");
  123. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  124. app.Tap("add");
  125.  
  126. //Filling the data
  127.  
  128. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  129. takeScreenshot("Then I should be on the New Document screen");
  130. app.EnterText("Subject_Entry", "doc1");
  131.  
  132. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  133. app.Tap("Attachments_Entry");
  134. AddPhotoAttachment();
  135. AddPhotoAttachment();
  136. AddPhotoAttachment();
  137. app.Back();
  138.  
  139. app.WaitForElement("Description_Entry", "Description Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  140. app.EnterText("Description_Entry", "exampleDescription");
  141. app.DismissKeyboard();
  142. if (this._platform == Platform.Android)
  143. {
  144. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  145. app.ScrollDownTo("SelectionPlace_Entry");
  146. app.Tap("SelectionPlace_Entry");
  147. app.WaitForElement("select_dialog_listview", "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  148. app.Tap("Building A");
  149. }
  150. else if (this._platform == Platform.iOS)
  151. {
  152. app.Tap("Description_Entry");
  153. app.DismissKeyboard();
  154. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  155. app.ScrollDownTo("SelectionPlace_Entry");
  156. app.Tap("SelectionPlace_Entry");
  157. app.WaitForElement(c => c.Class("UIPickerView"), "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  158. app.Tap("Building A");
  159. app.Tap("Done");
  160. }
  161.  
  162. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry"), "Auswahl Type Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  163. app.ScrollDownTo("AuswahlType_Entry");
  164. app.Tap("AuswahlType_Entry");
  165. app.WaitForElement("searchingListTest", "List of Auswahl Types did not appear!", timeout: TimeSpan.FromSeconds(10));
  166. app.Tap("Defect");
  167.  
  168. app.WaitForElement(c => c.All().Marked("Latitude_Entry"), "Latitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  169. app.ScrollDownTo("Latitude_Entry");
  170. app.EnterText("Latitude_Entry", "23.23252");
  171. app.DismissKeyboard();
  172. app.WaitForElement(c => c.All().Marked("Longitude_Entry"), "Longitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  173. app.ScrollDownTo("Longitude_Entry");
  174. app.EnterText("Longitude_Entry", "32.2652");
  175. app.DismissKeyboard();
  176. setDateInDatePicker(2016, 3, 12);
  177. takeScreenshot("When I enter the data, and I tap the save button");
  178. app.WaitForElement("save", "Save button did not appear!", timeout: TimeSpan.FromSeconds(10));
  179. app.Tap("save");
  180. app.WaitForElement("doc1", "Added document doc1 did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  181. takeScreenshot("Then I should be back on the Document List screen, and the newly added document should be on the list");
  182. app.Back();
  183. takeScreenshot("When I go back on the Document Types screen, and I select the document type");
  184. app.Tap("Photo Documentation");
  185. app.WaitForElement("documentsListViewTest", "Document list did not appear!", timeout: TimeSpan.FromSeconds(10));
  186. app.WaitForElement("doc1", "Added document doc1 did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  187. takeScreenshot("Then the newly added document should still be there. When I tap on the document name");
  188.  
  189. //Checking if the document was saved correctly
  190.  
  191. app.Tap("doc1");
  192.  
  193. app.WaitForElement(c => c.Marked("Subject_Entry").Text("doc1"), "Subject text field contains incorrect data!", timeout: TimeSpan.FromSeconds(10));
  194.  
  195. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  196. app.Tap("Attachments_Entry");
  197. app.WaitForElement("ImageAttachementListTest", "Attachments list list did not appear!", timeout: TimeSpan.FromSeconds(15));
  198.  
  199. for (int i = 1; i <= 3; i++)
  200. {
  201. app.WaitForElement("photostub_" + i, "List of attachments contains incorrect attchments!", timeout: TimeSpan.FromSeconds(10));
  202. }
  203.  
  204. app.Back();
  205.  
  206. app.WaitForElement(c => c.Marked("Description_Entry").Descendant().Text("exampleDescription"), "Description text field contains incorrect data! Expected value: 'exampleDescription'", timeout: TimeSpan.FromSeconds(10));
  207. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry").Text("Building A"), "Selection Place text field contains incorrect data! Expected value: 'Building B'", timeout: TimeSpan.FromSeconds(10));
  208. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry").Descendant().Text("Defect"), "Auswahl Type text field contains incorrect data! Expected value: 'Defect'", timeout: TimeSpan.FromSeconds(10));
  209. app.WaitForElement(c => c.All().Marked("Latitude_Entry").Text("23.23252"), "Latitude text field contains incorrect data! Expected value: '23.23252'", timeout: TimeSpan.FromSeconds(10));
  210. app.WaitForElement(c => c.All().Marked("Longitude_Entry").Text("32.2652"), "Longitude text field contains incorrect data! Expected value: '32.2652'", timeout: TimeSpan.FromSeconds(10));
  211. app.WaitForElement(c => c.All().Marked("RecordingDate/Time_Entry").Text("3/12/2016"), "Recording Date/Time text field contains incorrect data! Expected value: '3/12/2016'", timeout: TimeSpan.FromSeconds(10));
  212.  
  213. takeScreenshot("Then I should see that entire document was saved properly");
  214.  
  215. }
  216.  
  217. [Test]
  218. public void TestGPSCoordinatesFetch()
  219. {
  220. app.Device.SetLocation(53.4285, 14.5528);
  221. LoginAndChooseDocumentType();
  222. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  223. app.Tap("add");
  224. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  225. takeScreenshot("Given I am on the New Document screen and the device has GPS signal");
  226.  
  227. if (this._platform == Platform.Android)
  228. {
  229. app.WaitForElement("More options", "More Options button did not appear!", timeout: TimeSpan.FromSeconds(10));
  230. app.Tap("More options");
  231. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  232. takeScreenshot("When I open the options menu, and I click the GPS button");
  233. }
  234. else if (this._platform == Platform.iOS)
  235. {
  236. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  237. takeScreenshot("When I tap the GPS button");
  238. }
  239.  
  240. app.Tap("GPS");
  241.  
  242. app.WaitForElement(c => c.All().Marked("Latitude_Entry").Text("53.4285"), "Latitude is incorrect! Expected value: 53.4285", timeout: TimeSpan.FromSeconds(15));
  243. app.WaitForElement(c => c.All().Marked("Longitude_Entry").Text("14.5528"), "Longitude is incorrect! Expected value: 14.5528", timeout: TimeSpan.FromSeconds(15));
  244. takeScreenshot("Then the correct GPS coordinates should be fetched and entered into Latutude and Longitude fields");
  245. }
  246.  
  247. [Test]
  248. public void TestGPSCoordinatesFetchWhenNoSignal()
  249. {
  250. Invoke("SetGps", "Noise");
  251. LoginAndChooseDocumentType();
  252. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  253. app.Tap("add");
  254. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  255. takeScreenshot("Given I am on the New Document screen and the device's GPS is on but has no signal");
  256.  
  257. if (this._platform == Platform.Android)
  258. {
  259. app.WaitForElement("More options", "More Options button did not appear!", timeout: TimeSpan.FromSeconds(10));
  260. app.Tap("More options");
  261. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  262. takeScreenshot("When I open the options menu, and I click the GPS button");
  263. }
  264. else if (this._platform == Platform.iOS)
  265. {
  266. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  267. takeScreenshot("When I tap the GPS button");
  268. }
  269.  
  270. app.Tap("GPS");
  271.  
  272. app.WaitForElement(c => c.All().Marked("Latitude_Entry").Text("Can't read GPS"), "Latitude is incorrect! Expected value: 'Can't read GPS'", timeout: TimeSpan.FromSeconds(15));
  273. app.WaitForElement(c => c.All().Marked("Longitude_Entry").Text("Can't read GPS"), "Longitude is incorrect! Expected value: 'Can't read GPS'", timeout: TimeSpan.FromSeconds(15));
  274. takeScreenshot("Then there should be a 'Can't read GPS' message in both the Latitude and Longitude fields");
  275. }
  276.  
  277. [Test]
  278. public void TestGPSCoordinatesFetchWhenGPSIsOff()
  279. {
  280. Invoke("SetGps", "Off");
  281. LoginAndChooseDocumentType();
  282. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  283. app.Tap("add");
  284. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  285. takeScreenshot("Given I am on the New Document screen and the device's GPS is off or unavailable");
  286.  
  287. if (this._platform == Platform.Android)
  288. {
  289. app.WaitForElement("More options", "More Options button did not appear!", timeout: TimeSpan.FromSeconds(10));
  290. app.Tap("More options");
  291. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  292. takeScreenshot("When I open the options menu, and I click the GPS button");
  293. }
  294. else if (this._platform == Platform.iOS)
  295. {
  296. app.WaitForElement("GPS", "GPS button did not appear!", timeout: TimeSpan.FromSeconds(10));
  297. takeScreenshot("When I tap the GPS button");
  298. }
  299.  
  300. app.Tap("GPS");
  301.  
  302. app.WaitForElement(c => c.All().Marked("Latitude_Entry").Text("GPS unavailable"), "Latitude is incorrect! Expected value: 'GPS unavailable'", timeout: TimeSpan.FromSeconds(15));
  303. app.WaitForElement(c => c.All().Marked("Longitude_Entry").Text("GPS unavailable"), "Longitude is incorrect! Expected value: 'GPS unavailable'", timeout: TimeSpan.FromSeconds(15));
  304. takeScreenshot("Then there should be a 'GPS unavailable' message in both the Latitude and Longitude fields");
  305. }
  306.  
  307. [Test]
  308. public void TestProperFieldsVisibleForNewDocument()
  309. {
  310. checkFields("visible");
  311. }
  312.  
  313. [Test]
  314. public void TestAddPhotoAttachmentFromCamera()
  315. {
  316. LoginAndChooseDocumentType();
  317. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  318. app.Tap("add");
  319. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  320. takeScreenshot("Given that I'm on the New Document screen, when I tap the 'Attachments' button");
  321. app.Tap("Attachments_Entry");
  322. app.WaitForElement("AddPhotoTest", "'Add Photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  323. takeScreenshot("Then I should be on the Attachments screen. When I tap the 'Add Photo' button");
  324. app.Tap("AddPhotoTest");
  325. takeScreenshot("Then the list of options should appear. When I tap the 'Take a photo' option");
  326. app.WaitForElement("Take a photo", "'Take a photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  327. app.Tap("Take a photo");
  328. app.WaitForElement("ImageAttachementListTest", "Attachments list list did not appear!", timeout: TimeSpan.FromSeconds(15));
  329. app.WaitForElement("photostub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  330. app.Back();
  331. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  332. app.Tap("Attachments_Entry");
  333. app.WaitForElement("photostub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  334. takeScreenshot("Then the photo should be taken, and it should appear on the list of attachments.");
  335. }
  336.  
  337. [Test]
  338. public void TestAddPhotoAttachmentFromGallery()
  339. {
  340. LoginAndChooseDocumentType();
  341. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  342. app.Tap("add");
  343. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  344. takeScreenshot("Given that I'm on the New Document screen, when I tap the 'Attachments' button");
  345. app.Tap("Attachments_Entry");
  346. app.WaitForElement("AddPhotoTest", "'Add Photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  347. takeScreenshot("Then I should be on the Attachments screen. When I tap the 'Add Photo' button");
  348. app.Tap("AddPhotoTest");
  349. takeScreenshot("Then the list of options should appear. When I tap the 'Select photo from gallery' option");
  350. app.WaitForElement("Select photo from gallery", "'Select photo from gallery' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  351. app.Tap("Select photo from gallery");
  352. app.WaitForElement("ImageAttachementListTest", "Attachments list list did not appear!", timeout: TimeSpan.FromSeconds(15));
  353. app.WaitForElement("gallerystub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  354. app.Back();
  355. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  356. app.Tap("Attachments_Entry");
  357. app.WaitForElement("gallerystub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  358. takeScreenshot("Then the photo should be selected from gallery, and it should appear on the list of attachments");
  359. }
  360.  
  361. [Test]
  362. public void TestDeletePhotoAttachment()
  363. {
  364. LoginAndAddPhotoAttachment();
  365.  
  366. app.WaitForElement("photostub_1", "photostub_1 attachment did not appear!", timeout: TimeSpan.FromSeconds(10));
  367.  
  368. if (this._platform == Platform.Android)
  369. {
  370. takeScreenshot("Given that I'm on Attachments screen, and there is an attachment added, when I tap and hold the attachment");
  371. app.TouchAndHold("photostub_1");
  372. app.WaitForElement("Delete", "'Delete' button didn't appear!", timeout: TimeSpan.FromSeconds(10));
  373. takeScreenshot("Then 'Delete' button should appear on the upper bar. When I tap the delete button");
  374. }
  375. else if (this._platform == Platform.iOS)
  376. {
  377. takeScreenshot("Given that I'm on Attachments screen, and there is an attachment added, when I tap and swipe left the attachment");
  378. app.SwipeRightToLeft("photostub_1");
  379. app.WaitForElement("Delete", "'Delete' button didn't appear!", timeout: TimeSpan.FromSeconds(10));
  380. takeScreenshot("Then 'Delete' button should appear to the right of the attachment name. When I tap the delete button");
  381. }
  382.  
  383. app.Tap("Delete");
  384. app.WaitForNoElement("photostub_1", "Photo is still on the list of attachment but it was supposed to be deleted!", timeout: TimeSpan.FromSeconds(10));
  385. app.Back();
  386. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  387. app.Tap("Attachments_Entry");
  388. app.WaitForNoElement("photostub_1", "Photo is still on the list of attachments but it was supposed to be deleted!", timeout: TimeSpan.FromSeconds(10));
  389. takeScreenshot("Then the attachment should be removed from the list of attachments");
  390. }
  391.  
  392. [Test]
  393. public void TestViewAttachmentPreview()
  394. {
  395. LoginAndAddPhotoAttachment();
  396. takeScreenshot("Given that I'm on Attachments screen, and there is an attachment added, when I tap the attachment");
  397. app.WaitForElement("photostub_1", "photostub_1 attachment did not appear!", timeout: TimeSpan.FromSeconds(10));
  398. app.Tap("photostub_1");
  399. app.WaitForElement("photostub_1", "Attachment preview screen did not appear!", timeout: TimeSpan.FromSeconds(10));
  400.  
  401. if (this._platform == Platform.Android)
  402. app.WaitForElement(c => c.Class("FormsImageView"), "Attachment preview did not appear!", timeout: TimeSpan.FromSeconds(10));
  403. else if (this._platform == Platform.iOS)
  404. app.WaitForElement(c => c.Class("UINavigationTransitionView").Class("UIImageView"), "Attachment preview did not appear!", timeout: TimeSpan.FromSeconds(10));
  405.  
  406. takeScreenshot("Then I should see preview of the attachment");
  407. }
  408.  
  409. [Test]
  410. public void TestEditDocument()
  411. {
  412. //Adding document for test
  413. AddNewDocument();
  414. takeScreenshot("Given that I'm on the Document List screen and there is a document already on the list, when I tap on the document");
  415. app.WaitForElement("doc1", "doc1 document did not appear!", timeout: TimeSpan.FromSeconds(10));
  416. app.Tap("doc1");
  417. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  418. takeScreenshot("Then I should be on the document edit screen");
  419.  
  420. //Editing document
  421.  
  422. app.ClearText("Subject_Entry");
  423. app.EnterText("Subject_Entry", "editedSubject");
  424.  
  425. if (this._platform == Platform.iOS)
  426. {
  427. app.Tap(c => c.All().Marked("Subject_Entry"));
  428. app.DismissKeyboard();
  429. app.ClearText("Subject_Entry");
  430. app.EnterText("Subject_Entry", "editedSubject");
  431. app.Tap(c => c.All().Marked("Subject_Entry"));
  432. app.DismissKeyboard();
  433. }
  434.  
  435. //Adding 1 additional attachment (should be 4 now)
  436.  
  437. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  438. app.Tap("Attachments_Entry");
  439. AddPhotoAttachment();
  440. app.Back();
  441.  
  442. app.WaitForElement("Description_Entry", "Description Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  443.  
  444. if (this._platform == Platform.Android)
  445. app.ClearText("Description_Entry");
  446. else if (this._platform == Platform.iOS)
  447. app.ClearText(c => c.All().Marked("Description_Entry").Class("UITextView"));
  448.  
  449. app.EnterText("Description_Entry", "editedDescription");
  450. app.DismissKeyboard();
  451.  
  452. if (this._platform == Platform.Android)
  453. {
  454. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  455. app.ScrollDownTo("SelectionPlace_Entry");
  456. app.Tap("SelectionPlace_Entry");
  457. app.WaitForElement("select_dialog_listview", "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  458. app.Tap("Building B");
  459.  
  460. }
  461. else if (this._platform == Platform.iOS)
  462. {
  463. app.Tap("Description_Entry");
  464. app.DismissKeyboard();
  465. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  466. app.ScrollDownTo("SelectionPlace_Entry");
  467. app.Tap("SelectionPlace_Entry");
  468. app.WaitForElement(c => c.Class("UIPickerView"), "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  469. app.Tap("Building B");
  470. app.Tap("Done");
  471. }
  472.  
  473. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry"), "Auswahl Type Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  474. app.ScrollDownTo("AuswahlType_Entry");
  475. app.Tap("AuswahlType_Entry");
  476. app.WaitForElement("searchingListTest", "List of Auswahl Types did not appear!", timeout: TimeSpan.FromSeconds(10));
  477. app.Tap("Security");
  478.  
  479. app.WaitForElement(c => c.All().Marked("Latitude_Entry"), "Latitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  480. app.ScrollDownTo("Latitude_Entry");
  481. app.ClearText("Latitude_Entry");
  482. app.EnterText("Latitude_Entry", "100");
  483. app.DismissKeyboard();
  484. app.WaitForElement(c => c.All().Marked("Longitude_Entry"), "Longitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  485. app.ScrollDownTo("Longitude_Entry");
  486. app.ClearText("Longitude_Entry");
  487. app.EnterText("Longitude_Entry", "120");
  488. app.DismissKeyboard();
  489. setDateInDatePicker(2016, 6, 24);
  490. takeScreenshot("When I edit the data and I tap the 'SAVE' button");
  491.  
  492. //Saving the edited document
  493.  
  494. app.WaitForElement("save", "Save button did not appear!", timeout: TimeSpan.FromSeconds(10));
  495. app.Tap("save");
  496. app.WaitForElement("editedSubject", "Edited document 'editedSubject' did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  497. takeScreenshot("Then I should be back on the Document List screen, and the edited document name should already be visible. When I tap on the document name");
  498. app.Tap("editedSubject");
  499. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  500.  
  501. //Checking if data got edited
  502.  
  503. app.WaitForElement(c => c.Marked("Subject_Entry").Text("editedSubject"), "Subject field was not edited! Expected value: 'editedSubject'", timeout: TimeSpan.FromSeconds(10));
  504.  
  505. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  506. app.Tap("Attachments_Entry");
  507.  
  508. for (int i = 1; i <= 4; i++)
  509. {
  510. app.WaitForElement("photostub_" + i, "List of attachments contains incorrect attachments! 4 attachments - photostub_1/2/3/4 were expected!", timeout: TimeSpan.FromSeconds(10));
  511. }
  512.  
  513. app.Back();
  514.  
  515. app.WaitForElement(c => c.Marked("Description_Entry").Descendant().Text("editedDescription"), "Description field was not edited! Expected value: 'editedDescription'", timeout: TimeSpan.FromSeconds(10));
  516. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry").Text("Building B"), "Selection Place field was not edited! Expected value: 'Building B'", timeout: TimeSpan.FromSeconds(10));
  517. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry").Descendant().Text("Security"), "Auswahl Type field was not edited! Expected value: 'Security'", timeout: TimeSpan.FromSeconds(10));
  518. app.WaitForElement(c => c.All().Marked("Latitude_Entry").Text("100"), "Latitude field was not edited! Expected value: '100'", timeout: TimeSpan.FromSeconds(10));
  519. app.WaitForElement(c => c.All().Marked("Longitude_Entry").Text("120"), "Longitude field was not edited! Expected value: '120'", timeout: TimeSpan.FromSeconds(10));
  520. app.WaitForElement(c => c.All().Marked("RecordingDate/Time_Entry").Text("6/24/2016"), "Recording Date/Time text field was not edited! Expected value: '6/24/2016'", timeout: TimeSpan.FromSeconds(10));
  521. takeScreenshot("Then I should see the edited document. When I tap the 'Attachments button'");
  522.  
  523. //Additional step for checking if attachment list gets saved correctly after deleting the attachment
  524.  
  525. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  526. app.Tap("Attachments_Entry");
  527.  
  528. app.WaitForElement("photostub_4", "Attachment 'photostub_4' did not appear!", timeout: TimeSpan.FromSeconds(10));
  529.  
  530. if (this._platform == Platform.Android)
  531. app.TouchAndHold("photostub_4");
  532. else if (this._platform == Platform.iOS)
  533. app.SwipeRightToLeft("photostub_4");
  534.  
  535. app.WaitForElement("Delete", "'Delete' button didn't appear!", timeout: TimeSpan.FromSeconds(10));
  536. takeScreenshot("And I delete the last attachment on the list");
  537. app.Tap("Delete");
  538. app.Back();
  539.  
  540. takeScreenshot("And I go back and save the edited document");
  541. app.WaitForElement("save", "Save button did not appear!", timeout: TimeSpan.FromSeconds(10));
  542. app.Tap("save");
  543. app.WaitForElement("editedSubject", "Edited document 'editedSubject' did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  544. app.Tap("editedSubject");
  545.  
  546. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  547. app.Tap("Attachments_Entry");
  548.  
  549. for (int i = 1; i <= 3; i++)
  550. {
  551. app.WaitForElement("photostub_" + i, "List of attachments contains incorrect attachments! 3 attachments - photostub_1/2/3 were expected!", timeout: TimeSpan.FromSeconds(10));
  552. }
  553.  
  554. app.WaitForNoElement("photostub_4", "List of attachments contains incorrect attachments! 3 attachments - photostub_1/2/3 were expected!", timeout: TimeSpan.FromSeconds(10));
  555. takeScreenshot("Then when I go back on the attachments screen, I should see that the last attachment was deleted and there are only 3 attachments now");
  556. }
  557.  
  558. [Test]
  559. public void TestRemoveDocument()
  560. {
  561. //Adding document for test
  562. AddNewDocument();
  563.  
  564. app.WaitForElement("doc1", "doc1 document did not appear!", timeout: TimeSpan.FromSeconds(10));
  565.  
  566. if (this._platform == Platform.Android)
  567. {
  568. takeScreenshot("Given that I'm on the Document List screen and there is a document already on the list, when I tap and hold the document name");
  569. app.TouchAndHold("doc1");
  570. app.WaitForElement("Delete", "'Delete' button didn't appear!", timeout: TimeSpan.FromSeconds(10));
  571. takeScreenshot("Then 'Delete' button should appear on the upper bar. When I tap the delete button");
  572. }
  573. else if (this._platform == Platform.iOS)
  574. {
  575. takeScreenshot("Given that I'm on Document List screen, and there is a document already on the list, when I tap and swipe left the document name");
  576. app.SwipeRightToLeft("doc1");
  577. app.WaitForElement("Delete", "'Delete' button didn't appear!", timeout: TimeSpan.FromSeconds(10));
  578. takeScreenshot("Then 'Delete' button should appear to the right of the document name. When I tap the delete button");
  579. }
  580. app.Tap("Delete");
  581. app.WaitForNoElement("doc1", "Document 'doc1' is still on the list of documents, but it was supposed to be deleted!", timeout: TimeSpan.FromSeconds(10));
  582. takeScreenshot("Then the document should be removed from the list");
  583. }
  584.  
  585. [Test]
  586. public void TestCheckForRequiredFields()
  587. {
  588. checkFields("required");
  589. }
  590.  
  591. [Test]
  592. public void TestValidationCheckRequiredFields()
  593. {
  594. LoginAndChooseDocumentType();
  595. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  596. app.Tap("add");
  597. takeScreenshot("Given that I'm on the New Document screen");
  598. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  599.  
  600. List<string> listOfRequiredFields = getListOfRequiredFields();
  601. app.Back();
  602.  
  603. //fill everything EXCEPT the given required field
  604.  
  605. foreach (string requiredFieldName in listOfRequiredFields)
  606. {
  607. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  608. app.Tap("add");
  609.  
  610. string requiredFieldEntry = requiredFieldName.Replace(" ", string.Empty) + "_Entry";
  611.  
  612. if (String.Compare(requiredFieldEntry, "Subject_Entry") != 0)
  613. {
  614. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  615. app.EnterText("Subject_Entry", "doc1");
  616. }
  617.  
  618. if (String.Compare(requiredFieldEntry, "Attachments_Entry") != 0)
  619. {
  620. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  621. app.Tap("Attachments_Entry");
  622. AddPhotoAttachment();
  623. AddPhotoAttachment();
  624. AddPhotoAttachment();
  625. app.Back();
  626. }
  627.  
  628. if (String.Compare(requiredFieldEntry, "Description_Entry") != 0)
  629. {
  630. app.WaitForElement("Description_Entry", "Description Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  631. app.EnterText("Description_Entry", "exampleDescription");
  632. app.DismissKeyboard();
  633.  
  634. if (this._platform == Platform.iOS)
  635. {
  636. app.Tap("Description_Entry");
  637. app.DismissKeyboard();
  638. }
  639. }
  640.  
  641.  
  642. if (String.Compare(requiredFieldEntry, "SelectionPlace_Entry") != 0)
  643. {
  644. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  645. app.ScrollDownTo("SelectionPlace_Entry");
  646. app.Tap("SelectionPlace_Entry");
  647.  
  648. if (this._platform == Platform.Android)
  649. {
  650. app.WaitForElement("select_dialog_listview", "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  651. app.Tap("Building A");
  652. }
  653. else if (this._platform == Platform.iOS)
  654. {
  655. app.WaitForElement(c => c.Class("UIPickerView"), "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  656. app.Tap("Building A");
  657. app.Tap("Done");
  658. }
  659. }
  660.  
  661. if (String.Compare(requiredFieldEntry, "AuswahlType_Entry") != 0)
  662. {
  663. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry"), "Auswahl Type Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  664. app.ScrollDownTo("AuswahlType_Entry");
  665. app.Tap("AuswahlType_Entry");
  666.  
  667. app.WaitForElement("searchingListTest", "List of Auswahl Types did not appear!", timeout: TimeSpan.FromSeconds(10));
  668. app.Tap("Defect");
  669. }
  670.  
  671. if (String.Compare(requiredFieldEntry, "Latitude_Entry") != 0)
  672. {
  673. app.WaitForElement(c => c.All().Marked("Latitude_Entry"), "Latitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  674. app.ScrollDownTo("Latitude_Entry");
  675. app.EnterText("Latitude_Entry", "23.23252");
  676. app.DismissKeyboard();
  677. }
  678.  
  679. if (String.Compare(requiredFieldEntry, "Longitude_Entry") != 0)
  680. {
  681. app.WaitForElement(c => c.All().Marked("Longitude_Entry"), "Longitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  682. app.ScrollDownTo("Longitude_Entry");
  683. app.EnterText("Longitude_Entry", "32.2652");
  684. app.DismissKeyboard();
  685. }
  686.  
  687. if (String.Compare(requiredFieldEntry, "RecordingDate/Time_Entry") != 0)
  688. setDateInDatePicker(2016, 3, 12);
  689.  
  690. takeScreenshot("When I fill all fields except the '" + requiredFieldName + "' field");
  691.  
  692. //saving the document
  693.  
  694. app.WaitForElement("save", "Save button did not appear!", timeout: TimeSpan.FromSeconds(10));
  695. app.Tap("save");
  696.  
  697. //sending the document
  698.  
  699. if (String.Compare(requiredFieldEntry, "Subject_Entry") == 0)
  700. {
  701. if (this._platform == Platform.Android)
  702. app.TouchAndHold(c => c.Class("ConditionalFocusLayout"));
  703. else if (this._platform == Platform.iOS)
  704. app.SwipeRightToLeft(c => c.Class("Xamarin_Forms_Platform_iOS_CellTableViewCell"));
  705. }
  706. else
  707. {
  708. if (this._platform == Platform.Android)
  709. app.TouchAndHold("doc1");
  710. else if (this._platform == Platform.iOS)
  711. app.SwipeRightToLeft("doc1");
  712. }
  713.  
  714.  
  715. app.WaitForElement("Send", "SEND button did not appear!", timeout: TimeSpan.FromSeconds(10));
  716. takeScreenshot("And I save the document and then try sending it to the server");
  717. app.Tap("Send");
  718.  
  719. //checking for the validation message
  720.  
  721. if (this._platform == Platform.Android)
  722. app.WaitForElement(c => c.Marked("message").Text("Required field is empty\n Required field missing exception"), "Validation error message did not appear when checking for '" + requiredFieldName + "' required field!", timeout: TimeSpan.FromSeconds(10));
  723. else if (this._platform == Platform.iOS)
  724. app.WaitForElement(c => c.Class("UILabel").Text("Required field is empty\n Required field missing exception"), "Validation error message did not appear when checking for '" + requiredFieldName + "' required field!", timeout: TimeSpan.FromSeconds(10));
  725.  
  726. takeScreenshot("Then the validation error message about empty required fields should appear");
  727. app.WaitForElement("Ok", "OK button did not appear!", timeout: TimeSpan.FromSeconds(10));
  728. app.Tap("Ok");
  729.  
  730. //deleting the document for the next loop run
  731.  
  732. if (String.Compare(requiredFieldEntry, "Subject_Entry") == 0)
  733. {
  734. if (this._platform == Platform.Android)
  735. {
  736. app.WaitForElement(c => c.Class("ConditionalFocusLayout"), "Document with empty subject did not appear!", timeout: TimeSpan.FromSeconds(10));
  737. app.TouchAndHold(c => c.Class("ConditionalFocusLayout"));
  738. }
  739. else if (this._platform == Platform.iOS)
  740. {
  741. app.WaitForElement(c => c.Class("Xamarin_Forms_Platform_iOS_CellTableViewCell"), "Document with empty subject did not appear!", timeout: TimeSpan.FromSeconds(10));
  742. app.SwipeRightToLeft(c => c.Class("Xamarin_Forms_Platform_iOS_CellTableViewCell"));
  743. }
  744.  
  745. app.Tap("Delete");
  746. }
  747. else
  748. {
  749. app.WaitForElement("doc1", "doc1 document did not appear!", timeout: TimeSpan.FromSeconds(10));
  750.  
  751. if (this._platform == Platform.Android)
  752. app.TouchAndHold("doc1");
  753. else if (this._platform == Platform.iOS)
  754. app.SwipeRightToLeft("doc1");
  755.  
  756. app.Tap("Delete");
  757. }
  758. }
  759. }
  760.  
  761.  
  762. private void AssertLabelHasText(string automationId, string message, string assertionMessage)
  763. {
  764. app.WaitForElement(c => c.Marked(automationId).Marked(message));
  765. }
  766.  
  767. private void TestWriteLoginAndPassword(string login, string password)
  768. {
  769. WriteStringToUsername(login);
  770. WriteStringToPassword(password);
  771. app.DismissKeyboard();
  772. }
  773.  
  774. private void ClickLoginButton()
  775. {
  776. app.WaitForElement("ClickedLoginButtonTest", "Login button did not appear!", timeout: TimeSpan.FromSeconds(10));
  777. app.Tap("ClickedLoginButtonTest");
  778. }
  779.  
  780. private void ClickButtonWithServers()
  781. {
  782. app.WaitForElement("choseServerButtonTest", "Choose server button did not appear!");
  783. app.Tap("choseServerButtonTest");
  784. }
  785.  
  786. private void WriteStringToUsername(string s)
  787. {
  788. app.WaitForElement("usernameEntryTest", "Username text field did not appear!");
  789. app.ClearText("usernameEntryTest");
  790. app.EnterText("usernameEntryTest", s);
  791. app.DismissKeyboard();
  792. }
  793.  
  794. private void WriteStringToPassword(string s)
  795. {
  796. app.WaitForElement("passwordEntryTest", "Password text field did not appear!");
  797. app.ClearText("passwordEntryTest");
  798. app.EnterText("passwordEntryTest", s);
  799. }
  800.  
  801. private void SelectServerTP()
  802. {
  803. app.WaitForElement("firstItemServersListTest", "Server did not appear!", timeout: TimeSpan.FromSeconds(10));
  804. app.Tap("firstItemServersListTest");
  805. }
  806.  
  807. private void LoginAndChooseDocumentType()
  808. {
  809. LoginAndChooseProject();
  810. app.WaitForElement("Photo Documentation", "Photo Documentation button did not appear!", timeout: TimeSpan.FromSeconds(10));
  811. app.Tap("Photo Documentation");
  812. app.WaitForElement("documentsListViewTest", "Document List did not appear!", timeout: TimeSpan.FromSeconds(10));
  813. }
  814.  
  815. private void LoginAndChooseProject()
  816. {
  817. app.WaitForElement("choseServerButtonTest", "Choose Server button did not appear!");
  818. TestWriteLoginAndPassword(testUser, testPass);
  819. ClickLoginButton();
  820. app.WaitForElement("projectslistViewTest", "Projects List did not appear!", timeout: TimeSpan.FromSeconds(300));
  821. app.Tap("Template für FotoPusher");
  822. app.WaitForElement("documentsTypelistViewTest", "Document Type list did not appear!", timeout: TimeSpan.FromSeconds(10));
  823. }
  824.  
  825.  
  826. private void LoginAndAddPhotoAttachment()
  827. {
  828. LoginAndChooseDocumentType();
  829. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  830. app.Tap("add");
  831. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  832. app.Tap("Attachments_Entry");
  833. app.WaitForElement("AddPhotoTest", "'Add Photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  834. app.Tap("AddPhotoTest");
  835. app.WaitForElement("Take a photo", "'Take a photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  836. app.Tap("Take a photo");
  837. app.WaitForElement("ImageAttachementListTest", "Attachments list list did not appear!", timeout: TimeSpan.FromSeconds(15));
  838. app.WaitForElement("photostub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  839. }
  840.  
  841. private void AddPhotoAttachment()
  842. {
  843. app.WaitForElement("AddPhotoTest", "'Add Photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  844. app.Tap("AddPhotoTest");
  845. app.WaitForElement("Take a photo", "'Take a photo' button did not appear!", timeout: TimeSpan.FromSeconds(10));
  846. app.Tap("Take a photo");
  847. app.WaitForElement("ImageAttachementListTest", "Attachments list list did not appear!", timeout: TimeSpan.FromSeconds(15));
  848. app.WaitForElement("photostub_1", "Photo wasn't added to the list of attachments!", timeout: TimeSpan.FromSeconds(10));
  849. }
  850.  
  851. private void AddNewDocument()
  852. {
  853. LoginAndChooseDocumentType();
  854. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  855. app.Tap("add");
  856.  
  857. //Filling the data
  858.  
  859. app.WaitForElement("Subject_Entry", "Document Subject text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  860. app.EnterText("Subject_Entry", "doc1");
  861.  
  862. app.WaitForElement("Attachments_Entry", "Attachments button did not appear!", timeout: TimeSpan.FromSeconds(10));
  863. app.Tap("Attachments_Entry");
  864. AddPhotoAttachment();
  865. AddPhotoAttachment();
  866. AddPhotoAttachment();
  867. app.Back();
  868.  
  869. app.WaitForElement("Description_Entry", "Description Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  870. app.EnterText("Description_Entry", "exampleDescription");
  871. app.DismissKeyboard();
  872.  
  873. if (this._platform == Platform.Android)
  874. {
  875. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  876. app.ScrollDownTo("SelectionPlace_Entry");
  877. app.Tap("SelectionPlace_Entry");
  878. app.WaitForElement("select_dialog_listview", "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  879. app.Tap("Building A");
  880. }
  881. else if (this._platform == Platform.iOS)
  882. {
  883. app.Tap("Description_Entry");
  884. app.DismissKeyboard();
  885. app.WaitForElement(c => c.All().Marked("SelectionPlace_Entry"), "Selection Place Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  886. app.ScrollDownTo("SelectionPlace_Entry");
  887. app.Tap("SelectionPlace_Entry");
  888. app.WaitForElement(c => c.Class("UIPickerView"), "List of buildings did not appear!", timeout: TimeSpan.FromSeconds(10));
  889. app.Tap("Building A");
  890. app.Tap("Done");
  891. }
  892.  
  893. app.WaitForElement(c => c.All().Marked("AuswahlType_Entry"), "Auswahl Type Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  894. app.ScrollDownTo("AuswahlType_Entry");
  895. app.Tap("AuswahlType_Entry");
  896. app.WaitForElement("searchingListTest", "List of Auswahl Types did not appear!", timeout: TimeSpan.FromSeconds(10));
  897. app.Tap("Defect");
  898.  
  899. app.WaitForElement(c => c.All().Marked("Latitude_Entry"), "Latitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  900. app.ScrollDownTo("Latitude_Entry");
  901. app.EnterText("Latitude_Entry", "23.23252");
  902. app.DismissKeyboard();
  903. app.WaitForElement(c => c.All().Marked("Longitude_Entry"), "Longitude Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  904. app.ScrollDownTo("Longitude_Entry");
  905. app.EnterText("Longitude_Entry", "32.2652");
  906. app.DismissKeyboard();
  907. setDateInDatePicker(2016, 3, 12);
  908. app.WaitForElement("save", "Save button did not appear!", timeout: TimeSpan.FromSeconds(10));
  909. app.Tap("save");
  910. app.WaitForElement("doc1", "Added document doc1 did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  911. app.Back();
  912. app.Tap("Photo Documentation");
  913. app.WaitForElement("documentsListViewTest", "Document list did not appear!", timeout: TimeSpan.FromSeconds(10));
  914. app.WaitForElement("doc1", "Added document doc1 did not appear on the list!", timeout: TimeSpan.FromSeconds(10));
  915. }
  916.  
  917. private void takeScreenshot(string description)
  918. {
  919. string locale = System.Environment.GetEnvironmentVariable("XTC_LOCALE");
  920.  
  921. if (0 != String.Compare(locale, "en_GB"))
  922. {
  923. app.Screenshot(description);
  924. }
  925. }
  926.  
  927. private void setDateInDatePicker(int year, int month, int day)
  928. {
  929. app.WaitForElement(c => c.All().Marked("RecordingDate/Time_Entry"), "Recording Date/Time Entry text field did not appear!", timeout: TimeSpan.FromSeconds(10));
  930. app.ScrollDownTo("RecordingDate/Time_Entry");
  931. app.Tap("RecordingDate/Time_Entry");
  932.  
  933. DateTime date = new DateTime(year, month, day);
  934.  
  935. int mnth;
  936. if (this._platform == Platform.Android)
  937. {
  938. mnth = date.Month - 1;
  939. app.WaitForElement("datePicker", "Date Picker did not appear!", timeout: TimeSpan.FromSeconds(10));
  940. app.Query(c => c.Marked("datePicker").Invoke("updateDate", date.Year, mnth, date.Day));
  941. app.WaitForElement("OK", "OK button in Date Picker did not appear", timeout: TimeSpan.FromSeconds(10));
  942. app.Tap("OK");
  943. }
  944. else if (this._platform == Platform.iOS)
  945. {
  946. mnth = date.Month;
  947. string yearStr = "" + date.Year;
  948. string monthStr = date.ToString("MMMM");
  949. string dateStr = "" + date.Day;
  950.  
  951. app.ScrollDownTo(x => x.Text(monthStr), x => x.Class("UIPickerTableView").Index(0));
  952. app.Tap(x => x.Text(monthStr));
  953. app.ScrollDownTo(x => x.Text(dateStr), x => x.Class("UIPickerTableView").Index(3));
  954. app.Tap(x => x.Text(dateStr));
  955. app.ScrollUpTo(x => x.Text(yearStr), x => x.Class("UIPickerTableView").Index(6));
  956. app.Tap(x => x.Text(yearStr));
  957. app.Tap("Done");
  958. }
  959. }
  960.  
  961. //Possible values: "visible" and "required"
  962. private void checkFields(string checkVisibleOrRequired)
  963. {
  964. LoginAndChooseDocumentType();
  965. app.WaitForElement("add", "ADD button did not appear!", timeout: TimeSpan.FromSeconds(10));
  966. app.Tap("add");
  967. app.WaitForElement("Subject_Entry", "Subject_Entry is required but not marked with a red star!", timeout: TimeSpan.FromSeconds(10));
  968.  
  969. string jSONWithFields = (string)Invoke("GetInfoAboutFields");
  970. JsonStructureForTestOnly jSonStructure = JsonConvert.DeserializeObject<JsonStructureForTestOnly>(jSONWithFields);
  971.  
  972. List<string> visibleFieldNames = new List<string>();
  973. List<string> invisibleFieldNames = new List<string>();
  974. List<string> requiredFieldNames = new List<string>();
  975.  
  976. foreach (var field in jSonStructure.fields)
  977. {
  978. string fieldName = field.name;
  979. string isFieldVisible = field.visible;
  980. string isFieldRequired = field.required;
  981.  
  982. if (0 == String.Compare(checkVisibleOrRequired, "visible")) //if we are checking for visible fields
  983. {
  984. if (0 == String.Compare(isFieldVisible, "true"))
  985. {
  986. if (0 == String.Compare(isFieldRequired, "true"))
  987. {
  988. app.WaitForElement(c => c.All().Marked(fieldName + "*"), fieldName + " field is invisible but it was supposed to be visible!", timeout: TimeSpan.FromSeconds(10));
  989. }
  990. else
  991. {
  992. app.WaitForElement(c => c.All().Marked(fieldName), fieldName + " field is invisible but it was supposed to be visible!", timeout: TimeSpan.FromSeconds(10));
  993. }
  994.  
  995. string entryName = fieldName.Replace(" ", string.Empty) + "_Entry";
  996. app.WaitForElement(c => c.All().Marked(entryName), entryName + " field is invisible but it was supposed to be visible!", timeout: TimeSpan.FromSeconds(10));
  997.  
  998. visibleFieldNames.Add(fieldName);
  999. }
  1000. else
  1001. {
  1002. if (0 == String.Compare(isFieldRequired, "true"))
  1003. {
  1004. app.WaitForNoElement(c => c.All().Marked(fieldName + "*"), fieldName + " field is visible but it was supposed to be invisible!", timeout: TimeSpan.FromSeconds(10));
  1005. }
  1006. else
  1007. {
  1008. app.WaitForNoElement(c => c.All().Marked(fieldName), fieldName + " field is visible but it was supposed to be invisible!", timeout: TimeSpan.FromSeconds(10));
  1009. }
  1010.  
  1011. string entryName = fieldName.Replace(" ", string.Empty) + "_Entry";
  1012. app.WaitForNoElement(c => c.All().Marked(entryName), entryName + " field is visible but it was supposed to be invisible!", timeout: TimeSpan.FromSeconds(10));
  1013.  
  1014. invisibleFieldNames.Add(fieldName);
  1015. }
  1016. }
  1017. else if (0 == String.Compare(checkVisibleOrRequired, "required")) //if we are checking for required fields
  1018. {
  1019. if (0 == String.Compare(isFieldRequired, "true"))
  1020. {
  1021. app.WaitForElement(c => c.All().Marked(fieldName + "*"), fieldName + " field is required but not marked with a red star!", timeout: TimeSpan.FromSeconds(10));
  1022. requiredFieldNames.Add(fieldName);
  1023. }
  1024. else
  1025. {
  1026. app.WaitForNoElement(c => c.All().Marked(fieldName + "*"), fieldName + " field is not required but it's with a red star!", timeout: TimeSpan.FromSeconds(10));
  1027. }
  1028. }
  1029. }
  1030.  
  1031. if (0 == String.Compare(checkVisibleOrRequired, "visible"))
  1032. takeScreenshot("Given that I'm on the New Document screen, then I shall see following fields: '" + String.Join(",", visibleFieldNames) + "', and: '" + String.Join(",", invisibleFieldNames) + "' fields shall not be displayed");
  1033. else if (0 == String.Compare(checkVisibleOrRequired, "required"))
  1034. takeScreenshot("Given that I'm on the New Document screen, then I should see that all the required fields i.e: " + String.Join(",", requiredFieldNames) + "are marked with a red star");
  1035. }
  1036.  
  1037. public class OneFieldForTestOnly
  1038. {
  1039. public string name { get; set; }
  1040. public string visible { get; set; }
  1041. public string required { get; set; }
  1042. }
  1043. public class JsonStructureForTestOnly
  1044. {
  1045. public List<OneFieldForTestOnly> fields { get; set; }
  1046. }
  1047.  
  1048. private List<string> getListOfRequiredFields()
  1049. {
  1050.  
  1051. string jSONWithFields = (string)Invoke("GetInfoAboutFields");
  1052.  
  1053. JsonStructureForTestOnly jSonStructure = JsonConvert.DeserializeObject<JsonStructureForTestOnly>(jSONWithFields);
  1054.  
  1055. List<string> requiredFieldNames = new List<string>();
  1056.  
  1057. foreach (var field in jSonStructure.fields)
  1058. {
  1059. string fieldName = field.name;
  1060. string isFieldRequired = field.required;
  1061.  
  1062. if (0 == String.Compare(isFieldRequired, "true"))
  1063. {
  1064. requiredFieldNames.Add(fieldName);
  1065. }
  1066. }
  1067. return requiredFieldNames;
  1068. }
  1069.  
  1070. private List<string> getListOfAllVisibleFields()
  1071. {
  1072. string jSONWithFields = (string)Invoke("GetInfoAboutFields");
  1073. JsonStructureForTestOnly jSonStructure = JsonConvert.DeserializeObject<JsonStructureForTestOnly>(jSONWithFields);
  1074.  
  1075. List<string> visibleFieldNames = new List<string>();
  1076.  
  1077. foreach (var field in jSonStructure.fields)
  1078. {
  1079. string fieldName = field.name;
  1080. string isFieldVisible = field.visible;
  1081.  
  1082. if (0 == String.Compare(isFieldVisible, "true"))
  1083. {
  1084. visibleFieldNames.Add(fieldName);
  1085. }
  1086. }
  1087. return visibleFieldNames;
  1088. }
  1089.  
  1090.  
  1091. }
  1092. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement