I have recently started to create my first Selenium Framework to help test the product at my work. I have managed to implement the first three pages and would like some feedback on and selenium or C# practices I can improve on.
Loading the website takes you to the login page. Once the user logs in, they are take to the DashboardPage. All the fields we care about on the page is the navigation bar. Clicking on StartNewQuote button takes the user to the clientDetailsOne Page.
I have a lot more pages to do so I would like to know if I am doing anything wrong or cant improve my practices sooner rather than later.
I also plan on implementing Cucumber, Gherkin, and Specflow in the future to make I more business readable.
TestMethod:
[TestMethod]
public void Test()
{
NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
var loginPage = new LoginPage();
loginPage.User_Login_As(ObjectRepository.Config.GetUsername(), ObjectRepository.Config.GetPassword());
var dashboardPage = new DashboardPage();
dashboardPage.GoToClientDetailsOnePage();
var clientDetailsOnePage = new ClientDetailsOnePage();
clientDetailsOnePage.TitleTextBox("Mr");
clientDetailsOnePage.FirstNameTextBox("John");
clientDetailsOnePage.NameTextBox("Smith");
clientDetailsOnePage.DesignatedAuthorityTextBox("None");
clientDetailsOnePage.UKResidentCheckBox();
clientDetailsOnePage.NextButton();
Thread.Sleep(5000);
}
LoginPage.cs:
using OpenQA.Selenium;
using TestAutomationFrameworkPOMS.Settings;
using OpenQA.Selenium.Support.PageObjects;
namespace TestAutomationFrameworkPOMS.PageObject.ContactCentre
{
public class LoginPage
{
public LoginPage()
{
PageFactory.InitElements(ObjectRepository.Driver, this);
}
[FindsBy(How = How.Id, Using = "username-inputEl")]
private IWebElement Username;
[FindsBy(How = How.Id, Using = "password-inputEl")]
private IWebElement Password;
[FindsBy(How = How.Id, Using = "remember-displayEl")]
private IWebElement RememberMe;
[FindsBy(How = How.LinkText, Using = "Login")]
private IWebElement Login;
public void User_Login_As(string username, string password)
{
Username.SendKeys(username);
Password.SendKeys(password);
RememberMe.Click();
Login.Click();
}
}
}
DashboardPage.cs:
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using TestAutomationFrameworkPOMS.Settings;
namespace TestAutomationFrameworkPOMS.PageObject.ContactCentre
{
public class DashboardPage
{
public DashboardPage()
{
PageFactory.InitElements(ObjectRepository.Driver, this);
}
#region Navigation
[FindsBy(How = How.Id, Using = "AgentPAS")]
private IWebElement NavigationPolicy;
[FindsBy(How = How.Id, Using = "Billing")]
private IWebElement NavigationBilling;
[FindsBy(How = How.Id, Using = "id_LogOut")]
private IWebElement NavigationLogout;
[FindsBy(How = How.Id, Using = "id_Home")]
private IWebElement NavigationDashboard;
[FindsBy(How = How.Id, Using = "id_Search")]
private IWebElement NavigationSearch;
[FindsBy(How = How.Id, Using = "id_New")]
private IWebElement NavigationStartNewQuote;
public void GoToPolicyExpress()
{
NavigationPolicy.Click();
}
public void GoToBillingExpress()
{
NavigationBilling.Click();
}
public void GoToLogoutButton()
{
NavigationLogout.Click();
}
public void GoToDashboardPage()
{
NavigationDashboard.Click();
}
public void GoToSearchPage()
{
NavigationSearch.Click();
}
public void GoToClientDetailsOnePage()
{
NavigationStartNewQuote.Click();
}
#endregion
}
}
ClientDetailsOnePage.cs:
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using TestAutomationFrameworkPOMS.ComponentHelper;
using TestAutomationFrameworkPOMS.Settings;
namespace TestAutomationFrameworkPOMS.PageObject.ContactCentre
{
public class ClientDetailsOnePage
{
#region InitiateElements
public ClientDetailsOnePage()
{
PageFactory.InitElements(ObjectRepository.Driver, this);
}
#endregion
#region WebElements
[FindsBy(How = How.XPath, Using = "//input[@fieldref='AccountInput.Title']")]
private IWebElement Title;
[FindsBy(How = How.XPath, Using = "//input[@fieldref='AccountInput.FirstName']")]
private IWebElement FirstName;
[FindsBy(How = How.XPath, Using = "//input[@fieldref='AccountInput.Name']")]
private IWebElement Name;
[FindsBy(How = How.XPath, Using = "//input[@fieldref='AccountInput.DesignatedAuthority']")]
private IWebElement DesignatedAuthority;
[FindsBy(How = How.XPath, Using = "//span[@data-ref='displayEl']")]
private IWebElement UKResident;
[FindsBy(How = How.LinkText, Using = "Save & Exit")]
private IWebElement SaveExit;
[FindsBy(How = How.LinkText, Using = "Next")]
private IWebElement Next;
#endregion
#region WebActions
public void TitleTextBox(string text)
{
Title.Clear();
Title.SendKeys(text);
Title.SendKeys(Keys.Enter);
}
public void FirstNameTextBox(string text)
{
FirstName.Clear();
FirstName.SendKeys(text);
FirstName.SendKeys(Keys.Enter);
}
public void NameTextBox(string text)
{
Name.Clear();
Name.SendKeys(text);
Name.SendKeys(Keys.Enter);
}
public void DesignatedAuthorityTextBox(string text)
{
DesignatedAuthority.Clear();
DesignatedAuthority.SendKeys(text);
DesignatedAuthority.SendKeys(Keys.Enter);
}
public void UKResidentCheckBox()
{
UKResident.Click();
}
public void SaveExitButton()
{
SaveExit.Click();
}
public void NextButton()
{
Next.Click();
}
#endregion
#region Navigation
[FindsBy(How = How.Id, Using = "AgentPAS")]
private IWebElement NavigationPolicy;
[FindsBy(How = How.Id, Using = "Billing")]
private IWebElement NavigationBilling;
[FindsBy(How = How.Id, Using = "id_LogOut")]
private IWebElement NavigationLogout;
[FindsBy(How = How.Id, Using = "id_Home")]
private IWebElement NavigationDashboard;
[FindsBy(How = How.Id, Using = "id_Search")]
private IWebElement NavigationSearch;
[FindsBy(How = How.Id, Using = "id_New")]
private IWebElement NavigationStartNewQuote;
public void GoToPolicyExpress()
{
NavigationPolicy.Click();
}
public void GoToBillingExpress()
{
NavigationBilling.Click();
}
public void GoToLogoutButton()
{
NavigationLogout.Click();
}
public void GoToDashboardPage()
{
NavigationDashboard.Click();
}
public void GoToSearchPage()
{
NavigationSearch.Click();
}
public void GoToClientDetailsOnePage()
{
NavigationStartNewQuote.Click();
}
#endregion
}
}