Annotations
Annotations
Annotations
Test scenario :
Before Method
Opening Browser
Navigate to amazon page
Max the window
F1 :
Title of the page
F2:
url of the page
f3:
afterMethod
Close the browser
package DAY1;
import java.io.File;
import java.io.IOException;
import java.util.List;
import
org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import
org.openqa.selenium.OutputType;
import
org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
import org.testng.annotations.Test;
d.findElement(By.id("searchDropdownBo
x")).sendKeys("Books");
}
@Test(priority=5)
public void Screenshot() throws
IOException
{
File
src=((TakesScreenshot)d).getScreensho
tAs(OutputType.FILE);
FileUtils.copyFile(src, new
File("D://o11.png"));
}
@Test(priority=6)
public void Close()
{
d.close();
}
}
Ex:
Login -----customer details ----logout
Login product details ---logout
Login payment details ---logout
Example :
package DAY1;
import java.io.File;
import java.io.IOException;
import java.util.List;
import
org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import
org.openqa.selenium.OutputType;
import
org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
import
org.testng.annotations.AfterMethod;
import
org.testng.annotations.AfterTest;
import
org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
d.findElement(By.id("searchDropdownBo
x")).sendKeys("Books");
}
@Test(priority=5)
public void Screenshot() throws
IOException
{
File
src=((TakesScreenshot)d).getScreensho
tAs(OutputType.FILE);
FileUtils.copyFile(src, new
File("D://o11.png"));
}
@AfterMethod
public void Close()
{
d.close();
}
}
Example:
package DAY1;
import java.io.File;
import java.io.IOException;
import java.util.List;
import
org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import
org.openqa.selenium.OutputType;
import
org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
import
org.testng.annotations.AfterClass;
import
org.testng.annotations.AfterMethod;
import
org.testng.annotations.AfterTest;
import
org.testng.annotations.BeforeClass;
import
org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
d.findElement(By.id("searchDropdownBo
x")).sendKeys("Books");
}
@Test(priority=5)
public void Screenshot() throws
IOException
{
File
src=((TakesScreenshot)d).getScreensho
tAs(OutputType.FILE);
FileUtils.copyFile(src, new
File("D://o11.png"));
}
@AfterClass
public void Close()
{
d.close();
}
}
package DAY1;
import java.io.File;
import java.io.IOException;
import java.util.List;
import
org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import
org.openqa.selenium.OutputType;
import
org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
import
org.testng.annotations.AfterClass;
import
org.testng.annotations.AfterMethod;
import
org.testng.annotations.AfterTest;
import
org.testng.annotations.BeforeClass;
import
org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
d.findElement(By.id("searchDropdownBo
x")).sendKeys("Books");
}
@Test(priority=5)
public void Screenshot() throws
IOException
{
File
src=((TakesScreenshot)d).getScreensho
tAs(OutputType.FILE);
FileUtils.copyFile(src, new
File("D://o11.png"));
}
@Test(priority=6)
public void Close()
{
d.close();
}
}
beforetest
@aftertest
Ex:
Class 1
Login ( beforetest)
Inbox
Class 2;
Compose
Chat
Class 3
Draft
Class 4
New folder
Logout (aftertest)
@beforesuite
@aftersuite
@dataProvider