Friday, 5 October 2012

Sending Attachment Mail using Java

import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;


public class SendAttachMail {
    public static void main(String[] args) throws MessagingException {
        SendAttachMail s = new SendAttachMail();
       
    }

    public SendAttachMail() throws MessagingException {

        String host = "smtp.gmail.com";
       /***
        * Here you need to give password
        */
        String Password = "xxxxxxxxxxx";
       
       
        String from = "xxxxxxxxxxxxxxxxxxxxxxx";
        String toAddress = "xxxxxxxxxxxxxxxxxxxxx";
        //Need to give file path
        String filename = "F:/ex/RealUsage/build.xml";
        // Get system properties
        Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtps.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        Session session = Session.getInstance(props, null);

        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(from));

        message.setRecipients(Message.RecipientType.TO, toAddress);

        message.setSubject("JavaMail Attachment");

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Here's the file");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        message.setContent(multipart);

        try {
            Transport tr = session.getTransport("smtps");
            tr.connect(host, from, Password);
            tr.sendMessage(message, message.getAllRecipients());
            System.out.println("Mail Sent Successfully");
            tr.close();

        } catch (SendFailedException sfe) {

            System.out.println(sfe);
        }
    }

}

SendingMail using Java

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

public class GmailSendEmailSSL {
    public static final String USERNAME = "xxxxxxxxxxxxxxxx";
    public static final String PASSWORD = "xxxxxxxxxxxxxxxx";

    public static void main(String[] args) throws Exception {
        //
        // Email information such as from, to, subject and contents.
        //
        String mailFrom = "xxxxxxxxxxxxxxxxxxxxxx";
        String mailTo = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
        String mailSubject = "TestReport";
        String mailText = "Please check enclosed TestReport";

        GmailSendEmailSSL gmail = new GmailSendEmailSSL();
        gmail.sendMail(mailFrom, mailTo, mailSubject, mailText);
    }

    private void sendMail(String mailFrom, String mailTo,
                          String mailSubject, String mailText)
            throws Exception {

        Properties config = createConfiguration();

        //
        // Creates a mail session. We need to supply username and
        // password for Gmail authentication.
        //
        Session session = Session.getInstance(config, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                        GmailSendEmailSSL.USERNAME,
                        GmailSendEmailSSL.PASSWORD
                );
            }
        });

        //
        // Creates email message
        //
        Message message = new MimeMessage(session);
        message.setSentDate(new Date());
        message.setFrom(new InternetAddress(mailFrom));
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
        message.setSubject(mailSubject);
        message.setText(mailText);

        //
        // Send a message
        //
        Transport.send(message);
    }

    private Properties createConfiguration() {
        return new Properties() {{
            put("mail.smtp.host", "smtp.gmail.com");
            put("mail.smtp.auth", "true");
            put("mail.smtp.port", "465");
            put("mail.smtp.socketFactory.port", "465");
            put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        }};
    }
}

Friday, 28 September 2012

Selenium Frameworks

Types of Framework

Any framework is made up of a number of reusable modules & function libraries that are developed with the following characteristics in mind:

Maintainable
Reusable
Manageable
Accessible
Robust
Flexibility
Measurable


Frame work has several types and most popular are the below :
 

Frame work has several types and most popular are the below :

a.Keyword driven frame work
b.Data driven driven frame work
c.Hybrid framework

Key word Driven Frame work :

Keyword driven framework is an action based test method used in planing and implementation of automation.

Data Driven Framework :

Data driven is the design of possible inputs what may be given by the end user.
This would cover maximum probabilities of an input data.
It can either be Spread sheet(excel)/sql/CSV.
We have to connect and pass the values to the respective field or element.
The data should be designed by the experienced person on the project. It may be a client or even non technical person but should be more familiar from an end users prospective.
We have to map the file path properly.

Hybrid Framework:

The Hybrid Automation Framework is otherwise referred to in the industry as a "Hybrid Keyword Data Driven Automation Framework".  


Referal Sites

http://www.gcrit.com/forums/viewtopic.php?f=29&t=109

http://zomobo.net/keyword-driven
 

http://www.youtube.com/watch?v=KL4Y7cWiK4g&feature=player_embedded
 

http://www.youtube.com/watch?v=JMZeaF0ST4w&feature=channel
 

http://www.youtube.com/watch?v=1ZV8pZAKkDQ&NR=1
 

http://www.youtube.com/watch?v=A6ND9pRRBY8&NR=1
 

http://www.whatsontv.co.uk/video/youtube/search/keyword-driven
 

Selenium Refereal sites

http://www.mkyong.com/



http://whytotest.blogspot.in/2010/05/selenium-test-framework.html

http://anoopjshetty.wordpress.com/2012/04/19/behaviour-driven-development-bdd-in-net-using-specflow-selenium-and-nunit/

http://codedetective.blogspot.in/2011/11/setting-up-selenium-webdriver-using-c.html

http://help.utest.com/testers/crash-courses/functional/automation-tools--selenium-102

http://www.savevid.com/video/selenium-video-training-datadriven-framework-and-hybrid-framework-comparison.html

http://testng.org/doc/index.html

http://selenium-tutorial.blogspot.in/2012/04/uploading-file.html

http://oxpedia.org/wiki/index.php?title=Automated_GUI_Tests

http://xebee.xebia.in/2012/05/29/creating-automation-framework-using-selenium-and-test-ng-2/

http://www.way2automation.com/selenium_tutorial/selenium-hybrid-datadriven-keyword-framework

-tutorial.html

http://www.seleniumwiki.com/selenium-rc/selenium-keyword-driven-framework/


http://executeautomation.com/blog/blog_mod/data-driven-testing-in-selenium-using-jxl-part-2/

http://code.google.com/p/selenium/wiki/AdvancedUserInteractions

http://www.kavinschool.com/content/selenium-tuition-bayarea/39-selenium-course/54-advanced-s

elenium-using-java-language

http://www.ijcst.com/vol23/1/prasanth.pdf

http://code.google.com/p/selenium/wiki/PageFactory

http://learnseleniumautomation.blogspot.in/2012/03/window-handle-example-with-selenium.html

http://www.ibm.com/developerworks/web/library/wa-seleniumgrid/index.html

http://www.8bitavenue.com/2012/03/gui-testing-using-sikuli-and-java/

http://eureka.ykyuen.info/2010/06/26/selenium-integrate-the-selenium-tests-into-maven-build/

http://www.way2automation.com/

http://mearra.com/blogs/jani-palsamaki/creating-and-running-simple-selenium-webdriver-test

http://code.google.com/p/selenium/wiki/SeleniumEmulation

http://automation.youplayoff.com/category/selenium/


http://qaselenium.blogspot.in/2011/01/selenium-automation-framework-design.html

http://seleniumexamples.com/blog/examples/selenium2-in-net-framework/

http://robotframework-seleniumlibrary.googlecode.com/hg/doc/SeleniumLibrary.html?r=2.8

https://blogs.oracle.com/rajeshthekkadath/

http://en.wikipedia.org/wiki/Selenium_%28software%29

http://www.f14testing.com/archives/1532

http://functionaltestautomation.blogspot.in/2009/10/dataprovider-data-driven-testing-with.html

http://www.javacodegeeks.com/2012/04/integration-testing-with-selenium.html

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/html5/package-summary.html

http://sauceio.com/index.php/2011/12/selenium-testing-framework-part-3-putting-it-all-togeth

er/

http://selftechy.com/2011/06/02/parameterization-of-selenium-tests-with-microsoft-excel

http://sauceio.com/index.php/2011/11/selenium-testing-framework-pt-2-base-classes/

http://www.kavinschool.com/content/selenium-tuition-bayarea/39-selenium-course/54-advanced-s

elenium-using-java-language

http://hop2croft.wordpress.com/2011/09/17/spring-mvc-basic-example-with-maven/

http://www.seleniumwiki.com/selenium-rc/selenium-rc-test-framework-using-xml-data-structure/

http://marcovaltas.com/2009/02/19/running-selenium-with-testng.html

http://blog.varunin.com/

http://en.wikipedia.org/wiki/Data-driven_testing

http://thangselenium.blogspot.in/


http://sqahome.blogspot.in/2010/06/selenium-framework-structure-java.html

http://www.wallix.org/2011/07/26/how-to-use-robotframework-with-the-selenium-library/

http://qtpselenium.com/selenium-tutorial/selenium-training-hybrid-framework/

http://automationtestingsimplified.wordpress.com/2011/08/18/how-to-do-data-driven-testing-us

ing-selenium-2-webdriver/

http://wiki.zimbra.com/wiki/Testing:_Selenium:_ZimbraSelenium_SampleTestCase

http://code.google.com/p/selenium/wiki/PageObjects

http://marakana.com/bookshelf/selenium_tutorial/project.html

http://in.linkedin.com/pub/selenium-rc-webdriver-tutorial/51/b7/49

http://code.google.com/p/robotframework-seleniumlibrary/

http://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/

http://www.pushtotest.com/testing-with-selenium#tutorial

http://seleniumrc.wordpress.com/

http://qtp-help.blogspot.in/p/selenium-training.html

http://www.seleniumtests.com/2012/01/selenium-2-methods-are-no-more-weird.html?utm_source=BP_recent

http://candidjava.com/keyword-this-in-java-with-example-program

https://github.com/Ardesco/Ebselen/blob/master/ebselen-core/src/main/java/com/lazerycode/ebselen/customhandlers/ExcelHandler.java

http://shanmugavelc.blogspot.in/2010/09/datadriven-test-using-selenium-nunit.html

http://vimeo.com/46412735

http://computer.motiontopic.net/s/Selenium-Data-driven-framework

Selenium Grid

http://code.google.com/p/selenium/wiki/Grid2
http://deors.wordpress.com/2012/02/02/selenium-webdriver-grid-2/
http://technologyandleadership.com/30-feet-view-of-test-automation-framework-with-selenium/

selenium with flash

http://code.google.com/p/flash-selenium/


http://www.softwaretestingtutorials.org/packages/


selenium with ant

http://hedleyproctor.com/2011/07/automating-selenium-testing-with-testng-ant-and-cruisecontrol/


selenium Index

http://www.sqaforums.com/showflat.php?Cat=0&Number=716574&Main=714887

http://www.citehr.com/374186-best-institute-learning-selenium-testing.html

http://forum.softwaretestinghelp.com/index.php?topic=446.0

http://grokbase.com/p/gg/selenium-users/125bve6d3m/is-anyone-provide-me-code-for-data-driven-testing-in-selenium-webdriver-in-java-junit-framework-plz-it-is-urgent

http://ahmedabad.olx.in/selenium-training-in-ahmedabad-iid-249982843


http://www.automation.lifegoeasy.com/Selenium-Webdriver-Java-Syllabus

http://seleniumtraining.weebly.com/selenium-automation.html

http://www.360logica.com/test-automation-services/functional-automation-framework


Testng

http://ravisha-selenium.blogspot.in/

DataDriven framework

http://executeautomation.com/blog/tag/data-driven-testing/

http://functionaltestautomation.blogspot.in/2009/10/dataprovider-data-driven-testing-with.html

http://qtpselenium.com/selenium-tutorial/selenium-training-data-driven-framework/

http://automationtestingsimplified.wordpress.com/2011/08/18/how-to-do-data-driven-testing-using-selenium-2-webdriver/

http://automationtestingsimplified.wordpress.com/2011/05/31/hybrid-testing-data-keyword-driven-using-selenium/

http://www.softwaretestingclub.com/video/selenium-data-driven-automation-framework-selenium-rc-junit

http://testerinyou.blogspot.in/2010/10/how-to-do-data-driven-testing-using.html

http://www.seleniumelearn.com/free-selenium-training-tutorial-videos

http://www.seleniumwebdriver.com/webdriver-tutorials/advance-selenium-rc-webdriver-tutorials-with-frameworks/msg16333/?PHPSESSID=b0af0d93c11942fedcc8c26d0ac04ec0#msg16333

http://lrnselenium.com/?category_name=automation-framework

http://selenium-suresh.blogspot.in/2012/07/data-driven-testing-using-selenium-rc_24.html

http://hedleyproctor.com/2011/07/automating-selenium-testing-with-testng-ant-and-cruisecontrol/

http://testingchronicle.blogspot.in/2012/05/selenium-keyword-driven-and-data-driven.html

https://sites.google.com/site/joinqahub/Selenium-tutorial-for-beginners

http://executeautomation.com/blog/blog_mod/data-driven-testing-in-selenium-using-jxl-part-2/

http://www.gcrit.com/forums/viewtopic.php?f=29&t=109
http://zomobo.net/keyword-driven
http://www.youtube.com/watch?v=KL4Y7cWiK4g&feature=player_embedded
http://www.youtube.com/watch?v=JMZeaF0ST4w&feature=channel
http://www.youtube.com/watch?v=1ZV8pZAKkDQ&NR=1
http://www.youtube.com/watch?v=A6ND9pRRBY8&NR=1
http://www.whatsontv.co.uk/video/youtube/search/keyword-driven
 

Thursday, 20 September 2012

Reading and Writing CSV Formated Data

Reading/Writing an excel document like you requested, you can use the CSV format


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class CsvWriter {
 
public static void main(String args[]) throws IOException {

 
String fileName = "test.xls";

 
PrintWriter out = new PrintWriter(new FileWriter(fileName));
  out
.println("a,b,c,d");
  out
.println("e,f,g,h");
  out
.println("i,j,k,l");
  out
.close();

 
BufferedReader in = new BufferedReader(new FileReader(fileName));
 
String line = null;
 
while ((line = in.readLine()) != null) {

   
Scanner scanner = new Scanner(line);
   
String sep = "";
   
while (scanner.hasNext()) {
   
System.out.println(sep + scanner.next());
    sep
= ",";
   
}
 
}
  in
.close();
 
}
}

Wednesday, 19 September 2012

Testing Interview Questions

Difference between Performance Testing, Load Testing and Stress Testing

Performance testing - It is performed to evaluate the performance of components of a particular system in a specific situation. It very wide term. It includes: Load Testing, Stress Testing, capacity testing, volume testing, endurance testing, spike testing, scalability testing and reliability testing etc. This type of testing generally does not give pass or fail. It is basically done to set the benchmark & standard of the application against Concurrency / Throughput, Server response time, Latency, Render response time etc. In other words, you can say it is technical & formal evaluation for responsiveness, speed, scalability and stability characteristics.

 

Load Testing is subset of performance testing. It is done by constantly increasing the load on the application under test till the time it reaches the threshold limit. The main goal of load testing is to identify the upper limit of the system in terms of database, hardware and network etc. The common goal of doing the load testing is to set the SLAs for the application. Example of load testing can be:

Running multiple applications on a computer simultaneously - starting with one application, then start second application, then third and so on....Now see the performance of your computer.

Endurance test is also a part of load testing which used to calculate metrics like Mean Time Between Failure and Mean Time to Failure.

Load Testing helps to determine:

Throughput

Peak Production Load

 Adequacy of H/W environment

Load balancing requirements

How many users application can handle with optimal performance results

How many users hardware can handle with optimal performance results

Stress testing - It is done to evaluate the application's behaviour beyond normal or peak load conditions. It is basically testing the functionality of the application under high loads. Normally these are related to synchronization issues, memory leaks or race conditions etc. Some testing experts also call it as fatigue testing. Sometimes, it becomes difficult to set up a controlled environment before running the test. Example of Stress testing is:

 

A banking application can take a maximum user load of 20000 concurrent users. Increase the load to 21000 and do some transaction like deposit or withdraw. As soon as you did the transaction, banking application server database will sync with ATM database server. Now check with the user load of 21000 does this sync happened successfully. Now repeat the same test with 22000 thousand concurrent users and so on.

Spike test is also a part of stress testing which is performed when application is loaded with heavy loads repeatedly and increase beyond production operations for short duration.

Stress Testing helps to determine:

Errors in slowness & at peak user loads

Any security loop holes with over loads

How the hardware reacts with over loads

Data corruption issues at over loads

 

Reading Data from excel file

How to read data from Excel file using Java

 

 

import java.io.*;
import java.sql.*;
public class ExcelReadTest{
public static void main(String[] args){ 
 Connection connection = null;
try{
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 Connection con = DriverManager.getConnection( "jdbc:odbc:exceltest" );
 Statement st = con.createStatement();
 ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
 
 ResultSetMetaData rsmd = rs.getMetaData();
 int numberOfColumns = rsmd.getColumnCount();
 
 
 while (rs.next()) {
 for (int i = 1; i <= numberOfColumns; i++) {
 if (i > 1) System.out.print(", ");
 String columnValue = rs.getString(i);
 System.out.print(columnValue);
 } 
 
System.out.println(""); 
}
 
st.close();
con.close();
}
catch(Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}
 
 

OR

WorkbookSettings ws = new WorkbookSettings();   

ws.setLocale(new Locale("en","EN"));   

Workbook workbook = Workbook.getWorkbook(file);              

Sheet s = workbook.getSheet(0);         

LabelCell lcdate = s.findLabelCell("Date");          

LabelCell lcitem = s.findLabelCell("Item");                                  

LabelCell lcamount = s.findLabelCell("Amount");                                 

LabelCell lctype = s.findLabelCell("Type");                 

int columns = s.getColumns();          

   int rows = s.getRows();         

      System.out.println("col -->>> "+columns+"  rows -->>> "+rows);  


To print the data


String data;     

  for(int col = 0;col < columns;col++)         {             for(int row = 0;row < rows;row++)             {                data = s.getCell(col, row).getContents();   

       // Code to display ....   

       }  

 

 

(OR)

 

 

Navigate to this url's

http://poi.apache.org/index.html 

 http://www.coderanch.com/t/465901/JDBC/databases/insert-data-excel-file-java

http://www.ibm.com/developerworks/library/x-jxmlexl/index.html 

http://www.avajava.com/tutorials/lessons/how-do-i-read-from-an-excel-file-using-poi.html?page=1 

http://mrbool.com/reading-excel-file-with-java/24562