Wednesday, April 24, 2013

Selenium : Reverse each word of a sentence

Reverse each word of a sentence

import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class Reverse_words_sentence {
 public static void main(String[] args)
 {
  String sStr=JOptionPane.showInputDialog("Enter a string");
  String[] sArr=StringUtils.split(sStr, " ");
  String sRes;

  for (int i=0 ;i<=sArr.length-1;i++)
  {
   sArr[i]=StringUtils.reverse(sArr[i]);
  }
  sRes=StringUtils.join(sArr, " ");
  System.out.print(sRes);
 }
}

Selenium :Reverse a String without using builtin Functions

Reverse a String without using builtin Functions

import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class Reverse_str
{
 public static void main(String[] args)
 {
  String sStr=JOptionPane.showInputDialog("Enetr a str");
  String sRes="";
  for (int i=sStr.length() ;i>=0;i--)
  {
   sRes=sRes+StringUtils.mid(sStr, i, 1);
  }
  System.out.print(sRes);
 }


}


Tuesday, April 23, 2013

Selenium : To find the length of the string withouth using "Length " function

 To find the length of the string withouth using "Length " function



import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class Len_of_string
{

 public static void main(String[] args)
 {
  String sStr= JOptionPane.showInputDialog("enter string");
  char[] sArr=sStr.toCharArray();
  System.out.print(sArr.length);
 }

}

Selenium : Extract only digits from a string ( try ....catch )

                                                Extract only digits from a string


import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class extract_digits
{

 public static void main(String[] args)
 {
 String sStr=JOptionPane.showInputDialog("Enter any string with Digit");
 String sRes="";
 int sTemp;

 for (int i=1 ; i<=sStr.length();i++)
 {
   try
   {
     sTemp=Integer.parseInt(StringUtils.mid(sStr, i, 1));//substring(sStr, 1, end)
     sRes=sRes+"\n"+sTemp;
   
   }catch (Exception  e)
   { 
   }
 }

 System.out.println(sRes);

}
}



Friday, April 19, 2013

Selenium : Program To display each Character seperatly from a string


 Program To display each Character seperatly from a string


import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class Display_each_char
{

 public static void main(String[] args)
 {
  String sStr=JOptionPane.showInputDialog("Enetr some data");

  for (int i=0 ;i<= sStr.length();i++)
  {
   System.out.println(StringUtils.mid(sStr, i, 1));
  }
  

 }
}
 

Selenium : To find substring inside a string

To find substring inside a string



import javax.swing.JOptionPane;
public class Substring_in_string
{
 public static void main(String[] args)
 {

  String sData1=JOptionPane.showInputDialog("enter a string data");
  String sData2=JOptionPane.showInputDialog("enter a sub string data");
  if (sData1.contains(sData2) == true)
  {
  System.out.print("The substring exits ");
  }
  else
  {
   System.out.print("The substringdoes not exits ");
  }
 }
}

Thursday, April 18, 2013

Selenium : Find occurence of last "/" in an URL without using string reverse function(built in function)

 

 Find occurence of last "/" in an URL without using string reverse function(built in function)



import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
public class url_bkslah_nrev
{
 public static void main(String[] args)
 {
  String sUrl=JOptionPane.showInputDialog("enter Url");
  Boolean bFlag=false;
  int i;

  for( i=sUrl.length()-1; i>=0 ; i--)  // Do if true until false
  {
   if (StringUtils.mid(sUrl, i, 1).charAt(0) == "/".charAt(0)) //converting to character
   {
    bFlag=true;
    break;
   }
  }

  if (bFlag=true)
  {
   System.out.print("/ exists at "+(i+1));
  }
  else
  {
   System.out.print("/ not exists");
  }

 }
//1/3/56/'
}

Selenium : Find the last occurence of "/" in the URL

                                    Find the last occurence of "/" in the URL



import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class url_backslash
{

 public static void main(String[] args)
 {
  String sUrl=JOptionPane.showInputDialog("enter url");
  Boolean bFlag=false;
  int i;
  String sReverse=StringUtils.reverse(sUrl);
  for ( i=0 ;i<=sUrl.length()-1;i++)
  {
   //if (Character.toString(sReverse.charAt(i)) ==  "/")  //Convert character to string
   if (sReverse.charAt(i)== "/".charAt(0))
   {
    bFlag=true;
    break;
   }
  }

  if ( bFlag = true )
  {
   System.out.print("the last '/' exists @ "+(sUrl.length()- i));
  }
  else
  {
   System.out.print("/ does not exists");
  }
 }

}
 

Timeout : Interesting Article - Ebola Zaire

Good read



One of my friend after watching some horror,thriller,psycho movie asked to me check out this link.Which I found interesting in the beginning and disgusted at the end but surely not boring.

Not for the faint hearted..

Wednesday, April 17, 2013

Selenium : Display data in right angle triangle with side towards right

Display data in right angle triangle with side towards right


I have used "StringUtils.leftPad"  which is present inside " org.apache.commons.lang3.StringUtils; "

1. Download common/common-lang3.jar.zip( 613 k) from http://www.java2s.com/Code/Jar/c/Downloadcommonlang3jar.htm

2.Extract Jar files and the files to your Package in Eclipse.


 import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
public class Triangle_right
{
 public static void main(String[] args)
 {
  String sRes="";
  String sData=JOptionPane.showInputDialog("enter data");
  for (int i=1 ; i<=sData.length();i++)
  {
   sRes=sRes+StringUtils.leftPad( sData.substring(0, i), sData.length())+"\n";    
  }
  System.out.print(sRes);
 }
}

Selenium :Display data in form of triangle in reverse

 Display data in form of triangle in reverse



import javax.swing.JOptionPane;

public class display_data_tri2
{

 public static void main(String[] args)
 {
    String sRes="";
    String sData=JOptionPane.showInputDialog("enter data");
    for (int i=sData.length() ;i>=1;i--)
    {
     sRes=sRes+sData.substring(0, i)+"\n";    
    }
    System.out.print(sRes);
  } 
}
 

Selenium : To display data in the form of right angled triangle


 To display data in the form of right angled triangle


import javax.swing.JOptionPane;
public class Triangle_left
{
 public static void main(String[] args)
 {
  String sRes="";
  String sData=JOptionPane.showInputDialog("enter data");
  for (int i=1 ; i<=sData.length();i++)
  {
   sRes=sRes+sData.substring(0, i)+"\n";    
  }
  System.out.print(sRes);
 }
}
 

Selenium :Search a String in a 2D array


Search a String in a 2D array



import javax.swing.JOptionPane;

public class Search_str_arr
{

 public static void main(String[] args)
 {

  String arr_String[][]=new String[3][3];

  for (int i=0 ;i<=2 ;i++)
  {
   for (int j=0;j<=2;j++ )
   {
    arr_String[i][j]=JOptionPane.showInputDialog("Enter string for arr_String["+i+"]["+j+"]");
   }
  }

  String sData=JOptionPane.showInputDialog("Enter Data to be searched");
  Boolean bFlag=false;

  for (int i=0 ;i<=2 ;i++)
  {
    for (int j=0;j<=2;j++ )
    {
     if (arr_String[i][j]==sData)
     {
      bFlag=true;
     }
    }
  
   if (bFlag=true)
   {
    break ;
   }   
  }

  if (bFlag=true)
  {
  System.out.println("the data exists");
  }
  else
  {
   System.out.println("the data does not exist");
  }
   
 }

}

Tuesday, April 16, 2013

Selenium :Transpose of Matrix

                                                    Transpose of Matrix



public class Transpose_Matrix
{
 /**
  * @param args
  */
 public static void main(String[] args)
 {
  String sRes="";
  int aArray[][]=new int [3][3];
  aArray[0][0]=0;
  aArray[0][1]=0;
  aArray[0][2]=0;

  aArray[1][0]=1;
  aArray[1][1]=1;
  aArray[1][2]=1;

  aArray[2][0]=2;
  aArray[2][1]=2;
  aArray[2][2]=2;


  for (int i=0 ; i<=aArray.length-1 ;i++)
  {
   for (int j=0;j<=aArray[0].length-1;j++)
   {
    sRes=sRes+" "+aArray[i][j];
   }
   sRes=sRes+"\n";
  }
  System.out.println(sRes);
  sRes="";
  //-----------------------------------------Method 1 
  for (int j=0;j<=aArray[0].length-1;j++)

  {
   for (int i=0 ; i<=aArray.length-1 ;i++)
   {
    sRes=sRes+" "+aArray[i][j];
   }
   sRes=sRes+"\n";
  }
  System.out.println(sRes);
  sRes="";
  //-----------------------------------------Method 2
  for (int i=0 ; i<=aArray.length-1 ;i++)
  {
   for (int j=0;j<=aArray[0].length-1;j++)
   {
    sRes=sRes+" "+aArray[j][i];
   }
   sRes=sRes+"\n";
  }
  System.out.println(sRes);
 }
}

Selenium :Print Array 3X3 in the form of Matrix

Print Array 3X3  in the form of Matrix



public class Print_array_in_matrix
{
 public static void main(String[] args)
 {
  String sRes="";
  int aArray[][]=new int [3][3];
  aArray[0][0]=0;
  aArray[0][1]=0;
  aArray[0][2]=0;

  aArray[1][0]=0;
  aArray[1][1]=0;
  aArray[1][2]=0;

  aArray[2][0]=0;
  aArray[2][1]=0;
  aArray[2][2]=0;


  for (int i=0 ; i<=aArray.length-1 ;i++)
  {
   for (int j=0;j<=aArray[0].length-1;j++)
   {
    sRes=sRes+" "+aArray[i][j];
   }
   sRes=sRes+"\n";
  }
  System.out.print(sRes);
  
 }
}


Selenium :To find Factorial of a number



To find Factorial of a number



import javax.swing.JOptionPane;
public class Factorial
{
 public static void main(String[] args)
 {
  int iRes=1;
  String sPict="1";
  int ifact=Integer.parseInt(JOptionPane.showInputDialog("enter an integer"));

  for (int i=2 ; i<=ifact ; i++)
  {
   iRes=iRes*i;
   sPict=i+"x"+sPict;
  
  }
  System.out.println(sPict+"="+iRes); 
 }
}

Monday, April 15, 2013

Selenium : Accept Array and print in Reverse order

Array in Reverse order



public class Array_Reverse
{
 public static void main(String[] args)
 {
  int aArray[]= new int[2];//  2 means not 2+1 --> aArray[0] , aArray[1]
  for (int iSize=0 ; iSize<=aArray.length-1 ; iSize++)
  {
   aArray[iSize]=Integer.parseInt(JOptionPane.showInputDialog("Enter value for aArray["+iSize+"]" ));
  }
  //System.out.println(aArray[0]);

  int iSize=aArray.length-1;
  for ( iSize=aArray.length-1 ; iSize>=0 ; iSize--) //"iSize>=0 "Execute if true till false
  {
   System.out.println("aArray["+iSize+"]="+aArray[iSize]);
  }
 
  for ( iSize=0 ; iSize<=aArray.length-1 ;iSize++ )// Execute if true till false
  {
   System.out.println(aArray[iSize]);
  }
 
  System.out.println("Done"); 

 }
}

Selenium : To check whether the given number is prime

To check whether the given number is prime


import javax.swing.JOptionPane;

public class Prime {
 public static void main(String[] args)
 {
  boolean bFlag=true;
  int iVar=Integer.parseInt(JOptionPane.showInputDialog("Enter an integer value"));
  for (int i=2 ; i<=iVar/2 ; i++)
  {
   if (iVar%i == 0)
   {
    System.out.print("The number is not prime");
    bFlag=false;
    break ;
   } 
 
  }
  if( bFlag == true )
  {
   System.out.print("The number is prime");
  }   
 }
}

Selenium : Size of Matrix or 2D array

 Calculate Size of Matrix or Size of 2D Array


public class Size_Matrix {
 public static void main(String[] args)
 {
  int[][] matrix = new int[20][30];
  System.out.println("Number of rows = " + matrix.length);
  System.out.println("Number of columns = " + matrix[0].length);
 }

Selenium : Units of Electricity bill

Calculate Units of Electricity bill

0-50      -> $.5/Unit
50-100  ->$1.5/Unit
100-200->$2 /unit
150-200->$3/Unit
>200    ->  $4/unit


import javax.swing.JOptionPane;

public class Electricity
{
 public static void main(String[] args)
 {
  int iUnit=Integer.parseInt(JOptionPane.showInputDialog("Enter units consumed"));

  if (iUnit<= 50) // ex 30 unit ==$0.5
  {
   System.out.print("Pay ="+"$.5");
 
  }
  else if (50  < iUnit && iUnit <=100 )  //Eg 70 Unit = 30.5
  {
   System.out.print("Pay =$"+(.5+(iUnit-50)*1.5));
  }
  else if (100  < iUnit && iUnit <=150 ) //Eg 120 Unit = 115.5
  {
   System.out.print("Pay =$"+( ((iUnit-100)*2) + ((50*1.5)) +(.5)));
  }
  else if (150  < iUnit && iUnit <=200 ) //Eg 170 Unit =$235.5
  {
   System.out.print("Pay =$"+((iUnit-150)*3+(50*2)+(50*1.5)+.5));
  }
  else if (iUnit >200 )  //Eg 210 units
  {
   System.out.print("Pay =$"+((iUnit-200)*4+(50*3)+(50*2)+(50*1.5)+.5));
  }
 }
}




Saturday, April 13, 2013

Selenium :Connect to an Excel Spreadsheet using JDBC in Java


Connect to an Excel Spreadsheet using JDBC in Java



This tutorial will show you how to connect to and read data from an Excel spreadsheet using JDBC.

To start, we need to setup the local ODBC connection.

Navigate to your computers Control Panel and locate the Administrative Tools.



Once in the Administrative Tools section, locate Data Sources (ODBC)



The ODBC Data Source Administor menu will open



Select the System DSN tab and click Add

Find Driver do Microsoft Excel(*.xls) from the list and click Finish

Give the Data Source Name & Description



Next, click Select Workbook and locate the spreadsheet you wish to use



In this case, we are using worcester.xls. Select it and click OK.

Click OK again to exit the setup. The ODBC connection is now complete.

Now that the ODBC connection is setup, its time for the Java code.


Note :1st Row in Excel is considered as column header 

-------------------------------------------------------------------
import java.sql.*;
public class Connect_Xl_using_JDBC
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:worcester");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from [Sheet1$]");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
System.out.println("Columns="+numberOfColumns);

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

------------------------------------------------------



Friday, April 12, 2013

Selenium: Find greatest of 3 nos

 Find the greatest of 3 nos



import javax.swing.JOptionPane;

public class Greatest_of_3_nos
{

 public static void main(String[] args)
 {
  int a,b,c;
  a=Integer.parseInt( JOptionPane.showInputDialog("Enter an value of a"));
  b=Integer.parseInt(JOptionPane.showInputDialog( "Enter an value of b"));
  c=Integer.parseInt(JOptionPane.showInputDialog( "Enter an value of c"));

  if (a > b && a > c)
  {
   System.out.print(a+" is the greatest");
  }
  else if  (c > b && a < c)
  {
   System.out.print(c+" is the greatest");
  }
  else
  {
   System.out.print(b+" is the greatest");
  }

 }
} 

Selenium : To calculate age of a person

                                                    To calculate age of a person



import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;

public class Calculate_age
{
 public static void main(String[] args)
 {
  Date oDt=new Date();
  int iYear=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter birth year"));
  JOptionPane.showMessageDialog(null,(oDt.getYear()+1900)- iYear);  
 }
}
 

Selenium : Validate voters age

Program to check the age of user


import javax.swing.JOptionPane;
public class Vote_eligible {
 public static void main(String[] args)
 {
  int iAge=Integer.parseInt(JOptionPane.showInputDialog("enter age"));
  if (iAge>= 18)
  {
   JOptionPane.showMessageDialog(null, "Voter is above or equal to 18 years ,Elibible to vote");
  }
  else
  {
   JOptionPane.showMessageDialog(null, "Voter not eligible to vote");
  }   

 }
}

Selenium:Get Month Name (Using Select Case and Array)

 Display Current Month Name using Array and Select Case




import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


public class Month_Name
{

 public static void main(String[] args)
 {
  Date dt=new Date();
  System.out.println(dt.getMonth());

  String Month_Name[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

  switch (dt.getMonth())//(c.MONTH+1)
  {
  case 0:
   System.out.println(Month_Name[0]);
   break;
  case 1:
   System.out.println(Month_Name[1]);
   break;
  case 2:
   System.out.println(Month_Name[2]);
   break;
  case 3:
   System.out.println(Month_Name[3]);
   break;
  case 4:
   System.out.println(Month_Name[4]);
   break;
  case 5:
   System.out.println(Month_Name[5]);
   break;
  case 6:
   System.out.println(Month_Name[6]);
   break;
  case 7:
   System.out.println(Month_Name[7]);
   break;
  case 8:
   System.out.println(Month_Name[8]);
   break;
  case 9:
   System.out.println(Month_Name[9]);
   break;
  case 10:
   System.out.println(Month_Name[10]);
   break;
  case 11:
   System.out.println(Month_Name[11]);
   break;
 
  }

 }

}
 

Tuesday, April 9, 2013

Selenium :Extracting Date from input string or putting date in particular format

                           Accepting String calender data and extracting date



import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//to create a SimpleDateFormat object and use it to parse Strings to Date and
//to format Dates to Strings. If you've tried SimpleDateFormat and it didn't work, then please show your code and any errors you may receive.
//
//Addendum: "mm" in the format String is not the same as "MM". Use MM for months and mm for minutes. Also, yyyyy is not the same as yyyy.

public class Changing_Date_Format
{

 public static void main(String[] args) throws ParseException
 {
  String date_s = "2011-01-18 00:00:00.0";

        // *** note that it's "yyyy-MM-dd hh:mm:ss" not "yyyy-mm-dd hh:mm:ss" 
        SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date = dt.parse(date_s); //Converting String to Date

        // *** same for the format String below
        SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(dt1.format(date));

 }
}

Selenium : Date

To Demonstrate date function



import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


public class Month_Name
{

 public static void main(String[] args)
 {
  Date dt = new Date();
  System.out.print(dt.toString());
  System.out.println(dt.getMonth()+":"+dt.getDate()+":"+dt.getYear());

  Calendar c = new GregorianCalendar();
  System.out.println(c.getTime());
  System.out.println(c.DATE+"/"+c.MONTH+"/"+c.YEAR);
 }

}

Selenium : Datatype Conversions

 Datatype Conversions

 //To demonstrate DataType conversions



public class Convert_2_int
{

 public static void main(String[] args)
 {
  String s="123";
  int a=Integer.parseInt(s);
  Float b=Float.parseFloat(s);
  System.out.println(a);
  System.out.println(b);
 }

}

Selenium : Basic arithematic operations and Insert Spaces

Basic arithematic operations



//To demonstrate the use of all arithematic operators
//Inserts 2 spaces   -     String.format("%2s","")

public class All_Arithematic_Operators
{

 public static void main(String[] args)
 {
  System.out.println(1+2);
  System.out.println(1-2);
  System.out.println(1/2);
  System.out.println(1*2);
  System.out.println(Math.sqrt(2));

  int a=1,b=2;
  if (a==1 && b==2 )
  {
   System.out.println("a==1 && b==2"+String.format("%2s","")+"true --a="+a+" b="+b);//Insert spaces
  }
  if (a!=2 || b!=1 )
  {
   System.out.println("a!=2 || b!=1"+String.format("%2s","")+"true --a="+a+" b="+b);//Insert Spaces
  }

  if (a < b)
  {
   System.out.println("a < b"+String.format("%2s","")+"true --a="+a+" b="+b);//Insert Spaces
  }
  if (a <= b)
  {
   System.out.println("a <= b"+String.format("%2s","")+"true --a="+a+" b="+b);//Insert Spaces
  }

 }

}

Thursday, April 4, 2013

Selenium : Get and Set

Selenium : Get and Set


This would probably help

Selenium : Initialising Objects

Initialising Objects

Example to open the browser and click on the Search button .


public class Test
{
 public static void test1() 
 {
  FirefoxDriver oFx=new FirefoxDriver ();   
  EventFiringWebDriver oEvent=new EventFiringWebDriver(oFx);
  oEvent.get("
http://www.google.co.in/");
  Thread.sleep(1000);

  WebElement oButton=oEvent.findElement(By.id("gbqfbb"));  //Object initialising
  oButton.click();
  System.out.print("Fin");

  oEvent.close();
  oEvent.quit();
}
}

Selenium : Verify element - 1. ispresent 2. isvisible 3. isenable 4. textpresent

Selenium : Verify element - 1. ispresent 2. isvisible 3. isenable 4. textpresent


  1. To check Element Present:
    if(driver.findElements(By.xpath("value")).size() != 0){
    System.out.println("Element is Present");
    }else{
    System.out.println("Element is Absent");
    }
    
    Or
    if(driver.findElement(By.xpath("value"))!= null){
    System.out.println("Element is Present");
    }else{
    System.out.println("Element is Absent");
    }
    
  2. To check Visible:
    if( driver.findElement(By.cssSelector("a > font")).isDisplayed()){
    System.out.println("Element is Visible");
    }else{
    System.out.println("Element is InVisible");
    }
    
  3. To check Enable:
    if( driver.findElement(By.cssSelector("a > font")).isEnabled()){
    System.out.println("Element is Enable");
    }else{
    System.out.println("Element is Disabled");
    }
    
  4. To check text present
    if(driver.getPageSource().contains("Text to check")){
    System.out.println("Text is present");
    }else{
    System.out.println("Text is absent");
    }
  5. WebElement rxBtn = driver.findElement(By.className("icon-rx"));
    WebElement otcBtn = driver.findElement(By.className("icon-otc"));
    WebElement herbBtn = driver.findElement(By.className("icon-herb"));
Assert.assertEquals(true, rxBtn.isDisplayed());
Assert.assertEquals(true, otcBtn.isDisplayed());
Assert.assertEquals(true, herbBtn.isDisplayed()); 

6. driver.findelement(By.id("id1")).isDisplayed()
  driver.findelement(By.id("id2")).sendkey("test"); 


Example :
 protected boolean isElementPresent(By by)
 {
   try {
    driver.findElement(by);
    return true;
       }
   catch (NoSuchElementException e)
  {
    return false;
  }
}
 

Sunday, March 24, 2013

Selenium:Open Browser and Check for element..BETTER !!

Open Browser and Check for element..BETTER !!


import javax.swing.JOptionPane;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample1
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.firefox.bin","E://Work//Program_files//Firefox17.0//firefox.exe");
FirefoxDriver oDriver=new FirefoxDriver();
oDriver.get("http://yahoo.com");

if (oDriver.findElementByXPath("//*[@id='default-u_14119506-bd']/div/h1/span").isDisplayed()==true)
{
System.out.println("passed");
}
else
{
System.out.println("failed");
}

// String a=JOptionPane.showInputDialog(null,"What is your name ?");
Thread.sleep(5000);
oDriver.close();
oDriver.quit();
JOptionPane.showMessageDialog(null,"Done");

}
}

Selenium:Open browser and Check for element

Open browser and Check for element




import javax.swing.JOptionPane;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample1
{
public static void main(String[] args) throws InterruptedException
{
//WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("path/to/your/firefox.exe")), profile);
System.setProperty("webdriver.firefox.bin","E://Work//Program_files//Firefox17.0//firefox.exe");
FirefoxDriver oDriver=new FirefoxDriver();
oDriver.get("http://yahoo.com");
//oDriver.
try
{
WebElement oflag=oDriver.findElementByXPath("//*[@id='default-u_14119506-bd']/div/h1/span") ;
System.out.println("passed");
}catch(org.openqa.selenium.NoSuchElementException Ex)
{
System.out.println("failed");
}

JOptionPane.showMessageDialog(null,"Done");

//driver.findElement(By.id("...")).isDisplayed()
// String a=JOptionPane.showInputDialog(null,"What is your name ?");
// JOptionPane.showMessageDialog(null, a);
Thread.sleep(5000);
oDriver.close();
oDriver.quit();

}
}

Selenium: Installation in brief

Selenium: Installation in brief 


All the files listed are free of charge and can be downloaded from Google or their official website

1.Download eclipse-jee-helios-SR2-win32.zip
2.Download Selenium from Selenium HQ ,under Selenium Client & WebDriver Language Bindings download Java.
3.Download FireFox (Selenium IDe 1.10.0 is compatble with Firefox 16 and 17)
4.Selenium IDe 1.10.0
5.firebug 1.11.2(works with firefox 17) 
6.firePath 0.9.7(works with firefox 4.0-20)
http://catchbug.blogspot.in/2013/02/configuring-eclipse-helios-for-selenium.html
http://catchbug.blogspot.in/2013/02/integrating-testng-with-eclipse.html

Procedure :

Following are Addons for FireFox
1.Install Firefox 17.0
2.Install Addon Firebug 1.11.2 -For FireFox
3.Install Addon Firepath 0.9.7 -For FireFox
4.Install Addon-Selenium IDe -For FireFox

Configuring Selenium with Eclipse

Eclipse is portable i.e., no installation is needed just unzip and open ".exe" file.
  1. Open Eclipse 
  2. Create a project.   (File ->New-> Java Project ->Give name as PracticeCode)
  3. Create Package under this project 
  4. Under this package > create a new class 
  5. Right click project 
  6. Click Properties
  7. Click Java Build Path
  8. Click Libraries
  9. Click Add External Libraries
  10. Select the Selenium-Client-Driver

----------------------- For those who are looking for a simple Database to work on -------------

Sql Server 2005 express installation files
For windows Xp

1.Install SQL Server 2005 EXPR(install me first) first.
2.Then install Sql Management Studio 2005.
3. If you getan error The file C:\Windows\Microsoft.NET\Framework\[version_number]\mscorlib.tlb could not be loaded"
then install "MicrosoftFixit50701.msi" or go to website do http://support.microsoft.com/kb/918685

-----------------------------------------------------------------------------------------------

Sunday, March 3, 2013

QTP :Batch Runner / Suite Trigger VBS

Batch Runner / Suite Trigger VBS

Dim qtp_test,url,function_lib,object_repository
qtp_test= "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\google -description programming"
url="www.google.com"
function_lib="C:\Testing\vbs\REGEX.vbs"
object_repository="C:\Program Files\Mercury Interactive\QuickTest Professional\CodeSamplesPlus\Flight_Samples\SOR.tsr"

'-------------------------------------------------------------
Set qtp=createobject("quicktest.application")

Call addins()
Call global_settings()
set ie=aut()

Set xl=createobject("excel.application")
xl.visible=true
Set wb=xl.workbooks.add
Set ws=wb.worksheets("Sheet1")

For i=1 to 3 step 1
with ws.cells(i,1)
.value=i
.font.colorindex=(i*10)
.font.size=i+5
.font.bold=true
.font.name="Arial"

.interior.colorindex=(i+2)*2
end with
Next
msgbox "excel rows "&ws.usedrange.rows.count
msgbox "excel columns "&ws.usedrange.columns.count

qtp.open qtp_test

Call local_settings()
res= fire_app()
msgbox "testscript results "&res
Call fire_app()
Call db_clean()
Call time_stamp()
Call send_mail()
Call read_mail()
ie.close
'---------------------------------------------------------------------
Function addins()
a=array("web")
qtp.setactiveaddins a
qtp.visible=true
qtp.launch
End Function

Function global_settings()
with qtp.options.run
.runmode="Fast"
.viewresults=false
.imagecapturefortestresults="Never"
.moviecapturefortestresults="Never"
end with
qtp.folders.removeall
qtp.folders.Add"c:\"
End Function

Function aut()
Set ie=createobject("internetexplorer.application")
ie.visible=true
ie.navigate url
Set aut=ie
End Function

Function local_settings()
with qtp.test.settings.run
.iterationmode="oneIteration"
.disablesmartidentification=true
.objectsynctimeout=10000
end with
qtp.test.settings.resources.libraries.removeall
qtp.test.settings.resources.libraries.add function_lib
For i=1 to qtp.test.actions.count
qtp.test.actions.item(i).objectrepositories.removeall
qtp.test.actions.item(i).objectrepositories.add object_repository
Next
End Function

Function fire_app()
qtp.test.run
fire_app=qtp.test.lastrunresults.status
End Function

Function db_clean()
Set db=createobject("adodb.connection")
db.open"actitime"
Set rs=db.execute("select * from at_user")
msgbox "checking db "&rs(0).value
msgbox "checking db "&rs(1).value
rs.movenext
msgbox "checking db "&rs(0).value
End Function


Function time_stamp()
ts=replace(now,":","_")
ts=replace(ts,"/","_")
wb.saveas "C:\"&ts&".xls"
wb.close
xl.quit
End Function

Function send_mail()
Set ol=createobject("outlook.application")
Set mail=ol.createitem(0)
mail.to="j.t@gmail.com"
mail.cc="j.t@gmail.com"
mail.subject="test_autoation"
mail.body="body"
'mail.attachments.add""
mail.Send
ol.quit
End Function


Function read_mail()
Set ol=createobject("outlook.application")
Set ol_ns=ol.getnamespace("Mapi")
set ol_obj=ol_ns=getdefaultfolder(6)
'msgbox ol_obj.items.count
For each item in ol_obj.items
If item.unread Then
a=item.subject
If a= "test_autoation"Then
msgbox "reading email "&"a o k"
End If
End If
Next
ol.quit
End Function

Saturday, March 2, 2013

SQL Free !!



FREE SQL

Linux

  1.     Download linux version https://www.sqlite.org/index.html  -
  2.     sqlite-tools-linux-x86-3280000.zip (Precompiled Binaries for Linux)
  3.     Open Terminal
  4.      chmod -R 777 sqlite-tools-linux-x86-3280000.zip
  5.     Unzip sqlite-tools-linux-x86-3280000.zip
  6.     cd sqlite-tools-linux-x86-3280000
  7.      sqlite3 test.db # to create a DB
  8.     Dowload SQL studio (Linux installer)
  9.     ./InstallSQLiteStudo-xx
  10.      After Installation , Click on Add Databases
  11.      Select test.db


Estrablishing Connection using Python with pandas:

import sqlite3
import pandas as pd

conn=sqlite3.connect("/home/deepak/Downloads/chinook.db") 

#chinook.db- https://drive.google.com/file/d/1uc54BXiil2d4pj1nMCGeBUKxsRrKl9zi/view?usp=sharing
df = pd.read_sql_query("SELECT * from genres",conn)
print(df)
  
   
   
     

Windows
SQLite Expert Personal


Installation SQL Server 2005 in XP for Testing

1. Download following SQL Server setups from Microsoft official site .They are free !!
http://www.microsoft.com/en-in/download/details.aspx?id=22625

Microsoft SQL Server 2005 Express Edition (SQL Server Express) is a free, easy-to-use, lightweight version of SQL Server 2005.
http://www.microsoft.com/en-in/download/details.aspx?id=8961

Microsoft SQL Server Management Studio Express (SSMSE) is a free, easy-to-use graphical management tool for managing SQL Server 2005 Express Edition and SQL Server 2005 Express Edition with Advanced Services


1. Install SQL Server Express First.
2. Download and install SQL Server management Studio Express compatible with the SQL Server Express in our case 2005. Management Studio Express is free to download from Microsoft as well.
3. You should be able to see the IDe on double clicking of SQl management Studio icon.


Note:
If you getan error "The file C:\Windows\Microsoft.NET\Framework\[version_number]\mscorlib.tlb could not be loaded".
Then install "MicrosoftFixit50701.msi" or go to website do http://support.microsoft.com/kb/918685 which should fix your problem.