Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. using AutomatedDevTests.Contracts;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Support.PageObjects;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace SeleniumStuff
  11. {
  12. public class SvealanetInterraction : PageObject
  13. {
  14.  
  15. SvealanetWebElementModel webElement = new SvealanetWebElementModel();
  16.  
  17. public SvealanetInterraction(string path, string browser) : base(path, browser)
  18. {
  19. }
  20.  
  21. public override string SendRequest(IHttpRequestParameters data)
  22. {
  23. LogIn();
  24. var response = BuildRequest((InsertApplicationModel)data);
  25.  
  26. return response;
  27. }
  28.  
  29. public void LogIn()
  30. {
  31. webElement.txtUsername = driver.FindElement(By.Id("user_login"));
  32. webElement.txtUsername.SendKeys("diana");
  33. webElement.txtPassword = driver.FindElement(By.Id("user_pass"));
  34. webElement.txtPassword.SendKeys("Svea123");
  35. webElement.btnLogIn = driver.FindElement(By.Id("wp-submit"));
  36. webElement.btnLogIn.Click();
  37. }
  38.  
  39. public string BuildRequest(InsertApplicationModel loan)
  40. {
  41. bool hasCoborrower = (loan.coBorrowerY == "checked");
  42. string response = string.Empty;
  43.  
  44. response = FillBorrowerData(loan);
  45. if (!string.IsNullOrEmpty(response))
  46. return response;
  47.  
  48. if (hasCoborrower)
  49. {
  50. response = FillCoBorrowerData(loan);
  51. }
  52.  
  53. return response;
  54. }
  55.  
  56. public string FillBorrowerData(InsertApplicationModel borrower)
  57. {
  58. string norwegianCitizenshipXPath = (borrower.norwegianCitizenshipY == "checked") ? "//*[@id='statsborger1Ja']" : "//*[@id='statsborger1Nei']";
  59. string sameAddressXPath = (borrower.sameAddressY == "checked") ? "//*[@id='OtherAddress1Ja']" : "//*[@id='OtherAddress1Nei']";
  60. bool hasChildSupport = (borrower.childSupport != string.Empty);
  61. bool hasRentalIncome = (borrower.rentalIncomeTaxFree != string.Empty);
  62. bool hasOtherIncome = (borrower.otherIncomesSources != string.Empty) || (borrower.otherIncomesValues != string.Empty);
  63. bool hasMortgageLoan = (borrower.mortgage != string.Empty) || (borrower.monthlyMortgage != string.Empty);
  64. bool hasStudentLoan = (borrower.studentLoan != string.Empty) || (borrower.monthlyStudent != string.Empty);
  65. bool hasCarLoan = (borrower.carLoan != string.Empty) || (borrower.monthlyCar != string.Empty);
  66. bool hasOtherLoan = (borrower.olValues != string.Empty) || (borrower.olMonthly != string.Empty);
  67. string response = string.Empty;
  68.  
  69. webElement.drpdnLoanType = driver.FindElement(By.Id("menu-item-427"));
  70. webElement.drpdnLoanType.Click();
  71. webElement.optnDefaultLoanType = driver.FindElement(By.Id("menu-item-243"));
  72. webElement.optnDefaultLoanType.Click();
  73.  
  74. webElement.txtPersonalId = driver.FindElement(By.Id("fodselsnummer"));
  75. webElement.txtPersonalId.SendKeys(borrower.personalID);
  76. webElement.txtMobilePhone = driver.FindElement(By.Id("mobil"));
  77. webElement.txtMobilePhone.SendKeys(borrower.mobilePhone);
  78. webElement.txtEmail = driver.FindElement(By.Id("epost"));
  79. webElement.txtEmail.SendKeys(borrower.email);
  80. webElement.btnNextStep = driver.FindElement(By.Id("nextStep"));
  81. webElement.btnNextStep.Click();
  82.  
  83. if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
  84. {
  85. response = "Fødselsnummer er ugyldig";
  86. return response;
  87. }
  88.  
  89. webElement.chkNorwegianCitizenship = driver.FindElement(By.Id(norwegianCitizenshipXPath));
  90. webElement.chkNorwegianCitizenship.Click();
  91. webElement.chkSameAddress = driver.FindElement(By.Id(sameAddressXPath));
  92. webElement.chkSameAddress.Click();
  93. webElement.txtMaritalStatus = driver.FindElement(By.Id("civil_state"));
  94. webElement.txtMaritalStatus.SendKeys(borrower.maritalStatus);
  95. webElement.txtChidrenUnder18 = driver.FindElement(By.Id("antall"));
  96. webElement.txtChidrenUnder18.SendKeys(borrower.childrenUnder18);
  97. webElement.txtLivingCondition = driver.FindElement(By.Id("accommodation"));
  98. webElement.txtLivingCondition.SendKeys(borrower.livingCondition);
  99. webElement.txtSharedCosts = driver.FindElement(By.Id("bokostnad"));
  100. webElement.txtSharedCosts.SendKeys(borrower.monthlyRent);
  101. webElement.txtLiveSinceMonth = driver.FindElement(By.Id("accommodationMonth"));
  102. webElement.txtLiveSinceMonth.SendKeys("");
  103. webElement.txtLiveSinceYear = driver.FindElement(By.Id("accommodationYear"));
  104. webElement.txtLiveSinceYear.SendKeys("");
  105.  
  106. webElement.btnNextStep = driver.FindElement(By.Id("nextStep"));
  107. webElement.btnNextStep.Click();
  108.  
  109. if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
  110. {
  111. response = "Fødselsnummer er ugyldig";
  112. return response;
  113. }
  114.  
  115. webElement.txtWorkingCondition = driver.FindElement(By.Id("occupation"));
  116. webElement.txtWorkingCondition.SendKeys(borrower.workingStatus);
  117. webElement.txtWorkingConditionSinceMonth = driver.FindElement(By.Id("occupationMonth"));
  118. webElement.txtWorkingConditionSinceMonth.SendKeys(borrower.workingStatusSinceMonth);
  119. webElement.txtWorkingConditionSinceYear = driver.FindElement(By.Id("occupationYear"));
  120. webElement.txtWorkingConditionSinceYear.SendKeys(borrower.workingStatusSinceYear);
  121. webElement.txtAnnualIncomeBeforeTaxes = driver.FindElement(By.Id("annualIncome"));
  122. webElement.txtAnnualIncomeBeforeTaxes.SendKeys("");
  123. webElement.txtMonthlyIncomeAfterTaxes = driver.FindElement(By.Id("monthlyIncome"));
  124. webElement.txtMonthlyIncomeAfterTaxes.SendKeys("");
  125. webElement.txtSamborAnnualIncomeBeforeTaxes = driver.FindElement(By.Id("cohabitantIncome"));
  126. webElement.txtSamborAnnualIncomeBeforeTaxes.SendKeys("");
  127. if (hasChildSupport)
  128. {
  129. webElement.chkChildSupport = driver.FindElement(By.Id("childSupportJa"));
  130. webElement.chkChildSupport.Click();
  131. webElement.txtChildSupport = driver.FindElement(By.Id("childSupportValue"));
  132. webElement.txtChildSupport.SendKeys("");
  133. }
  134. if (hasRentalIncome)
  135. {
  136. webElement.chkRentalIncome = driver.FindElement(By.Id("rentIncomeJa"));
  137. webElement.chkRentalIncome.Click();
  138. webElement.txtRentalIncome = driver.FindElement(By.Id("rentPrice"));
  139. webElement.txtRentalIncome.SendKeys("");
  140. }
  141. if (hasOtherIncome)
  142. {
  143. webElement.chkOtherIncome = driver.FindElement(By.Id("otherIncomeJa"));
  144. webElement.chkOtherIncome.Click();
  145. webElement.txtOtherIncomeSource = driver.FindElement(By.Id("formStep"));
  146. webElement.txtOtherIncomeSource.SendKeys("");
  147. webElement.txtOtherIncomeValue = driver.FindElement(By.Id("formStep"));
  148. webElement.txtOtherIncomeValue.SendKeys("");
  149. }
  150.  
  151. webElement.btnNextStep3 = driver.FindElement(By.Id("nextStep"));
  152. webElement.btnNextStep3.Click();
  153.  
  154. if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
  155. {
  156. response = "Fødselsnummer er ugyldig";
  157. return response;
  158. }
  159.  
  160. if (hasMortgageLoan)
  161. {
  162. webElement.chkMortgageLoan = driver.FindElement(By.Id("mortgageJa"));
  163. webElement.chkMortgageLoan.Click();
  164. webElement.txtRemainingMortgageLoan = driver.FindElement(By.Id("mortgageRemaining"));
  165. webElement.txtRemainingMortgageLoan.SendKeys("");
  166. webElement.txtMonthlyMortgageLoan = driver.FindElement(By.Id("mortgageRemaining"));
  167. webElement.txtMonthlyMortgageLoan.SendKeys("");
  168. }
  169. if (hasStudentLoan)
  170. {
  171. webElement.chkStudentLoan = driver.FindElement(By.Id("studentLoanJa"));
  172. webElement.chkStudentLoan.Click();
  173. webElement.txtRemainingStudentLoan = driver.FindElement(By.Id("studentLoanRemaining"));
  174. webElement.txtRemainingStudentLoan.SendKeys("");
  175. webElement.txtMonthlyStudentLoan = driver.FindElement(By.Id("studentLoanCost"));
  176. webElement.txtMonthlyStudentLoan.SendKeys("");
  177. }
  178. if (hasCarLoan)
  179. {
  180. webElement.chkCarLoan = driver.FindElement(By.Id("carLoanJa"));
  181. webElement.chkCarLoan.Click();
  182. webElement.txtRemainingCarLoan = driver.FindElement(By.Id("carLoanRemaining"));
  183. webElement.txtRemainingCarLoan.SendKeys("");
  184. webElement.txtMonthlyCarLoan = driver.FindElement(By.Id("carLoanCost"));
  185. webElement.txtMonthlyCarLoan.SendKeys("");
  186. }
  187. if (hasOtherLoan)
  188. {
  189. webElement.chkOtherLoan = driver.FindElement(By.Id("consumerLoanJa"));
  190. webElement.chkOtherLoan.Click();
  191. webElement.txtRemainingOtherLoan = driver.FindElement(By.Id("consumerLoanRemaining"));
  192. webElement.txtRemainingOtherLoan.SendKeys("");
  193. webElement.txtMonthlyOtherLoan = driver.FindElement(By.Id("consumerLoanCost"));
  194. webElement.txtMonthlyOtherLoan.SendKeys("");
  195. }
  196.  
  197. webElement.btnNextStep4 = driver.FindElement(By.Id("nextStep"));
  198. webElement.btnNextStep4.Click();
  199.  
  200. if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
  201. {
  202. response = "Fødselsnummer er ugyldig";
  203. return response;
  204. }
  205.  
  206. return response;
  207. }
  208.  
  209. public string FillCoBorrowerData(InsertApplicationModel coBorrower)
  210. {
  211. string response = string.Empty;
  212.  
  213. webElement.chkCoborrower = driver.FindElement(By.Id("coborrowerJa"));
  214. webElement.chkCoborrower.Click();
  215.  
  216. webElement.btnNextStep5 = driver.FindElement(By.Id("nextStep"));
  217. webElement.btnNextStep5.Click();
  218.  
  219. if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
  220. response = "Fødselsnummer er ugyldig";
  221.  
  222. return response;
  223. }
  224.  
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement