Selenium 29
Selenium 29
---------------------------------------------------------------
> Page Object Model is an Object / Element design pattern to create Repositories
for web elements
(Ex: Link, Edit box, Button etc�)
> Under this model container classes for web elements are created that behave as
object repositories
Under this POM, for each web page there should be corresponding Page Class�
This Page class will find the web elements of the web page and also contains
customized methods which
perform operations on those web elements.
In this approach all pages/elements of the application and user actions on those
web elements are
maintained as methods inside class file/s, by importing the page class/s we can
create test cases
----------------------------------------------------------------------------
Create Page Class/es by providing Elements information, they act as Object
Repositories
Create Test Cases (Classes) by importing the page classes
}
---------------------------------------------------
Create Test Case Class:
if (url.contains("http://www.gcrit.com/build3/admin/index.php")) {
System.out.println("Admin Login is Successful - Passed");
}
else {
System.out.println("Admin Login is Unsuccessful - Failed");
}
}
}
-------------------------------------------------------------------------
2) Create a Page Class / Object Repository using elements in Login Page (Username,
Password, Login, Error Message,
Online Catalog link etc,)
-----------------------------------------------------------------------
Create Test Cases
1) Admin Login
2) Verify "Error" Message"
3) Verifty "Redirect" functionality after Login
.
------------------------------------------------------------------
Page Class:
}
-----------------------------------------------------
Test Case 1 (Verify Admin Login)
System.setProperty("webdriver.chrome.driver", "F:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.gcrit.com/build3/admin/");
login.typeUserName("admin1");
login.typePassword("admin@123");
login.clickLoginButton();
if (url.contains("http://www.gcrit.com/build3/admin/index.php")) {
System.out.println("Admin Login is Successful - Passed");
}
else {
System.out.println("Admin Login is Unsuccessful - Failed");
}
driver.close();
}
}
------------------------------------------------------------------------
Test Case 2 (Verify Error Message in Admin Login Functionalily)
driver.get("http://www.gcrit.com/build3/admin/");
ErrorMessage.typeUserName("admin1");
ErrorMessage.typePassword("admin@321");
ErrorMessage.clickLoginButton();
String error=ErrorMessage.cpatureErrorMessage();
driver.get("http://www.gcrit.com/build3/admin/");
redirect.typeUserName("admin");
redirect.typePassword("admin@123");
redirect.clickLoginButton();
if (url.contains("http://www.gcrit.com/build3/admin/index.php")) {
redirect.clickLink();
}
String url2=driver.getCurrentUrl();
if (url2.equals("http://www.gcrit.com/build3/")) {
System.out.println("Page is Redirecting from Admin to User Interface -Passed");
}
else {
System.out.println("Page is Not Redirecting from Admin to User Interface -Passed");
}
driver.close();
}
}
------------------------------------------------------