Why do you use TestNG?
You see that TestNG is framework support get proper reports,
handle checkpoint or excaption handling.
You can to use Junit or TestNG or anything else to
support for you.
In previous post, I have explained setup TestNG in eclipse the following link
such as: http://howtesting.blogspot.com/2012/12/setting-up-testng-with-eclipse.html
I have a sort code below:
public class google_login extends
SeleneseTestBase {
WebDriver driver;
String url;
@BeforeMethod
public void setUp()throws Exception{
driver = new FirefoxDriver();
url = "http://www.gmail.com";
driver.get(url);
}
@Test
public void rungoogle() throws
IOException, InterruptedException, BiffException, Exception{
// driver = new FirefoxDriver();
// String url
= "http://www.gmail.com";
driver.getCurrentUrl();
File file = new File("D:\\ECLIPSE\\workspace_eclipseclassic\\seleniumdriver\\test.xls");
//Reading data in Excel file
Workbook wb = Workbook.getWorkbook(file);
jxl.Sheet sheet = wb.getSheet(0) ;
int rows = sheet.getRows();
String filename="D:\\ECLIPSE\\workspace_eclipseclassic\\seleniumdriver\\result.xls"
;
//Create sheet
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet1 =
((HSSFWorkbook) hwb).createSheet("Login Info");
//Create row
HSSFRow row1 =
sheet1.createRow(0);
for(int row = 0; row < rows; row
++){
driver.get(url);
//Reading data from excel file to write
element Email fields
WebElement email = driver.findElement(By.id("Email"));
email.clear();
String emailuser = sheet.getCell(0,row).getContents();
email.sendKeys(emailuser);
WebElement pass = driver.findElement(By.id("Passwd"));
pass.clear();
String passuser =
sheet.getCell(1,row).getContents();
pass.sendKeys(passuser);
WebElement btnlogin = driver.findElement(By.id("signIn"));
btnlogin.click();
driver.manage().timeouts().implicitlyWait(5,
TimeUnit.SECONDS);
try{
if(driver.findElement(By.id("gbqfq")).isDisplayed())
System.out.println("Passed");
row1.createCell(row).setCellValue("Pass");
driver.manage().deleteAllCookies();
}
catch(NoSuchElementException e){
System.out.println("Failed");
row1.createCell(row).setCellValue("Fail");
}
//
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
public static void writeresult(String
result) throws IOException{
ByteArrayOutputStream f = new ByteArrayOutputStream();
byte
buf[] = result.getBytes();
f.write(buf);
OutputStream f2 = new FileOutputStream("D:\\ECLIPSE\\workspace_eclipseclassic\\seleniumdriver\\output.xls");
f.writeTo(f2);
f2.close();
f.close();
}//writeresult
}
@AfterMethod
public void tearDown(){
driver.close();
}
|
The Java class “Google_Demo” is
implemented in Eclipse IDE using TestNG framework.
In the above code, you see “setUp”
and “tearDown” which are marked with @BeforeMethod and @AfterMethod annotations
and @Test annotation.
Hence Before executing each test,
setUp method will be executed. After the execution of each test, tearDown gets
executed.
How to execute the test?
Click Run –> Run As –>
TestNG Test
Output of the execution as below:
You should be Convert to TestNG.
It’s displayed such as:
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE suite
SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite"
parallel="none">
<test name="Test">
<classes>
<class name="com.dienmay_login"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite
-->
|
You can config some function in TestNG. Run and show the report of TestNG
hi ,
ReplyDeleteAll of your posting are really useful for selenium tester , Its really great effort .
-Jash
can i have your Gmail ID pls?
ReplyDeletenhen79@gmail.com
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
ReplyDeleteangularjs-Training in velachery
angularjs-Training in annanagar
angularjs Training in chennai
angularjs Training in chennai
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeleteblueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training
I know you feel more happy when you get things done and best of all those things are your most precious treasure.
ReplyDeleteJava training in Tambaram | Java training in Velachery
Java training in Omr | Oracle training in Chennai
I'm here representing the visitors and readers of your own website say many thanks for many remarkable
ReplyDeleteData Science training in kalyan nagar | Data Science training in OMR
Data Science training in chennai | Data science training in velachery
Data science training in tambaram | Data science training in jaya nagar
I would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
This article is so informatic and it really helped me to know more about the Selenium Testing. keep it up.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai