EnVisageOnline/Main/TestSystem/Prevu/Selenium/PeopleResourcePage.cs

153 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using System.Collections;
namespace Prevu
{
public class PeopleResourcePage : BasePage
{
By btnPrimary = By.ClassName("btn-primary");
By txtFirstName = By.Id("FirstName");
By txtLastName = By.Id("LastName");
By txtEmployeeID = By.Id("EmployeeID");
By txtEmailAddress = By.Id("EmailAddress");
By drdExpenditureCategory = By.Id("ExpenditureCategoryId");
By drdTeam = By.Id("TeamId");
By drdWorkWeek = By.Id("WorkWeekId");
By chbIsActiveEmployee = By.Id("IsActiveEmployee");
By chbChangeCapacity = By.Id("ChangeCapacity");
By chbPermanent = By.Id("PermanentResource");
By dtpStartDate = By.Id("StartDate");
By dtpEndDate = By.Id("EndDate");
By btnSave = By.Id("btnsave-peopleresource");
//By select = By.ClassName("select2-choice");
By lblWarning = By.ClassName("panel-body");
By btnDelete = By.Id("btnDelete");
By tblteamResources = By.ClassName("resourceTable");
By formEditPeopleResource = By.Id("editPeopleResourceForm");
WebDriver _driver;
public PeopleResourcePage(WebDriver driver)
{
_driver = driver;
}
public bool OpenPeopleResourceDetails(string resourceId)
{
_driver.OpenPage(string.Format("PeopleResource/Details?resourceId={0}", resourceId));
_driver.WaitElement(txtFirstName);
return _driver.GetElement(txtFirstName) != null;
}
public bool CheckPeopleResource(string resourceId, string firstName, string lastName, string employeeID, string emailAddress, string expenditureCategory, string team, string workWeek, bool employeeStatusIsActive, bool changePlannedCapacity, bool permanent, DateTime startDate, DateTime endDate)
{
OpenPeopleResourceDetails(resourceId);
if ((!string.IsNullOrEmpty(firstName)) && (!string.IsNullOrEmpty(lastName)))
{
return (_driver.GetElement(txtFirstName).GetAttribute("value") == firstName) &&
(_driver.GetElement(txtLastName).GetAttribute("value") == lastName); //TODO
} else
{
return true;
}
}
public bool EditPeopleResource(string resourceId, string firstName, string lastName, string employeeID, string emailAddress, string expenditureCategory, string team, string workWeek, bool employeeStatusIsActive, bool changePlannedCapacity, bool permanent, DateTime startDate, DateTime endDate)
{
OpenPeopleResourceDetails(resourceId);
_driver.ClickElement(btnPrimary, "Edit");
_driver.WaitElement(formEditPeopleResource);
IWebElement form = _driver.GetElement(formEditPeopleResource);
if (!string.IsNullOrEmpty(firstName))
{
_driver.SendKeys(form, txtFirstName, firstName);
}
if (!string.IsNullOrEmpty(lastName))
{
_driver.SendKeys(form, txtLastName, lastName);
}
if (!string.IsNullOrEmpty(employeeID))
{
_driver.SendKeys(form, txtEmployeeID, employeeID);
}
if (!string.IsNullOrEmpty(emailAddress))
{
_driver.SendKeys(form, txtEmailAddress, emailAddress);
}
if (!string.IsNullOrEmpty(team))
{
_driver.SelectDropdownValue(form, drdTeam, team);
}
if (!string.IsNullOrEmpty(workWeek))
{
_driver.SelectDropdownValue(form, drdWorkWeek, workWeek);
}
if (!employeeStatusIsActive)
{
_driver.ClickElement(form, chbIsActiveEmployee);
}
if (!changePlannedCapacity)
{
_driver.ClickElement(form, chbChangeCapacity);
}
if (permanent)
{
_driver.ClickElement(form, chbPermanent);
}
_driver.SendKeys(form, dtpStartDate, string.Format("{0}/{1}/{2}", startDate.Month, startDate.Day, startDate.Year));
_driver.SendKeys(form, dtpEndDate, string.Format("{0}/{1}/{2}", endDate.Month, endDate.Day, endDate.Year));
_driver.ClickElement(form, btnSave);
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
_driver.WaitAjax();
return CheckPeopleResource(resourceId, firstName, lastName, employeeID, emailAddress, expenditureCategory, team, workWeek, employeeStatusIsActive, changePlannedCapacity, permanent, startDate, endDate);
}
/*
public bool DeleteCompany(string companyId, string companyName)
{
_driver.OpenPage(string.Format("Company/Delete/{0}", companyId));
bool result = _driver.GetElement(lblWarning).Text.IndexOf("Are you sure you want to delete it?") > -1;
_driver.ClickElement(btnDelete);
string id = "";
_driver.FindRecord("Company", companyName, out id, 2);
return result && (id == "");
}
public bool FindCompany(string name, out string id)
{
return _driver.FindRecord("Company", name, out id);
}
private bool SetClients(string[] clients)
{
return _driver.SetCheckboxList("Clients", clients); ;
}
private bool CheckClients(string[] clients)
{
//TODO
return true;
}
private bool SetViews(string[] views)
{
return _driver.SetCheckboxList("Views", views); ;
}
private bool CheckViews(string[] views)
{
//TODO
return true;
}
*/
}
}