DWQA Ask QuestionCategory: SeleniumHow Inheitance and Page Factory work in c#. is it correct.
Akash asked 6 years ago

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using selenium_root.core;

namespace selenium_root
{
class UIEvents : LogAndReport
{
protected void click(IWebElement obj) { /*Definition Yet to be Written*/}
protected void sendKeys(IWebElement obj, string textToBeSet) { /*Definition Yet to be Written*/}
protected void selectList(IWebElement obj) { /*Definition Yet to be Written*/}
protected string getText(IWebElement obj) { /*Definition Yet to be Written*/ return “”; }
protected void getAttributeValue(IWebElement obj) { /*Definition Yet to be Written*/}
protected void rightMouseClick(IWebElement obj, int iX, int iY) { /*Definition Yet to be Written*/}
protected void moveMouse(IWebElement obj, int iX, int iY) { /*Definition Yet to be Written*/}
protected void dragAndDrop(IWebElement obj, int iX, int iY) { /*Definition Yet to be Written*/}
}
class UIControls
{
class UITable : UIEvents
{
public string getTableText(IWebElement obj)
{
return getText(obj);
}
public void getTableCellTextInRowAndClm(IWebElement obj, int iRow, int iClm)
{
//code to written
}
public void getTableRowWithCellTextAs(IWebElement obj) { /*Definition Yet to be Written*/ }
public List<IWebElement> getTableCellElementsInRowAndClm(IWebElement objTable, int iRow, int iClm) { return null; }
}
class UIList : UIEvents
{
public void selectListByValue(IWebElement obj, string sValue)
{
}
public void selectListByIndex(IWebElement obj, string sValue)
{
//code to written
}
public string getListText(IWebElement obj)
{
return getText(obj);
}
}
class UILink : UIEvents
{
public void clickLink(IWebElement obj)
{
click(obj);
}
}//end class
class UITextBox : UIEvents
{
public void clickTextBox(IWebElement obj)
{
click(obj);
}
public void setValueInTextBox(IWebElement obj, string textToBeSet)
{
sendKeys(obj, textToBeSet);
}
}//end class

}
}//end name space
 
//**********************************
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Support.PageObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using selenium_root.core;
namespace selenium_root.productName.pageObjects
{
class PO_Sample
{
//Declare Driver object
IWebDriver driver;
Init_UIMethods oUI = new Init_UIMethods();
//Declare Page properties
[FindsBy(How = How.XPath, Using = “<value>”)]
private IWebElement searchLink;
[FindsBy(How = How.XPath, Using = “<value>”)]
private IWebElement searchTextBox;
//Set driver object in constructor
public PO_Sample(IWebDriver driverArg)
{
this.driver = driverArg;
}
//Methods Getter and Setters
public void ClickSearchLink()
{
oUI.oUILink.clickLink(searchLink);
}

public void EnterTextBoxInSearchBox()
{
oUI.oUITextBox.setValueInTextBox(searchTextBox);
}

public void KW_SearchProduct(string prodToBeSearched)
{
ClickSearchLink();
EnterTextBoxInSearchBox();
}
}
}