113 lines
4.3 KiB
C#
113 lines
4.3 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 WorkWeeksPage : BasePage
|
|
{
|
|
By btnPrimary = By.ClassName("btn-primary");
|
|
By txtClientNumber = By.Id("ClientNumber");
|
|
By txtClientName = By.Id("Name");
|
|
By drdGLAccount = By.Id("GLAccountId");
|
|
By btnSave = By.Id("btnsave");
|
|
By lblWarning = By.ClassName("panel-body");
|
|
By btnDelete = By.Id("btnDelete");
|
|
|
|
WebDriver _driver;
|
|
|
|
public WorkWeeksPage(WebDriver driver)
|
|
{
|
|
_driver = driver;
|
|
}
|
|
/*
|
|
public bool OpenClients()
|
|
{
|
|
_driver.OpenPage("Clients");
|
|
_driver.WaitElement(btnPrimary);
|
|
return _driver.GetElement(btnPrimary, "Add Client") != null;
|
|
}
|
|
public bool CreateClient(string clientNumber, string clientName, string glAccountName, string[] companies, out string id)
|
|
{
|
|
_driver.ClickElement(btnPrimary, "Add Client");
|
|
_driver.SendKeys(txtClientNumber, clientNumber);
|
|
_driver.SendKeys(txtClientName, clientName);
|
|
_driver.SelectDropdownValue(drdGLAccount, glAccountName);
|
|
SetCompanies(companies);
|
|
_driver.ClickElement(btnSave);
|
|
id = "";
|
|
return _driver.FindRecord("Clients", clientName, out id);
|
|
}
|
|
public bool CheckClient(string id, string clientNumber, string clientName, string glAccountName, string[] companies)
|
|
{
|
|
_driver.OpenPage(string.Format("Clients/Edit/{0}", id));
|
|
return (_driver.GetElement(txtClientNumber).GetAttribute("value") == clientNumber) &&
|
|
(_driver.GetElement(txtClientName).GetAttribute("value") == clientName) &&
|
|
(_driver.SelectedDropdownValue(drdGLAccount) == glAccountName);
|
|
}
|
|
public bool DeleteClient(string clientId, string clientName)
|
|
{
|
|
_driver.OpenPage(string.Format("Clients/Delete/{0}", clientId));
|
|
bool result = _driver.GetElement(lblWarning).Text.IndexOf(string.Format("You are about to delete the {0}. Are you sure you want to delete it?", clientName)) > -1;
|
|
_driver.ClickElement(btnDelete);
|
|
string id = "";
|
|
_driver.FindRecord("Clients", clientName, out id);
|
|
return result && (id == "");
|
|
}
|
|
public bool EditClient(string id, string clientNumber, string clientName, string glAccountName, string[] companies)
|
|
{
|
|
_driver.OpenPage(string.Format("Clients/Edit/{0}", id));
|
|
_driver.SendKeys(txtClientNumber, clientNumber);
|
|
_driver.SendKeys(txtClientName, clientName);
|
|
_driver.SelectDropdownValue(drdGLAccount, glAccountName);
|
|
SetCompanies(companies);
|
|
_driver.ClickElement(btnSave);
|
|
return CheckClient(id, clientNumber, clientName, glAccountName, companies);
|
|
}
|
|
public bool FindClient(string name, out string id)
|
|
{
|
|
return _driver.FindRecord("Clients", name, out id);
|
|
}
|
|
|
|
private bool SetCompanies(string[] companies)
|
|
{
|
|
bool someChecked = false;
|
|
if (companies.Length > 0)
|
|
{
|
|
string pageSource = _driver.Driver.PageSource;
|
|
IWebElement tableCompanies = _driver.GetElement(By.Id("uom"));
|
|
IList<IWebElement> rows = tableCompanies.FindElement(By.XPath("tbody")).FindElements(By.XPath("tr"));
|
|
int i = -1;
|
|
foreach (IWebElement row in rows)
|
|
{
|
|
i++;
|
|
if (i > 0)
|
|
{
|
|
IWebElement checkbox = row.FindElement(By.XPath("td")).FindElement(By.XPath("input"));
|
|
if (companies.Contains(row.Text))
|
|
{
|
|
checkbox.Click();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
someChecked = true;
|
|
}
|
|
return someChecked;
|
|
}
|
|
private bool CheckCompanies(string[] companies)
|
|
{
|
|
//TODO
|
|
return true;
|
|
}
|
|
*/
|
|
}
|
|
}
|