Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using AutomatedDevTests.Contracts;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Support.PageObjects;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SeleniumStuff
- {
- public class SvealanetInterraction : PageObject
- {
- SvealanetWebElementModel webElement = new SvealanetWebElementModel();
- public SvealanetInterraction(string path, string browser) : base(path, browser)
- {
- }
- public override string SendRequest(IHttpRequestParameters data)
- {
- LogIn();
- var response = BuildRequest((InsertApplicationModel)data);
- return response;
- }
- public void LogIn()
- {
- webElement.txtUsername = driver.FindElement(By.Id("user_login"));
- webElement.txtUsername.SendKeys("diana");
- webElement.txtPassword = driver.FindElement(By.Id("user_pass"));
- webElement.txtPassword.SendKeys("Svea123");
- webElement.btnLogIn = driver.FindElement(By.Id("wp-submit"));
- webElement.btnLogIn.Click();
- }
- public string BuildRequest(InsertApplicationModel loan)
- {
- bool hasCoborrower = (loan.coBorrowerY == "checked");
- string response = string.Empty;
- response = FillBorrowerData(loan);
- if (!string.IsNullOrEmpty(response))
- return response;
- if (hasCoborrower)
- {
- response = FillCoBorrowerData(loan);
- }
- return response;
- }
- public string FillBorrowerData(InsertApplicationModel borrower)
- {
- string norwegianCitizenshipXPath = (borrower.norwegianCitizenshipY == "checked") ? "//*[@id='statsborger1Ja']" : "//*[@id='statsborger1Nei']";
- string sameAddressXPath = (borrower.sameAddressY == "checked") ? "//*[@id='OtherAddress1Ja']" : "//*[@id='OtherAddress1Nei']";
- bool hasChildSupport = (borrower.childSupport != string.Empty);
- bool hasRentalIncome = (borrower.rentalIncomeTaxFree != string.Empty);
- bool hasOtherIncome = (borrower.otherIncomesSources != string.Empty) || (borrower.otherIncomesValues != string.Empty);
- bool hasMortgageLoan = (borrower.mortgage != string.Empty) || (borrower.monthlyMortgage != string.Empty);
- bool hasStudentLoan = (borrower.studentLoan != string.Empty) || (borrower.monthlyStudent != string.Empty);
- bool hasCarLoan = (borrower.carLoan != string.Empty) || (borrower.monthlyCar != string.Empty);
- bool hasOtherLoan = (borrower.olValues != string.Empty) || (borrower.olMonthly != string.Empty);
- string response = string.Empty;
- webElement.drpdnLoanType = driver.FindElement(By.Id("menu-item-427"));
- webElement.drpdnLoanType.Click();
- webElement.optnDefaultLoanType = driver.FindElement(By.Id("menu-item-243"));
- webElement.optnDefaultLoanType.Click();
- webElement.txtPersonalId = driver.FindElement(By.Id("fodselsnummer"));
- webElement.txtPersonalId.SendKeys(borrower.personalID);
- webElement.txtMobilePhone = driver.FindElement(By.Id("mobil"));
- webElement.txtMobilePhone.SendKeys(borrower.mobilePhone);
- webElement.txtEmail = driver.FindElement(By.Id("epost"));
- webElement.txtEmail.SendKeys(borrower.email);
- webElement.btnNextStep = driver.FindElement(By.Id("nextStep"));
- webElement.btnNextStep.Click();
- if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
- {
- response = "Fødselsnummer er ugyldig";
- return response;
- }
- webElement.chkNorwegianCitizenship = driver.FindElement(By.Id(norwegianCitizenshipXPath));
- webElement.chkNorwegianCitizenship.Click();
- webElement.chkSameAddress = driver.FindElement(By.Id(sameAddressXPath));
- webElement.chkSameAddress.Click();
- webElement.txtMaritalStatus = driver.FindElement(By.Id("civil_state"));
- webElement.txtMaritalStatus.SendKeys(borrower.maritalStatus);
- webElement.txtChidrenUnder18 = driver.FindElement(By.Id("antall"));
- webElement.txtChidrenUnder18.SendKeys(borrower.childrenUnder18);
- webElement.txtLivingCondition = driver.FindElement(By.Id("accommodation"));
- webElement.txtLivingCondition.SendKeys(borrower.livingCondition);
- webElement.txtSharedCosts = driver.FindElement(By.Id("bokostnad"));
- webElement.txtSharedCosts.SendKeys(borrower.monthlyRent);
- webElement.txtLiveSinceMonth = driver.FindElement(By.Id("accommodationMonth"));
- webElement.txtLiveSinceMonth.SendKeys("");
- webElement.txtLiveSinceYear = driver.FindElement(By.Id("accommodationYear"));
- webElement.txtLiveSinceYear.SendKeys("");
- webElement.btnNextStep = driver.FindElement(By.Id("nextStep"));
- webElement.btnNextStep.Click();
- if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
- {
- response = "Fødselsnummer er ugyldig";
- return response;
- }
- webElement.txtWorkingCondition = driver.FindElement(By.Id("occupation"));
- webElement.txtWorkingCondition.SendKeys(borrower.workingStatus);
- webElement.txtWorkingConditionSinceMonth = driver.FindElement(By.Id("occupationMonth"));
- webElement.txtWorkingConditionSinceMonth.SendKeys(borrower.workingStatusSinceMonth);
- webElement.txtWorkingConditionSinceYear = driver.FindElement(By.Id("occupationYear"));
- webElement.txtWorkingConditionSinceYear.SendKeys(borrower.workingStatusSinceYear);
- webElement.txtAnnualIncomeBeforeTaxes = driver.FindElement(By.Id("annualIncome"));
- webElement.txtAnnualIncomeBeforeTaxes.SendKeys("");
- webElement.txtMonthlyIncomeAfterTaxes = driver.FindElement(By.Id("monthlyIncome"));
- webElement.txtMonthlyIncomeAfterTaxes.SendKeys("");
- webElement.txtSamborAnnualIncomeBeforeTaxes = driver.FindElement(By.Id("cohabitantIncome"));
- webElement.txtSamborAnnualIncomeBeforeTaxes.SendKeys("");
- if (hasChildSupport)
- {
- webElement.chkChildSupport = driver.FindElement(By.Id("childSupportJa"));
- webElement.chkChildSupport.Click();
- webElement.txtChildSupport = driver.FindElement(By.Id("childSupportValue"));
- webElement.txtChildSupport.SendKeys("");
- }
- if (hasRentalIncome)
- {
- webElement.chkRentalIncome = driver.FindElement(By.Id("rentIncomeJa"));
- webElement.chkRentalIncome.Click();
- webElement.txtRentalIncome = driver.FindElement(By.Id("rentPrice"));
- webElement.txtRentalIncome.SendKeys("");
- }
- if (hasOtherIncome)
- {
- webElement.chkOtherIncome = driver.FindElement(By.Id("otherIncomeJa"));
- webElement.chkOtherIncome.Click();
- webElement.txtOtherIncomeSource = driver.FindElement(By.Id("formStep"));
- webElement.txtOtherIncomeSource.SendKeys("");
- webElement.txtOtherIncomeValue = driver.FindElement(By.Id("formStep"));
- webElement.txtOtherIncomeValue.SendKeys("");
- }
- webElement.btnNextStep3 = driver.FindElement(By.Id("nextStep"));
- webElement.btnNextStep3.Click();
- if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
- {
- response = "Fødselsnummer er ugyldig";
- return response;
- }
- if (hasMortgageLoan)
- {
- webElement.chkMortgageLoan = driver.FindElement(By.Id("mortgageJa"));
- webElement.chkMortgageLoan.Click();
- webElement.txtRemainingMortgageLoan = driver.FindElement(By.Id("mortgageRemaining"));
- webElement.txtRemainingMortgageLoan.SendKeys("");
- webElement.txtMonthlyMortgageLoan = driver.FindElement(By.Id("mortgageRemaining"));
- webElement.txtMonthlyMortgageLoan.SendKeys("");
- }
- if (hasStudentLoan)
- {
- webElement.chkStudentLoan = driver.FindElement(By.Id("studentLoanJa"));
- webElement.chkStudentLoan.Click();
- webElement.txtRemainingStudentLoan = driver.FindElement(By.Id("studentLoanRemaining"));
- webElement.txtRemainingStudentLoan.SendKeys("");
- webElement.txtMonthlyStudentLoan = driver.FindElement(By.Id("studentLoanCost"));
- webElement.txtMonthlyStudentLoan.SendKeys("");
- }
- if (hasCarLoan)
- {
- webElement.chkCarLoan = driver.FindElement(By.Id("carLoanJa"));
- webElement.chkCarLoan.Click();
- webElement.txtRemainingCarLoan = driver.FindElement(By.Id("carLoanRemaining"));
- webElement.txtRemainingCarLoan.SendKeys("");
- webElement.txtMonthlyCarLoan = driver.FindElement(By.Id("carLoanCost"));
- webElement.txtMonthlyCarLoan.SendKeys("");
- }
- if (hasOtherLoan)
- {
- webElement.chkOtherLoan = driver.FindElement(By.Id("consumerLoanJa"));
- webElement.chkOtherLoan.Click();
- webElement.txtRemainingOtherLoan = driver.FindElement(By.Id("consumerLoanRemaining"));
- webElement.txtRemainingOtherLoan.SendKeys("");
- webElement.txtMonthlyOtherLoan = driver.FindElement(By.Id("consumerLoanCost"));
- webElement.txtMonthlyOtherLoan.SendKeys("");
- }
- webElement.btnNextStep4 = driver.FindElement(By.Id("nextStep"));
- webElement.btnNextStep4.Click();
- if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
- {
- response = "Fødselsnummer er ugyldig";
- return response;
- }
- return response;
- }
- public string FillCoBorrowerData(InsertApplicationModel coBorrower)
- {
- string response = string.Empty;
- webElement.chkCoborrower = driver.FindElement(By.Id("coborrowerJa"));
- webElement.chkCoborrower.Click();
- webElement.btnNextStep5 = driver.FindElement(By.Id("nextStep"));
- webElement.btnNextStep5.Click();
- if (driver.PageSource.Contains("Fødselsnummer er ugyldig"))
- response = "Fødselsnummer er ugyldig";
- return response;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement