Guest User

Untitled

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