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.

Friday, March 1, 2013

QTP :command in QTP to invoke IE Brow

command in QTP to invoke IE Brow



1. InvokeApplication "E:\Program Files\Plus!\Microsoft Internet\IEXPLORE.EXE"

2. Set IE=createobject("internetExplorer.application")
    IE.visible=true
     IE.navigate "www.gmail.com"

3. systemutil.Run "iexplore.exe",”www.gmail.com”

4. oShell = CreateObject ("Wscript.shell")
 oShell.Run Chr(34) & "C:Program FilesInternet ExplorerIEXPLORE.EXE" & Chr(34)






QTP :Run alternate iterations from the data table

Run alternate iterations from the data table


Click File –> Settings –> Run –> Select Run  once


currow = 1
Do Until currow =DataTable.GetSheet("dtGlobalSheet").GetRowCount

  currow = DataTable.GetCurrentRow
  msgbox Datatable("A",Global)
  currow = currow + 2
  DataTable.SetCurrentRow(currow)

Loop

VBS :Sorting using built in function

Sorting using built in function


Program to sort an array using built-in function
set a =createobject("system.collections.arraylist")
a.add "5"
a.add "1"
a.add "2"
a.sort
for each i in a
 b=b&i&vbnewline
next
msgbox b

VBS: Regular Expression

 VBS: Regular Expression



Example 1 :
set regex=new regexp
regex.pattern="((9|8)[0-9]{9})"

a=inputbox("enter data")
if regex.test(a) = true and len(a)=10 then
 msgbox "valid"
else
 msgbox "invalid"
end if


Example 2 :

set regex=new regexp
regex.pattern="www\..*\.(com|in|jp)$"
n=inputbox("validate any website address starting from --www")
if regex.test(n) then
 msgbox "valid"
else
 msgbox "invalid"
End if

VBS :Redim Example

VBS :Redim



Example :

 Program to illustrate used of redim and preserve mechanism

a=array("data in 0th index ","data in 1st index" ,"data in 2nd index" )
redim preserve a(3)
a(3)="This is adding some data to 4th inded "
msgbox ubound(a)&"  "&a(3)

VBS : Instr Example

VBS : Instr Example



Example 1
Program to find the character no "id=" in a sentence
q="select * from xxx where id=123"
r=instr(1,q,"id=")
msgbox r

Example 3:
msgbox instr(1,"ab","a")

VBS :Text File

Text File


Example :

set fso=createobject("scripting.filesystemobject")

fso.createtextfile"D:\1.txt"
set ctrl=fso.getfile("1.txt")
set mode=ctrl.openastextstream(8)
'1-read
'2-write
'8-append

mode.writeline "hi"
mode.writeblanklines 5
mode.writeline "end"

msgbox "over"

VBS :Dictionary

 

VBS :Dictionary

Example :


Set hash = CreateObject ("Scripting.Dictionary")
hash.add "A", "Apple" 'Inserting values into dictionary
hash.add "B", "Ball"  'Inserting valuesinto Dictionary

hash.item("b") = "Case Sensitive" 'The dictionary's "item" method can be used to do the same job as "add "

'hash.CompareMode = 1
'This must be places immediately after the CreateObject statement and before any items are added.
'If that's done then the keys will no longer be case sensitive.
msgbox "A for "& hash.item("A")

keys = hash.Keys   'Keys - returns an array containing the key words
items = hash.Items 'Items - returns an array containing the values
for i = 0 to hash.Count - 1
 msgbox Keys(i) & " for  " & Items(i)
next

hash.Remove("A") 'To remove individual values from dictionary
hash.RemoveAll   'To remove all values into Dictionary

VBS : ERRORS

VBS : ERRORS

Program to Raise , lear and Ignore Error

Example

on error resume next
Err.Raise 6  ' Raise an overflow error.
MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear    ' Clear the error.
MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)

Vbs :Count no of Commas in a string

Vbs :Count no of Commas in a string

Program to count no of commas in a string

n=inputbox("enetr a string containing commas")

for i=1 to len(n)
 k=mid(n,i,1)

 if k="," then
  RES=RES+1
 END IF
next

msgbox "no of commas="& RES

VBS :Classes


VBS :Classes

Program on classes in Vbs

Example :

call a2()

Class a1

  private Function add2()
    msgbox 2+3
 End Function

 Function add1()
  Call add2()     'inturn call the above function
  End Function

End Class

Function a2()
   Set a2=new a1
   a2.add1
End Function

VBS: Arrays and Functions

VBS:Arrays


Simple programs on sending Array to Function

Example 1 :

'----------"a" is an array
'----------notice the way I'm sending it to the function
'----------notice how array is received at the function definition
'Moral of the story ,
'-------you can use paranthesis at function header in the function definition
'***************************************
        a=array(4,23,1,2)
 res=fn(a)
 msgbox res

function fn(x())    'function fn(x)
 fn=ubound(x)
end function


Example 2 :

dim a(4)
a(0)=1
a(1)=2
res= fn(a) 'fn call
msgbox res

function fn(a())    'fn definition
 for i=0 to ubound(a)
  res=res&a(i)&vbnewline
  NEXT
 fn=res
end function

QTP: Create New Excel File

Create New Excel File


Program to create a new Excel workBook

set xl=createobject("excel.application")
set wb=xl.workbooks.Add
Set ws=wb.worksheets(1)
ws.Name="New Name"
ws.cells(1,1).value="Completed creation of new excel file"
wb.saveas ("C:\1.xlsx")
wb.close
xl.quit

QTP : DataTables

QTP Datables


Data Table Basics

Run -Time VS Design Time Datatables


1) The values of the Run Time Data table does not reflect in the QTP's DataTable window after run.

2) If you like to see the values of that DataTable after Run you can see it by openning QTP's result window,  then expanding the trees in the left pane of that window, there you will see Run Time DataTable Icon just below the Test Summary. If you click that you can see the runtime's content of that DataTable.

3) If you want to store runtime values, please, export it to some location (see below code):
DataTable.Export ("D:\XYZ.xls")





QTP : Program to Display 1st Column Data in Database through QTP

 Program to Display 1st Column Data in Database through QTP



Set oConnection=createobject("adodb.connection")
Set oRecordSet=createobject("adodb.recordset")

oConnection.Open "Connection String for the Server"
oRecordSet.Open "Query" ,oConnection

Do while not oRecordSet.EOF
        sData=sData &vblf & oRecordSet.Fields.Item(1)
        oRecordSet.MoveNext
Loop

msgbox oRecordSet
oConnection.Close
Set oConnection=Nothing
Set oRecordSet=Nothing