Before you start: Read about Page object pattern. The Page Object Pattern wraps all elements, actions and validations happening on a page in one single object- Page Object.
Official:
- Page Objects and PageFactory on Selenuim Wiki.
- Page Object Design Pattern on Selenium official site.
Unofficial:
- Page Object Pattern
- Page Objects in Selenium 2.0
- Selenium 2/WebDriver Quick Tips: Page Object Navigation Strategies
- PageObject by Martin Fowler
Download and Install
- Download and install Visual Studio 2015 https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx (free version)
- Launch VS and create a new project: Unit test project
- Install Nuget package manager and navigate to it.
- From the Manage Nuget Packages -> search online for ‘Selenium’ ; Install Selenium WebDriver
First Lines of code
- Create an instance of a driver (*Only the FirefoxDriver can be created without parameters. For all other drivers you need to point the location where the specific driver is downloaded
IWebDriver driv1 = new CromeDriver(); (“C:\\pathtomyCromedriverbinaries”); - Write methods to locate elements on web-page( by id/xpath/css/linktext/tagname/name/class)
IWebElement element = driv1.FindElement(By.Id(“UniqueId“)); - Use a Chain of Locators in order to find a specific element.
IWebElement ToFind = this.driv1.FindElement(By.ClassName(“firstElementTable“)).FindElement(By.Id(“secondElement“)); - Iwebelemet methods and properties: