Friday, November 21, 2014

Vbs: Reflection in vbs or Converting String into Function Name

  Reflection in vbs or Converting String into Function Name



Output:
tc1
tc2

SQL :Important Queries

SQL Server : Important Queries


1.To display all tables in a database
SELECT * FROM information_schema.tables
 
2. To display table information
 sp_help table_name

Tuesday, November 18, 2014

TestComplete : UserForms

TestComplete : UserForms





Dim sPath,sBrowser,oDialog,form,mr

sub a
    Set form = UserForms.UserForm1
    Set oDialog = form.OpenDialog1        
     
      do
        mr=form.ShowModal     'Show GUI
        Select Case mr
            Case mrOK          'Ok button , In properties set the ModalResult as mrOK 
           
                   if( (form.cxRadioGroup1.ItemIndex=0 or form.cxRadioGroup1.ItemIndex=1) and sPath<>"" )then
                      if(form.cxRadioGroup1.ItemIndex=0) then
                        sBrowser="FireFox"
                        else
                        sBrowser="IE"
                      end if   
                      exit do
                   end if
                             
            Case mrCancel     'Cancel Button .'Ok button , In properties set the ModalResult as mrCancel      
                  exit sub
                     
             Case mrYes         'BrowserButton , In properties set the ModalResult as mrYes
                     oDialog.Execute           'Trigger TOpenBrowser
                     sPath=oDialog.FileName
                     form.Path.Text=sPath
      End Select
    Loop  While (1<2)
   
    msgbox("Browser="&sBrowser&vblf&"File Path="&sPath)
     
end sub

Saturday, November 15, 2014

Android : Cannot resolve android (Android Studio error)

Cannot resolve android  (Android Studio error)


Make sure you have Andoid SDK in your system :

1- press ctrl+alt+shift+s
2-in the Modules bar click on your project name
3-change the compile sdk version to the newest one
4-click apply and ok then sync your project
5-done , i hope the best for you

Thursday, November 13, 2014

Eclipse: Paste Multiline String

Paste Multiline String


Eclipse has an option so that copy-paste of multi-line text into String literals will result in quoted newlines:


Preferences/Java/Editor/Typing/  enable Escape text when pasting into a string literal"



Wednesday, November 12, 2014

Selenium : Eclipse (java) relative path

Eclipse (java) relative path



Example  1:
String filePath = ".\\images\\NotSet_16x16.png";

Example 2 :
If I have a project with following structure and want to reach excel file "excel.xls" as below .


Project_test
        |
        |
         --- src
            |
            |
             ---com (this is a package)
                |
                |
                ---    library (this is a package)
                    |
                    |
                    ---excel.xls



Path=".\\src\\com\\library\\excel.xls"


where «.\» is a root for Eclipse project, «images» is a folder with user's files inside of Eclipse project. Since we are talking about Windows OS, we have to use «\» and not «/», like in Linux, but «\» is the reserved symbol, so we have to type «\» to get desired result.

Monday, November 10, 2014

Selenium : 2D listin Java

2D list in Java

 

// Create an ArrayList of ArrayLists of Integers
ArrayList<ArrayList<Integer>> my2DArrayList = new ArrayList<ArrayList<Integer>>();
// add in a few ArrayLists. These contain the "rows" of the 2D ArrayList
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
// you can retrieve rows using get(), then treat that 1D arrayList as the column.
my2DArrayList.get(0).add(1);
my2DArrayList.get(0).add(2);
my2DArrayList.get(1).add(3);
my2DArrayList.get(1).add(4);
my2DArrayList.get(1).add(0);
my2DArrayList.get(2).add(5);
// my2DArrayList now contains this:
// row 0: 1, 2
// row 1: 3, 4, 0
// row 2: 5
// to retrieve a specific element, you need to first get the ArrayList of the row you want, then retrieve the column from that arraylist you want
// get element at row 1 and column 2
int number = my2DArrayList.get(1).get(2);


Friday, November 7, 2014

Selenium : TestNg Dataprovider with DependsonMethod

TestNg Dataprovider with DependsonMethod

public class testng {
       
    @DataProvider
        public Object[][] dp() {
          Object[][] o=new Object[2][2];
          o[0][0]="a";
          o[0][1]="b";
          o[1][0]="c";
          o[1][1]="d";
          return o;
        }
   
    @Test()
    public void a1()
    {
        System.out.println("byei");
    }
   
    @Test(dependsOnMethods= { "a1" },dataProvider="dp")
    public void a2(String a,String b)
    {
        System.out.println(a+b);
    }   
}

 

Output 

byei
ab
cd

Selenium : Retrieve Method information in Testng DataProvider

Retrieve Method information in Testng DataProvider


If you declare your @DataProvider as taking a java.lang.reflect.Method as first parameter, TestNG will pass the current test method for this first parameter. This is particularly useful when several test methods use the same @DataProvider and you want it to return different values depending on which test method it is supplying data for.

For example, the following code prints the name of the test method inside its @DataProvider:

@DataProvider(name = "dp")
public Object[][] createData(Method m) {
  System.out.println(m.getName());  // print test method name
  return new Object[][] { new Object[] { "Cedric" }};
}

@Test(dataProvider = "dp")
  public void test1(String s) {
}

@Test(dataProvider = "dp")
  public void test2(String s) {
}


and will therefore display:

test1
test2

Selenium:TestNG factory class with example

TestNG factory class with example 

 http://roadtoautomation.blogspot.in/2014/08/testng-factory-class-with-example.html


@DataProvider is used to pass different test data to a test method
@Factory is used to create different instance of Test class and is useful annotation when you run test multiple time.
you can find examples with description for both at : http://testng.org/doc/index.html


DataProvider Example:

public class DataProviderDemo {

    @DataProvider(name="myDataProvider")
    public Object[][] data(){
        return new Object[][]{ {"adf",5.0f}, {"dfds",4.0f} };
    }
    
    @Test(dataProvider="myDataProvider")
    public void method1( String strData ,float floatData){
        Reporter.log("String "+strData);
        Reporter.log("float "+floatData);
    }
  
}


Factory Example:

public class FactoryDemo {
   
    String strData;
    float floatData;
   
    public FactoryDemo(String string, float f){    
        strData = string;
        floatData = f;      
    }
   
    @Factory
    public static Object[] data(){
        return new Object[]{  new FactoryDemo("adf",5.0f),  new FactoryDemo("dfds",4.0f)   };
    }
      
    @Test()
    public void method1(){
        Reporter.log("String "+strData);
        Reporter.log("float "+floatData);
    }  
}

Selenium : Using 2 Dataproviders in single test

Selenium : Using 2 Dataproviders in single test


public class testng {
 
 public Object[][] dp1() {
    return new Object[][] {new Object[] { "a", "b" },new Object[] { "c", "d" } };
  }

  public Object[][] dp2() {
    return new Object[][] {  new Object[] { "e", "f" },new Object[] { "g", "h" } };
  }

  @DataProvider
  public Object[][] dp() {
    List result = Lists.newArrayList();
    
    result.addAll(Arrays.asList(dp1()));
    result.addAll(Arrays.asList(dp2()));
    return result.toArray(new Object[result.size()][]);
    
  }

  @Test(dataProvider = "dp")
  public void f(String a, String b) {
    System.out.println( a + " " + b);

  }

}//

Selenium : Testng not running Test Cases

Selenium : Testng not running Test Cases


In the below screenshot , the Testng will executethe test case "m1 ()"



The problem is that all the methods which use Testng annotationsshould be declared " public "  by default :


Tuesday, November 4, 2014

Selenium:Create firefox profile with addons and preferences

Selenium:Create firefox profile with addons and preferences

 

Note : If you already have a profile with Firebug added then use :
System.setProperty("webdriver.firefox.profile", "default");
//to find profile name - Start>Run >firefox -ProfileManager

1. Close all firefox instances ,verify the same if any firefox instance is running in the task manager.
2. Goto Start>Run and type "firefox -ProfileManager"
3. click "OK"
4. Firefox "Choose profile" should open.
5. Click on "Create Profile"button.
6. Click on next button in following screen
7. Enter profile name in the next screen and choose the path where you want to save it (ex. D:\profile)
8. Click on finish.
9.  Now uncheck "use the selected profile without asking at startup"
10. Select the profile which has been created .
11 click on "Start firefox ".

Now the firefox will be open with the selected profile.

12. Do required settings and add any addons needed and restart firefox.
13. Now when firefox opens check "use the selected profile without asking at startup"
14. Select default profile.
15 Click on "Start Firefox".


In your Selenium use the below code :

File profileDir = new File("D:\\profile");  //("path/to/top/level/of/profile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setPreferences(extraPrefs);
WebDriver driver = new FirefoxDriver(profile);

Sunday, November 2, 2014

Selenium :Sikuli for 64Bit JRE- Solution

Selenium :Sikuli for 64Bit Machine - Solution


If you are using Sikuli for the first time please refer the below link (once done we will port it to 64Bit)  :



Porting for 64Bit :
  1.   Download and install 32Bit JRE (http://filehippo.com/download_jre_32/3868/) .Make sure JRE 6 is installed in a different location to avoid conflicts.
  2. Open Eclipse and configure the following
a)      Project ---> Properties ---> Java Compiler : set compliance level and Source compatibility to 1.6
b)       Project ---> Properties ---> Java Build Path ---> Libraries ---> and change the JRE system library to 1.6
  1. Project ---> Java Build Paths--->Libraries--->Add Library--->Select Jre System Library
a)      Click Next
b)      Select Alternate JRE Radio button in JRE System Library Screen
c)      Click on Installed JREs
d)     In Prefrences window , Click on Search Button
e)      In search window , Select the Parent folder where Java6 is installed(“C:\Program Files (x86)\Java”)    .
f)       Click on OK
  1. Now Jre6 will be added to your Installed JREs window
  2. Now check “jre6” as default and close .
  3. Now check whether JRE6 has been added to your current project.

Now run your SIKULI script to check if the same is working .. .

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);
     }