There are tons of information on Selenium but then I’ve got OCD and I won’t feel complete if I don’t touch a little on selenium, but as usual I will only focus on what we will need on our journey of developing a UI automation framework from scratch.

Well, Selenium is not just one tool, rather it consists of several tools/libraries, which we can use for our automation testing purposes. The part of selenium we will be concerned about is Selenium Webdriver and maybe Selenium grid later on (Another fun tool to play with).

Agenda:

  • Why Selenium Webdriver?
  • The PageFactory
  • IWebdriver and IWebelement Interface.
  • Links
  • Tools

Pre-requisite/ Tools:

  • General Knowledge of selenium webdriver

Why Selenium WebDriver?

 

Why I will choose Selenium as an automation tool.

  • Selenium works on most major desktop OS, Linux, Mac OS, Windows etc
  • Selenium is open source with huge community and I like free stuff
  • Selenium supports multiple languages C#, Java, python, PHP, Ruby, Pearl etc
  • Drivers are available for selenium to Automate different browsers. What this means is a Single Script and code base should (theoretically) just run on any browser.
  • Combined with Another tool (Appium), we can Automate mobile Hybrid and Native apps on IOS and Android with only a bit more learning curve.

https://github.com/SeleniumHQ/selenium/wiki/PageFactory

The PageFactory Class

One of Selenium Webdriver support library is the PageFactory Class. This class will aid in following the Page Object pattern. It takes in the webdriver instance, and it will automatically use it to search for an element on a page that matches the attribute we supply it. Ofcourse we could use selenium webdriver without this, but we will not re-invent the wheel, but rather leverage this class and focus on the framework development.

With PageFactory, most of the time we do not have to worry about nullReferenceException as we can assume the fields we declare are initialized.

IWebdriver and IWebelement Interface

It is a good idea to familiarize yourself with these two interfaces and goodies they provide.

Through the IWebdriver Interface we can control the browser, and instantiate ‘ANY’ Browser that implements the IWebdriver interface. I say any as this is where the true power of selenium comes into play. It means we can just plug in ChromeDriver, FirefoxDriver, Edge, IE Classes/Types because they all implement this interface (Directly/Indirectly).

In our framework, we will instantiate our browser for example as follows;

IWebdriver driver = new ChromeDriver(); instead of using concrete class

Chromedriver driver = new ChromeDriver();

Because then we can plug in any of the other browsers in place of ChromeDriver() directly (if we haven’t done anything fancy like taking screenshot etc.)

Methods and Properties provided for Browser control and information includes:

Through the IWebelement Interface we can interact with DOM elements, as it provides the following Methods and properties. Selenium uses tags to know what operation is executable on which DOM element. This means Clear() method for example can work on a text input, but not on a button etc.

These are the most common things we will programmatically use to automate User actions. Another invaluable Class part of the support classes is the WebDriverWait(). Primarily, we will use it to prevent NoSuchElementException as a result of a slow loading page not displaying a DOM element quick enough. If you want to have a look at what you have at your disposal, In your solution explorer from our framework project, under the .Web project, expand the References, right click on either WebDriver/ WebDriver.Support and select View in Object Browser.

Then you can browse through the list of all the namespaces and classes.

To read more about Selenium visit: http://www.seleniumhq.org.

Next we will start capturing pageObjects and Write functions to Smoke test our AUT. Don’t miss it Click here to be the first to know when it is published.

Any thoughts, questions, comments, addition, or anything you don’t like, do not hesitate to leave a comment or contact me. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Show Buttons
Hide Buttons