Friday, October 31, 2014

java : Setup Windows Environment Variables for Eclipse

Setup Windows Environment Variables for Eclipse



The considered scenario is to set environment variables to enable the compilation and execution of Java applications from the command line (command prompt) or by using an IDE like Eclipse. By installing the Java SDK, system variables about the location of executables (compiler, java virtual machine) are not defined or initialized automatically.
Testing is done by opening command prompt (Start -> cmd) and trying to launch the compiler with the command
C:\Users\User>javac.exe
If there is no system variable to indicate where to look for the this executable, the system will give an error like:
'javac' is not recognized as an internal or external command,
operable program or batch file.
The solution to this problem is given by setting the system variables: JAVA_HOME, PATH and CLASSPATH:
  1. Open the Control Panel -> System or Security –> System; the same thing can be done by right-clicking on MyComputer and choosing Properties
2.   Choose Advanced System Settings option

3.   Choose the Environment Variables option

4.   In the System variables section it is selected New

5.   Define the variable name, JAVA_HOME and its value C:\Program Files\Java\jdk1.6.0_16 (for this example JDK version 1.6.0 was installed in C:\Program Files\Java\jdk1.6.0_16 folder; if needed, modify this value to reflect the real situation)

6. Insert a new system variable named, CLASSPATH and its value %JAVA_HOME%\jre\lib

7. For PATH, if it already exists, select it and choose the Edit option; in the editor add the value;%JAVA_HOME%\bin (the new values are separated by a semicolon from the existing ones) Testing the system variables is done by opening a new command prompt window (Start -> cmd) and trying to launch the compiler with the command:
C:\Users\User>javac
Usage: javac
where possible options include:
  -g                         Generate all debugging info
...
or, by using next commands
C:\Users\Catalin>echo %CLASSPATH%
C:\Program Files\Java\jdk1.6.0_16\jre\lib
 
C:\Users\User>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_16
 
C:\Users\User>echo %PATH%

8. Restart the computer in order to make your system aware of these changes (thanks to Ike for reminding me)

If it is not working , go to Environment Variables> System Variables .Verify the following:-
  1. "Path" variable can hold any number of paths but only 1 Java path.
  2. See whether you have added path containing "JDK" not "JRE".

Monday, October 27, 2014

Selenium : FastExcel

FastExcel

Also try:

FastExcel is a pure java excel read/write component.It's FAST and TINY. We provide:

    Reading and Writing support for Excel '97(-2003) (BIFF8) file format.
    Low level structures for BIFF(Binary Interchange File Format).
    Low level structures for compound document file format (also known as "OLE2 storage file format" or "Microsoft Office compatible storage file format").
    API for creating, reading excel file.

FastExcel 0.5.1 Release
http://sourceforge.net/projects/fastexcel/files/fastexcel/fastexcel0.5.1/


FastExcel is content-based,that means we just care about the content of excel. So FastExcel just read the cell string and other important information,Some Properities like color,font are not supported.Because we don't need to read,parse,store these additional information so FastExcel just need little memory. New Features in FastExcel 0.4



To read excel file.FastExcel parses these records and build an inner struct of excel file.The Record Parsers:

    BOFParser
    EOFParser
    BoundSheetParser
    SSTParser
    IndexParser
    DimensionParser
    RowParser
    LabelSSTParser
    RKParser
    MulRKParser
    LabelParser
    BoolerrParser
    XFParser
    FormatParser
    DateModeParser
    StyleParser
    MulBlankParser
    NumberParser
    RStringParser

Example :


Basic Read

public void testDump() throws ExcelException {
Workbook workBook;
workBook = FastExcel.createReadableWorkbook(new File("test.xls"));
workBook.setSSTType(BIFFSetting.SST_TYPE_DEFAULT);//memory storage
workBook.open();
Sheet s;
s = workBook.getSheet(0);
System.out.println("SHEET:"+s);
for (int i = s.getFirstRow(); i < s.getLastRow(); i++) {
System.out.print(i+"#");
for (int j = s.getFirstColumn(); j < s.getLastColumn(); j++) {
System.out.print(","+s.getCell(i, j));
}
System.out.println();
}
workBook.close();
}

Event-based Read

public void testEventDump() throws ExcelException {
Workbook workBook;
workBook = FastExcel
.createReadableWorkbook(new File("test.xls"));
workBook.open();
workBook.getSheet(0, new SheetReadAdapter() {
public void onCell(int row, int col, String content) {
System.out.println(row + "," + col + "," + content);
}
});
workBook.close();
}

Basic Write

public void testWrite() throws ExcelException{
File f=new File("write.xls");
Workbook wb=FastExcel.createWriteableWorkbook(f);
wb.open();
Sheet sheet=wb.addSheet("sheetA");
sheet.setCell(1, 2, "some string");
wb.close();
}

Stream Write

public void testStreamWrite() throws Exception{
File f=new File("write1.xls");
Workbook wb=FastExcel.createWriteableWorkbook(f);
wb.open();
Sheet sheet=wb.addStreamSheet("SheetA");
sheet.addRow(new String[]{"aaa","bbb"});
wb.close();
}



Ref:
http://fastexcel.sourceforge.net/

Thursday, October 23, 2014

Selenium : Report Template 2

Report Template 2




<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Expandable and collapsible table - demo</title>
<a>
</a>
<script type="text/javascript">
function toggle_visibility(tbid,lnkid) {
if (document.getElementsByTagName) {
var tables = document.getElementsByTagName('table');
for (var i = 0; i < tables.length; i++) {
if (tables[i].id == tbid){
var trs = tables[i].getElementsByTagName('tr');
for (var j = 1; j < trs.length; j+=1) {
trs[j].bgcolor = '#CCCCCC';
if(trs[j].style.display == 'none')
trs[j].style.display = '';
else
trs[j].style.display = 'none';
}
}
}
}
var x = document.getElementById(lnkid);
if (x.innerHTML == '[+] Expand ')
x.innerHTML = '[-] Collapse ';
else
x.innerHTML = '[+] Expand ';
}
function Count_function() {
var pass = "PASS";
var fail = "FAIL";
var count_pass=0;
var count_fail=0;
var targetTable=document.getElementsByTagName("td");
var rowData="";
for (var i=0; i < targetTable.length; i++) {
if (targetTable[i].innerHTML == "PASS") {
count_pass=count_pass+1;
} else if(targetTable[i].innerHTML == "FAIL")
{
count_fail=count_fail+1;
}
}
document.getElementById("total").value = document.getElementsByTagName("table").length;
document.getElementById("pass").value = count_pass;
document.getElementById("fail").value = count_fail;
}
</script>
<style type="text/css">
body {
margin: 3px;
padding: 3px;
border: 1px solid #000000;
}
tr#steps{background-color: rgb(255, 255, 204);}
td { FONT-SIZE: 90%; MARGIN: 0px; COLOR: #000000;
FONT-FAMILY: font-family: Arial;
padding:1px; border:#4e95f4 1px solid;
height: 20px;
width:auto;
}
a {TEXT-DECORATION: none;}
table{text-align: left; margin-left: auto; margin-right: auto; width: auto; height: auto; font-family: Arial;
}
</style>
</head><body><br><div style="text-align: center; font-family: Arial;"><br>
<img style="width: 205px; height: 70px;" alt="http://www.google.com" title="http://www.google.com" src="src.png"><br>
<br><div style="text-align: right;"><small><small>
Total Test Case : <input id="total" type="text"><br><br>
Pass Test Case : <input id="pass" type="text"><br><br>
Fail Test Case : <input id="fail" type="text"><br><br><button onclick="Count_function()">count</button></small>
</small>
<br></div>
<br>
</div>
<table id="tc1" border="0" cellpadding="4" cellspacing="0">
<tbody>
<tr>
<td colspan="1" style="width: 36px; text-align: center;">tc1</td>
<td style="width: 339px; text-align: center;" colspan="1">TCname &nbsp;</td>
<td style="width: 99px; text-align: center;">Program</td>
<td style="width: 189px; text-align: center;">Sub Module</td>
<td style="width: 177px; text-align: center;" colspan="1">Module</td>
<td style="width: 95px; text-align: center;">PASS</td>
<td style="width: 125px; text-align: center;"><a href="javascript:toggle_visibility('tc1','l1');">
<div id="l1" align="right">[+]Expand</div></a></td>
</tr>
<tr id="steps">
<td colspan="2" rowspan="1" style="text-align: left; width: auto;">1.Step name</td>
<td style="text-align: center;">title<br></td>
<td style="text-align: center;">message</td>
<td style="text-align: center;"><br></td>
<td style="width: 95px; text-align: center;">Pass</td>
<td style="width: 125px;"></td>
</tr>
<tr id="steps">
<td colspan="2" rowspan="1" style="text-align: left; width: 339px;">2.&nbsp;Step name</td>
<td style="text-align: center;">title<br></td>
<td style="text-align: center;">mesage-</td>
<td style="text-align: center;"><a href="#"><br></a></td>
<td style="width: 95px; text-align: center;">Pass</td>
<td style="width: 125px;"></td>
</tr>
<tr id="steps">
<td colspan="2" rowspan="1" style="text-align: left; width: 339px;">3.&nbsp;Step name</td>
<td style="text-align: center;">title<br></td>
<td style="text-align: center;">message</td>
<td style="text-align: center;"><a href="#">screenshot</a></td>
<td style="width: 95px; text-align: center;">fail</td>
<td style="width: 125px;"></td>
</tr>
<tr id="steps">
<td colspan="2" rowspan="1" style="text-align: left; width: 339px;">4.&nbsp;Step name</td>
<td style="text-align: center;">title<br></td>
<td style="text-align: center;">message-</td>
<td style="text-align: center;"><a href="#"><br></a></td>
<td style="width: 95px; text-align: center;">Pass</td>
<td style="width: 125px;"></td>
</tr>
</tbody>
</table>
<table id="tc2" border="0" cellpadding="4" cellspacing="0">
<tbody>
<tr>
<td colspan="1" style="width: 36px; text-align: center;">tc2</td>
<td style="width: 339px; text-align: center;" colspan="1">TCname &nbsp;</td>
<td style="width: 99px; text-align: center;">Program</td>
<td style="width: 189px; text-align: center;">Sub Module</td>
<td style="width: 177px; text-align: center;" colspan="1">Module</td>
<td style="width: 95px; text-align: center;">PASS</td>
<td style="width: 125px; text-align: center;"><a href="javascript:toggle_visibility('tc2','l2');">
<div id="l2" align="right">[+]Expand</div></a></td>
</tr>
<tr id="steps">
<td colspan="2" rowspan="1" style="text-align: left; width: 339px;">1.Step name</td>
<td style="text-align: center;">title<br></td>
<td style="text-align: center;">message</td>
<td style="text-align: center;"><br></td>
<td style="width: 95px; text-align: center;">Pass</td>
<td style="width: 125px;"></td>
</tr>
</tbody></table>
<br>
<br>
<br>
<br>
<div style="text-align: center;"><a href="http://google.com">Contact Us | some ERP</a></div>
</body></html>

Wednesday, October 22, 2014

Selenium : Report Template


 Report Template


 

<HTML>
<HEAD>
<TITLE>Expandable and collapsible table - demo</TITLE>
<script type="text/javascript">

function toggle_visibility(tbid,lnkid) {
if (document.getElementsByTagName) {
  var tables = document.getElementsByTagName('table');
  for (var i = 0; i < tables.length; i++) {
   if (tables[i].id == tbid){
     var trs = tables[i].getElementsByTagName('tr');
     for (var j = 2; j < trs.length; j+=1) {
     trs[j].bgcolor = '#CCCCCC';
       if(trs[j].style.display == 'none')
          trs[j].style.display = '';
       else
          trs[j].style.display = 'none';
    }
   }
  }
 }
   var x = document.getElementById(lnkid);
   if (x.innerHTML == '[+] Expand ')
      x.innerHTML = '[-] Collapse ';
   else
      x.innerHTML = '[+] Expand ';
}
</script>

<style type="text/css">
td {FONT-SIZE: 75%; MARGIN: 0px; COLOR: #000000;}
td {FONT-FAMILY: verdana,helvetica,arial,sans-serif}
a {TEXT-DECORATION: none;}
</style>

</head>

<BODY>
    <table width="800" border="0" align="center" cellpadding="4" cellspacing="0" id="tbl1" name="tbl1">
        <tr><td height="1" bgcolor="#727272" colspan="3"></td></tr>
        <tr bgcolor="#EEEEEE"><td height="15" colspan="2"> <strong>Project name 1</strong></td>
            <td bgcolor="#EEEEEE"><a href="javascript:toggle_visibility('tbl1','lnk1');">
            <div align="right" id="lnk1" name="lnk1">[+] Expand </div></a></td></tr>
        <tr style="{display='none'}"><td colspan="3"><div align="left">Short summary which describes Project 1.</div></td></tr>
        <tr style="{display='none'}" bgcolor="#EEEEEE"><td width="70%">File Name</td><td width="15%">Size</td><td  width="15%"></td></tr>

            <tr style="{display='none'}"><td>Document 1 of the project 1.doc</td><td>209.5 KB</td><td><a href="#">Download</a></td></tr>
            <tr style="{display='none'}"><td colspan="3" bgcolor="#CCCCCC" height="1"></td></tr>

            <tr style="{display='none'}"><td>Document 2 of the project 1.doc</td><td>86 KB</td><td><a href="#">Download</a></td></tr>
            <tr style="{display='none'}"><td colspan="3" bgcolor="#CCCCCC" height="1"></td></tr>

            <tr style="{display='none'}"><td>Document 3 of the project 1.doc</td><td>325.5 KB</td><td><a href="#">Download</a></td></tr>
            <tr style="{display='none'}"><td colspan="3" bgcolor="#CCCCCC" height="1"></td></tr>

            <tr style="{display='none'}"><td height="1" bgcolor="#CCCCCC" colspan="3"></td></tr>
            <tr style="{display='none'}"><td height="1" bgcolor="#727272" colspan="3"></td></tr>

            <tr style="{display='none'}"><td height="8" colspan="3"></td></tr>
     </table>

    <table width="800" border="0" align="center" cellpadding="4" cellspacing="0" id="tbl2" name="tbl2">
        <tr><td height="1" bgcolor="#727272" colspan="3"></td></tr>
        <tr bgcolor="#EEEEEE"><td height="15" colspan="2"> <strong>Project name 2</strong></td>
            <td bgcolor="#EEEEEE"><a href="javascript:toggle_visibility('tbl2','lnk2');">
            <div align="right" id="lnk2" name="lnk2">[+] Expand </div></a></td></tr>
        <tr style="{display='none'}"><td colspan="3"><div align="left">Short summary which describes Project 2.</div></td></tr>
        <tr style="{display='none'}" bgcolor="#EEEEEE"><td width="70%">File Name</td><td width="15%">Size</td><td  width="15%"></td></tr>

            <tr style="{display='none'}"><td>Document 1 of the project 2.doc</td><td>209.5 KB</td><td><a href="#">Download</a></td></tr>
            <tr style="{display='none'}"><td colspan="3" bgcolor="#CCCCCC" height="1"></td></tr>

            <tr style="{display='none'}"><td>Document 2 of the project 2.doc</td><td>86 KB</td><td><a href="#">Download</a></td></tr>
            <tr style="{display='none'}"><td colspan="3" bgcolor="#CCCCCC" height="1"></td></tr>

            <tr style="{display='none'}"><td height="1" bgcolor="#CCCCCC" colspan="3"></td></tr>
            <tr style="{display='none'}"><td height="1" bgcolor="#727272" colspan="3"></td></tr>

            <tr style="{display='none'}"><td height="8" colspan="3"></td></tr>
     </table>
</body>
</html>

Sunday, October 12, 2014

Selenium : Interaction with Windows objects(Autoit)

Selenium : Read Webtable

Read Web-table



Code Here :

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class test_table {

 public static void main(String[] args) throws InterruptedException {
  WebDriver driver=new FirefoxDriver();
  driver.get("http://www.w3schools.com/html/html_tables.asp");
  String s="";
   
  
  int i,j;
  for( i=1;i<=5;i++){
   for( j=1;j<=4;j++)
   {
    System.out.println(i+" ,"+ j);
    if (i==1)
     s=s+" "+driver.findElement(By.xpath("//table[@class='reference']//tr["+i+"]//th["+j+"]")).getText(); 
    else
     s=s+" "+driver.findElement(By.xpath("//table[@class='reference']//tr["+i+"]//td["+j+"]")).getText();
   }
  s=s+"\n";
  }
  
  System.out.println(s);
 }

}
 


Wednesday, October 8, 2014

How to know if Reporter Fail has been logged

How to know if Reporter Fail has been logged



Declare a variable at the start of the vbs file (it should be outside all the function ie., global). And assign a value "true". In case of error insert "false" into it so that it can be visible when you are in different function.

Monday, September 1, 2014

Java: Relative path of the current working Project folder

Relative path of the current working Project folder

System.out.println((new File("")).getAbsolutePath());
 
-----------------OR -----------------
     File currDir = new File(".");
     String path = currDir.getAbsolutePath();
     System.out.println(path);
 

Tuesday, August 26, 2014

Java :Simple GUI (Button activating an Edit Field)

Java :Simple GUI (Button activating an Edit Field) 

Steps for creating new GUI :
  1. Make sure you have added Windows Builder Pro addin to your Eclipse
  2. Select the immediate parent location where you want to create a new GUI file.
  3. Rt click>new>other>Window Builder > Swing Designer >Select Application Window.
  4. Click on Next
  5. In Create application window give a Name in "Name"box.
  6. Click on Finish
Refer : http://catchbug.blogspot.in/2014/02/java-add-browse-button-to-gui.html

 // Use JDialog instead of JFrame for thread to pause until an event


Code for gui


import java.awt.EventQueue;
public class gui {

 JFrame frame;
 JButton btnNewButton ;
 JTextArea textArea;
 SpringLayout springLayout;
 JTextPane textPane;

// gui(){ initialize();}

public void initialize() {
 
 frame = new JFrame();
 frame.setBounds(100, 100, 450, 300);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 springLayout = new SpringLayout();
 frame.getContentPane().setLayout(springLayout);
 
 btnNewButton = new JButton("New button");
 springLayout.putConstraint(SpringLayout.NORTH, btnNewButton, 113, SpringLayout.NORTH, frame.getContentPane());
 springLayout.putConstraint(SpringLayout.WEST, btnNewButton, 132, SpringLayout.WEST, frame.getContentPane());
 frame.getContentPane().add(btnNewButton);
 
 textPane = new JTextPane();
 textPane.setText("Hi");

 btnNewButton.addActionListener(new ActionListener(){ 
  public void actionPerformed(ActionEvent e){ 
   
   if(textPane.isDisplayable()==false){
    frame.getContentPane().add(textPane); 
    springLayout.putConstraint(SpringLayout.NORTH, textPane, 31, SpringLayout.SOUTH, btnNewButton);
    springLayout.putConstraint(SpringLayout.WEST, textPane, 148, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, textPane, 248, SpringLayout.WEST, frame.getContentPane());
   }
   else    
    frame.getContentPane().remove(textPane);
 
    frame.validate();
    frame.repaint();
 
   }});

}
}
Code calling GUI
 class Test {

  public static void main(String[] args) {

   gui obj=new gui();
   obj.initialize();
   obj.frame.setVisible(true);
     }

Saturday, August 23, 2014

Selenium : Selenium WebDriver And Interface

 WebDriver And Interface






Q. What Is An Interface And Why To Use It?

Interface is set of rules for behavior of application. Interface looks like class but it is not. When you implements that Interface In any class then all those Interface rules must be applied on that class.
 In short, if you implement an Interface on class then you must have to override all the methods of Interface In your class. Interface will create Rules to follow structure for class where it Is Implemented. This way, if you look at the code of Interface, You can get Idea about your program business logic. When you are designing big architecture applications like selenium web driver, you can use Interface to define business logic at Initial level.
 Interface can be implemented with any class using implements keyword. There are set of rules to be followed for creating an Interface. Let me tell you all these rules first and then give you an example of an Interface.

1.       Interface can not hold constructor.
2.       Interface can not hold instance fields/variables.
3.       Interface can not hold static methods.
4.       You can not instantiate/create object of an Interface.
5.       Variables Inside Interface must be static and mandatory to initialize the variable.
6.       Any class can Implement Interface but can not extend Interface.
7.       Can write body less methods Inside Interface.
8.       By default all the methods and variables of Interface are public so no need to provide access modifiers.

public interface College {        //Interface file
     static String Collegename = "XYZ";  //static by default
     void StudentDetails();    //Created non static methods without body.
     void StudentResult();
}

public class Computer implements College {
                                        //@Override annotation describes that methods are overridden on interface method.
                                         //Methods name, return type are same as methods of an Interface.
     @Override
     public void StudentDetails() {  System.out.println("hi"); }

     @Override
     public void StudentResult() { System.out.println("bye");  }
}

public class TestCollege
{                  //Class file. No need to implement Interface.

                    public static void main(String[] args)
{
                                         //Can access Interface variable directly using Interface name.
                                        System.out.println(College.Collegename+" Collage student details.");
 
                                                            //Created Computer class object with reference of interface College.
                                        College compdept = new Computer();
                                                            //Methods will be called from Computer class.
                                        compdept.StudentDetails();
                                        compdept.StudentResult();
 }
}
-------------------------------------------------------------------------------------------------------------------------
Selenium WebDriver And Interface

Simple example of Interface In selenium WebDriver Is WebDriver Interface. When you are Initializing any browser using selenium WebDriver, You are writing statements like bellow.

WebDriver driver = new FirefoxDriver();
Or
WebDriver driver = new ChromeDriver();

You can view more examples of selenium WebDriver on THIS PAGE.Here, WebDriver Is Interface and FirefoxDriver and ChromeDriver are the class files where WebDriver Interface Is Implemented.

http://software-testing-tutorials-automation.blogspot.in/2014/04/interface-in-java-tutorials-for.html

Wednesday, August 20, 2014

BASIC HTML FOR TESTING SELENIUM - SOURCE CODE

 BASIC HTML FOR TESTING SELENIUM - SOURCE CODE

app link -
http://catchbug.blogspot.in/2014/08/basic-html.html




<!—This is a comment  -   ref http://www.ironspider.ca/basic_html/structure.htm-->
<html>
<head>
               <title> My Home Page </title>
</head>
<body>
               HELLO WORLD!
<br>
<br>
               EDIT FIELD
               <input type="text" name="firstname">
<br>
<br>
               CHECKBOX
               My favourite colors are:<br><br>
               <input type="checkbox" name="color" value="red">Red<br>
               <input type="checkbox" name="color" value="yellow">Yellow<br>
<br>
<br>
               RADIO BUTTON
               Your current web browser is:<br><br>
               <input type="radio" name="browser" value="IE" checked>Internet Explorer<br>
               <input type="radio" name="browser" value="Mozilla">Mozilla<br>
<br>
<br>
               DROP DOWN
               I like my coffee:<br><br>
               <select name="coffee">
               <option value="black">Black</option>
               <option value="cream" selected>With cream</option>
<br>
<br>
               BUTTON
               <input type="submit" value="Submit Information">
<br>
<br>
               TABLE
<table border="5">
   <tr>     <td>Row 1, Cell 1</td>                    <td>Row 1, Cell 2</td>     </tr>
   <tr>     <td>Row 2, Cell 1</td>                    <td>Row 2, Cell 2</td>     </tr>
</table>
</body>
</html>