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

71 lines
2.7 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;
namespace Prevu
{
public class GLAccountsPage : BasePage
{
By btnPrimary = By.ClassName("btn-primary");
By txtGLName = By.Id("Name");
By txtGLNumber = By.Id("GLNumber");
By btnSave = By.Id("btnsave");
By lblWarning = By.ClassName("panel-body");
By btnDelete = By.Id("btnDelete");
WebDriver _driver;
public GLAccountsPage(WebDriver driver)
{
_driver = driver;
}
public bool OpenGLAccounts()
{
_driver.OpenPage("GLAccount");
_driver.WaitElement(btnPrimary);
return _driver.GetElement(btnPrimary, "Add GL Account") != null;
}
public bool CreateGLAccount(string glAccountName, string glAccountNumber, out string id)
{
_driver.ClickElement(btnPrimary, "Add GL Account");
_driver.SendKeys(txtGLName, glAccountName);
_driver.SendKeys(txtGLNumber, glAccountNumber);
_driver.ClickElement(btnSave);
id = "";
return _driver.FindRecord("GLAccount", glAccountName, out id);
}
public bool CheckGLAccount(string id, string glAccountName, string glAccountNumber)
{
_driver.OpenPage(string.Format("GLAccount/Edit/{0}", id));
return (_driver.GetElement(txtGLName).GetAttribute("value") == glAccountName) &&
(_driver.GetElement(txtGLNumber).GetAttribute("value") == glAccountNumber);
}
public bool DeleteGLAccount(string userId, string userName)
{
_driver.OpenPage(string.Format("GLAccount/Delete/{0}", userId));
bool result = _driver.GetElement(lblWarning).Text.IndexOf(string.Format("You are about to delete the {0}. Are you sure you want to delete it?", userName)) > -1;
_driver.ClickElement(btnDelete);
string id = "";
_driver.FindRecord("GLAccount", userName, out id);
return result && (id == "");
}
public bool EditGLAccount(string id, string glAccountName, string glAccountNumber)
{
_driver.OpenPage(string.Format("GLAccount/Edit/{0}", id));
_driver.SendKeys(txtGLName, glAccountName);
_driver.SendKeys(txtGLNumber, glAccountNumber);
_driver.ClickElement(btnSave);
return CheckGLAccount(id, glAccountName, glAccountNumber);
}
public bool FindGLAccount(string name, out string id)
{
return _driver.FindRecord("GLAccount", name, out id);
}
}
}