Selenium Tutorial For Beginners 33|Page Object Model in Selenium|G C Reddy|

preview_player
Показать описание
What is POM - Page Object Model in Selenium?, Advantages of Page Object Model in Selenium, Drawbacks of Page Object Model in Selenium, and Implementing Page Object Model in Selenium.
Introduction to TestNG Testing Framework in Selenium, Overview of Supported Frameworks in Selenium, Advantages of TestNG Testing Framework, Download & Install TestNG Testing Framework, and write first TestNG Test Case & execute.
Рекомендации по теме
Комментарии
Автор

Class Notes:
Selenium Class 33: Page Object Model (POM) in Selenium

1) What is Page Object Model?

> POM (Page Object Model) is an Object/Element design pattern to create Object
Repository for Web elements/objects (Ex: Link, Button, Edit Box etc...)

> Under this model, container classes for wen elements are created that behave has
Object Repositories

> We can create POM in 2 ways,
i) POM without Page Factory
ii) POM with Page Factory

> No Object Repository in Selenium, it is a programming interface, if it is UFT/QTP
we have Object Repositories (Local and Shared)

> Under this Model, for every web page in the Application, there should be
corresponding page class

> This Page Class will find web elements of that web page and also contains
the methods which perform operations on those elements

> If No Object Repository/Page Object Model then it is difficult to maintain
Objects or Elements in Test Cases

2) Advantages of Page Object Model

> Centralized maintenance of Web Elements/Objects
> Reusability, reduce duplication of code

Implementation of Page Object Model

Create Page Class

package abcd;

import org.openqa.selenium.By;
import

public class LoginPage {
WebDriver driver;

By Username=By.name("username");
By Pass = By.name("password");
By LoginButton = By.id("tdb1");

public LoginPage(WebDriver driver){
this.driver=driver;
}
public void typeUsername(String uname){

}
public void clearUserName(){

}
public String captureUserName(){
return
}
public void typePassword(String password){

}
public void ClickLogin(){

}
}

1) Test Case/s Class
public class TestCases {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();


LoginPage login = new LoginPage(driver);

login.typeUsername("admin");
login.ClickLogin();

String url=driver.getCurrentUrl();

System.out.println("Admin Login is Successful-Passed");
}
else {
System.out.println("Admin Login is Unsuccessful - Failed");
}
driver.close();
}
}

2nd Test Case

public class VerifyErr {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();


LoginPage Err = new LoginPage(driver);

Err.typeUsername("admin1");
Err.ClickLogin();

String errmessage =Err.captureErr();

if (errmessage.contains("Error: Invalid administrator login attempt.")){
System.out.println("Admin Login Unsuccessful & Showing Correct Error Message -Passed");
}
else {
System.out.println("Admin Login Unsuccessful & Not Showing Correct Error Message -Failed");
}
driver.close();
}
}

Introduction to TestNG Testing Framework

In Selenium using Java there are two Testing Frameworks are available,
i) JUnit
ii) TestNG

Selection of Testing Framework is depends on Programming platform that we selected
for Selenium Test Automation,

Selenium with Java- JUnit or TestNG,
Selenium with C#.NET- NUnit,
Selenium with PHP -Behat+Mink
Selenium with Ruby - Repect, Test:Unit,
Selenium with Python - PyUnit, Py:Test
Etc...

1) Introduction to TestNG Testing Framework

> TestNG is a Testing Framework, was designed to simplify a broad range of
Testing needs from Unit Testing to System Testing...

> Initially developed for Unit Testing, now using for all levels of Testing

> TestNG is an Open Source Software, where NG stands for Next Generation

> TestNG was inspired bt JUnit and NUnit, and introduced some new functionalities

Advantages of TestNG Testing Framework in Selenium Testing,

> TestNG Annotations are easy to create Test cases,
> Test Cases can be grouped and prioritized more easily,
> Executes multiple programs / Classes using XML file
Multiple Classes - more than one class (ex: 3 classes)
Multiple Test Cases - more than one Test Case (ex: 3 Test Cases)
Ex:
We have 3 Test Cases,
> Using 3 different classes or using a single class

Ex:
9 Test cases,
Create 9 test cases in 3 classes and execute these 3 classes using xml file in TestNG

> Generates Test Reports
> Parallel Testing

2) Install TestNG and write first TestNG Test Case

In Eclipse IDE:
> Help Menu
> Select "Install New Software"
> Click "Add"
> Enter Name as "TestNG"
> Click "OK"
>Then TestNG will be populated,
> Select TestNG
> Next > Next > accept the agreement > Finish

Write First TestNG Test Case

Manual Test Case:
Test Case Name: Verify Page Title (Google Home)

Test Steps:
i) Launch the Browser

Verification Point/s:
Capture the Page Title and Compare with Expected

Expected:
Google

Test Data:
NA

TestNG Test Case
i) main method is not used in TestNG Test Cases/Program
ii) TestNG programs contains methods only that contain Annotations
iii) If we don't use @Test Annotation then the method won't be executed

Ex:
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();

Assert.assertEquals(driver.getTitle(), "Google");
driver.close();

gcreddy
Автор

Sir TestNG was not downloaded m cheyali

ramyakrishnapothem
Автор

Hi sir, i m learing Selenium by seeing ur video, its very helpful, i am having one doubt, why we have created constructor here, plz help

isabelgill