Automation
Frameworks:
Framework is
a structure with set of assumptions, concepts and tools to automate S/w testing
Advantages:
-provides consistency in Testing
-Increase the reusability of the
scripts
-low maintenance
Automation
Frameworks:
1. Modular Framework
2. Page Object Model Framework
3. TestNg Framework
4. Data Driven Framework
5. Keyword Driven Framework
1. Modular Framework:
In this approach we create individual methods/functions for each reusable
test scenario in application after that we call those methods from different
classes based on functionality flow in application to execute
Procedure:
Step 1:
Create
non-executable class with following methods
Method-1: to perform user
Registration
Method-2: to close application
Script:
Class-1:
Parent-1
----------------
package
ModularFramework;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
public class Parent1 {
// Method 1-to
perform user Registration
public void
userReg(WebDriver driver) throws InterruptedException {
// to click on
"Home" link
driver.findElement(By.linkText("Home")).click();
// to click on
REgister link
driver.findElement(By.linkText("REGISTER")).click();
// to enter
"firstName"
driver.findElement(By.name("firstName")).sendKeys("Smith");
// to enter
user name
driver.findElement(By.name("email")).sendKeys("Smith");
driver.findElement(By.name("password")).sendKeys("P@ssw0rd");
driver.findElement(By.name("confirmPassword")).sendKeys("P@ssw0rd");
driver.findElement(By.name("register")).click();
Thread.sleep(3000);
System.out.println("User
Registration operation completed");
}
// Method-2 to
close application
public void
tearDown(WebDriver driver) {
driver.close();
System.out.println("Application
closed");
}
}
Step 2:
Create
non-executable class with following method
Method-1: to perform login operation
Script:
Class-2:
(Parent-2)
package
ModularFramework;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
public class Parent2 extends Parent1{
// to perform
login operation
public void
userLogin(WebDriver driver) throws InterruptedException {
driver.findElement(By.linkText("Home")).click();
driver.findElement(By.name("userName")).sendKeys("mercury");
driver.findElement(By.name("password")).sendKeys("mercury");
driver.findElement(By.name("login")).click();
Thread.sleep(3000);
System.out.println("Successful
login operation");
}
}Step 3:
Create
Driver class to call the required methods from parent classes and also create
following method
Method-1: to initialize FF browser
and to open url
Script:
Class-3:
(DriverClass)
package
ModularFramework;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
java.util.concurrent.TimeUnit;
public class DriverClass extends Parent2{
static WebDriver driver;
// Method-1 to
initialize FF browser and open URL
public void setUp(){
driver= new
FirefoxDriver();
driver.get("http://newtours.demoaut.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
System.out.println("Browser
Initialized and application opened");
}
public static void main(String[] args) throws
InterruptedException {
//create
instance object for class and calling other methods
DriverClass
dc= new DriverClass();
dc.setUp();
dc.userReg(driver);
dc.userLogin(driver);
dc.tearDown(driver);
}
}
No comments:
Post a Comment