TestNG Framework Annotations

 The annotated method is a purpose of Test Case TestNG Framework Annotations
TestNG Framework Annotations

Important TestNG Annotations...

@Test - The annotated method is a purpose of Test Case

@BeforeMethod: The annotated method volition live on run earlier each Test Case inward the electrical flow shape is invoked
@AfterMethod: The annotated method volition live on run afterward each Test Case inward the electrical flow shape convey been run

Example:
Test Cases...
i) launchBrowser()
ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifybankofAmericaTitle()
iv) closeBrowser()
--------------------------------
Test Execution Flow...

i) launchBrowser()
ii) verifygoogleTitle()
iii) closeBrowser()

i) launchBrowser()
ii) verifyyahooTitle()
iii) closeBrowser()

i) launchBrowser()
ii) verifybankofAmericaTitle()
iii) closeBrowser()
-----------------------------------
@BeforeClass: The annotated method volition live on run the get-go Test Method inward the electrical flow shape is invoked
@AfterClass: The annotated method volition live on run afterward all the Test methods inward the electrical flow shape convey been run

Example:
Test Cases...
i) launchBrowser()
ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifybankofAmericaTitle()
iv) closeBrowser()
--------------------------------
Test Execution Flow....

i) launchBrowser()

ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifybankofAmericaTitle()

iv) closeBrowser()
-----------------------------------
@BeforeTest: The annotated method volition live on run earlier whatsoever Test Method belonging to the classes within the tag is run.
@AfterTest: The annotated method volition live on run afterward all the Test Methods belonging to classes within the tag 

Example:
Test Cases inward Class 1...
i) launchBrowser()
ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifybankofAmericaTitle()
iv) closeBrowser()
--------------------------------
Test Cases inward Class 2...

i) launchBrowser()
ii) verifyabcdeTitle()
iii) verifyxyzaTitle()
iv) verifysdfghjTitle()
iv) closeBrowser()
--------------------------------
Test Execution Flow...

i) launchBrowser()
ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifybankofAmericaTitle()
v) verifyabcdeTitle()
vi) verifyxyzaTitle()
vii) verifysdfghjTitle()
viii) closeBrowser()
-----------------------------------
Example 1: TestNG Program amongst "priority" Attribute

Test Cases....
i) launchBrowser()
ii) verifygoogleTitle()
iii) verifyyahooTitle()
iv) verifygcreddy()
iv) closeBrowser()
--------------------------------
Test Execution every minute per Alphabetical order...

i) closeBrowser()
ii)  launchBrowser()
iii) verifygcreddyTitle()
iv) verifygoogleTitle()
v) verifyyahooTitle()
-------------------------------------
public shape Class3 {
public static WebDriver driver;

@Test (priority = 1)
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
driver = novel ChromeDriver();
driver.manage().window().maximize();
}
@Test (priority = 2)
public void verifygoogleTitle(){
driver.get("https://www.google.co.in/");
String pageTitle = driver.getTitle();
Assert.assertEquals("Google", pageTitle);
}
@Test (priority = 3)
public void verifyyahooTitle(){
driver.get("https://in.yahoo.com/");
String pageTitle = driver.getTitle();
Assert.assertEquals("Yahoo", pageTitle);
}
@Test (priority = 4)
public void verifygcreddyTitle(){
driver.get("https://tutorial-testing-software.blogspot.co.id/");
String pageTitle = driver.getTitle();
//System.out.println(pageTitle);
Assert.assertEquals("", pageTitle);
}
@Test (priority = 5)
public void closeBrowser(){
driver.close();
}
}
-----------------------------------
Example 2: TestNG Program amongst "BeforeMethod, AfterMethod Annotations in addition to "priority" Attribute

Test Execution Flow...

i) launchBrowser()
ii) verifygoogleTitle()
iii) closeBrowser()

i) launchBrowser()
iii) verifyyahooTitle()
iii) closeBrowser()

i) launchBrowser()
iii) verifygcreddy()
iii) closeBrowser()
--------------------------------
@BeforeMethod
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
driver = novel ChromeDriver();
driver.manage().window().maximize();
}
@Test (priority = 1)
public void verifygoogleTitle(){
driver.get("https://www.google.co.in/");
String pageTitle = driver.getTitle();
Assert.assertEquals("Google", pageTitle);
}
@Test (priority = 2)
public void verifyyahooTitle(){
driver.get("https://in.yahoo.com/");
String pageTitle = driver.getTitle();
Assert.assertEquals("Yahoo", pageTitle);
}
@Test (priority = 3)
public void verifygcreddyTitle(){
driver.get("https://tutorial-testing-software.blogspot.co.id/");
String pageTitle = driver.getTitle();
//System.out.println(pageTitle);
Assert.assertEquals("", pageTitle);
}
@AfterMethod
public void closeBrowser(){
driver.close();
}
}
-----------------------------------
public shape Class3 {
public static WebDriver driver;

@BeforeMethod
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
driver = novel ChromeDriver();
driver.manage().window().maximize();
System.out.println("Application Launched - Passed");
}
@Test (priority = 1)
public void verifygoogleTitle(){
driver.get("https://www.google.co.in/");
System.out.println("Title is Google - Passed");
}
@Test (priority = 2)
public void verifyyahooTitle(){
driver.get("https://in.yahoo.com/");
System.out.println("Title is Yahoo - Passed");
}
@Test (priority = 3)
public void verifygcreddyTitle(){
driver.get("https://tutorial-testing-software.blogspot.co.id/");
System.out.println("Title is - Passed");
}
@AfterMethod
public void closeBrowser(){
driver.close();
System.out.println("Application Closed - Passed");
}
}
-----------------------------------
Example 3: TestNG Program amongst "BeforeClass, AfterClass Annotations in addition to "priority" Attribute

Test Execution Flow...

launchBrowser()
i) verifygoogleTitle()
ii) verifyyahooTitle()
iii) verifygcreddy()
closeBrowser()
-----------------------------------
public shape Class3 {
public static WebDriver driver;

@BeforeClass
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
driver = novel ChromeDriver();
driver.manage().window().maximize();
System.out.println("Application Launched - Passed");
}
@Test (priority = 1)
public void verifygoogleTitle(){
driver.get("https://www.google.co.in/");
System.out.println("Title is Google - Passed");
}
@Test (priority = 2)
public void verifyyahooTitle(){
driver.get("https://in.yahoo.com/");
System.out.println("Title is Yahoo - Passed");
}
@Test (priority = 3)
public void verifygcreddyTitle(){
driver.get("https://tutorial-testing-software.blogspot.co.id/");
System.out.println("Title is - Passed");
}
@AfterClass
public void closeBrowser(){
driver.close();
System.out.println("Application Closed - Passed");
}
}
-----------------------------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post