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.