Advertisement
Guest User

Untitled

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