Advertisement
Guest User

Untitled

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