Design Selenium Framework with C# – Part 4

In this part lets look at creating the page objects in most generic way.

As discussed in the last post the selenium support of page object initiation is getting deprecated from next releases of the selenium. So lets create page objects in most generic format.

HomePage

In the above class, we are declaring the all const string or identification strings may be xpath or ids or css selectors as const strings.

And we are assuming that driver object is being sent to the class. We are creating class property as driver and assigning the sent driver while creating the page class object from test.  So the constructor of the page class takes one parameter driver, also if you look at it it take parameter type IWebDriver that means, any type of driver which implements IWebDriver is good enough, this will make class independent of the driver type.

HomePage2

In the above code we have created the web elements as properties of the class

And the actions as methods. We can create the elements in the methods as well. But to make differentiation between actions and elements, its good practice to keep the elements as properties.

I am not creating utility class as of now to keep the common methods in there, also there is no BasePage which has global objects of the application. We can very well do that, but for the simplicity , I have not added additional classes which makes it bit complex to understand the execution flow.

Similar to the above the class, we can create search results page and validation of the search results page in another class called GoogleSearchResults.

SearchResultsPage

And verification method for verifying the returned search result.

SearchResults2

Now that we have every thing ready we are good to create NUnit test and understand the execution flow. I will discuss it in next section.

Design Selenium Framework with C# – Part 5

 

 

Advertisement

One thought on “Design Selenium Framework with C# – Part 4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s