We are
using the concept of Page Object Model, where we will have a Page class for
every page in the application and action class to perform action on that
particular page class and a Test class which in turn will merge those actions
and execute as single Test.
Page Class
– For every web page in our application we will have an individual Page class,
which will store all the WebElement’s of that particular page.
Action
Class – For Every Page class created we will have Action class, which will have
methods to perform action on the WebElement’s that are stored in Page class.
Test Class
– For Every Page class and Action class we will again have a single Test class,
which will merge all the action methods in Action class and let us execute as
single Test.
Scenario Automated Below
- Open Chrome Browser
- Enter URL to login to Rediffmail
- Enter Username and Password
- Click Login Button
- Close the Opened Browser.
Complete Source Code
Page Class
LoginPage.cs
using
OpenQA.Selenium;
using
OpenQA.Selenium.Support;
using
OpenQA.Selenium.Support.PageObjects;
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
using
System.Threading.Tasks;
using Protractor;
namespace
Purush_Framework
{
class LoginPage:Base
{
public LoginPage()
{
}
public static IWebElement Usernametxt
{
get
{
return driver.FindElement(By.Id("login1"));
}
}
public static IWebElement
Passwordtxt
{
get
{
return
driver.FindElement(By.Id("password"));
}
}
public static IWebElement Loginbtn
{
get
{
return driver.FindElement(By.Name("proceed"));
}
}
}
}
Action Class
LoginAction.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Purush_Framework
{
using System.Threading;
class LoginAction
{
public LoginAction EnterUsernameTxt()
{
LoginPage.Usernametxt.SendKeys("Purush@rediffmail.com");
return new LoginAction();
}
public LoginAction EnterPasswordTxt()
{
LoginPage.Passwordtxt.SendKeys("123");
return new LoginAction();
}
public LoginAction ClickLoginBtn()
{
LoginPage.Loginbtn.Click();
return this;
}
}
}
Test Class
LoginTest.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
namespace Purush_Framework
{
class LoginTest
{
LoginAction LoginObj = new LoginAction();
public void Login()
{
LoginObj.EnterUsernameTxt() // Fluency Method Concept is used
.EnterPasswordTxt()
.ClickLoginBtn();
}
public void
EndTest()
{
Base.driver.Quit();
}
}
}
Base Class
Base.cs
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Protractor;
namespace Purush_Framework
{
public class Base
{
public static IWebDriver driver = new ChromeDriver();
public Base()
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://mail.rediff.com/cgi-bin/login.cgi");
}
}
}
0 comments: