Sunday, November 27, 2011

Webdriver - Drop down select values

Webdriver - Drop down select values. (IE Driver)

There is no direct method to choose/click the values from the drop down.
I have used following code to select the list values. Also attaching the screen shot of the list box HTML for better understanding.

String UOMCode = "A1";

Also read following post


Monday, November 21, 2011

VB Script - Call Web-Service with parameters as inline attachment (Base 64)

VB Script - Call Web-Service with parameters as inline attachment (Base 64)

This code is written to automate web-service testing using QTP and Selenium. Actual code is more complicated, below code will help you understand in construction of web-service for the method mentioned in below screen shot.
Need to modify the SOAP message as per your method parameters and data type.

SOAPMessage = "" & _ 
     "" & Bytes() & "" & _

msgBox SOAPMessage
Set objHTTP = CreateObject ( "MSXML2.XMLHTTP")
Set xmlDOC = CreateObject ( "MSXML.DOMDocument") 
strWebserviceURL = URL '""
objHTTP.Open "POST", strWebserviceURL, False
'Set the Content-Type is very important 
objHTTP.SetRequestHeader "Content-Type", "text/xml;charset=utf-8"
'objHTTP.SetRequestHeader "SOAPAction", ""
objHTTP.SetRequestHeader "User-Agent", "Jakarta Commons-HttpClient/3.0"
objHTTP.SetRequestHeader "Host", Domain ' 
objHTTP.Send (SOAPMessage) 
bOK = xmlDOC.load (objHTTP.responseXML) 
'Look at the state value 
msgBox objHTTP.Status 
msgbox objHTTP.StatusText 
msgbox objHTTP.responseText
'objHTTP.Status = 200, return here to deal with a fragment of xml 
'If necessary, you can replace them to return the xml string of  
xmlStr = xmlDOC.xml 
xmlStr = Replace (xmlStr ,"&lt","<", 1, -1,1) 
xmlStr = Replace (xmlStr ,"&gt",">", 1, -1,1) 
msgbox xmlStr 

' HTTP is a text based protocol, it can't transmit binary content
' so content need to be converted into base 64 format
' Below function perform this job for you

Function Bytes()
 Const fsDoOverwrite     = true  ' Overwrite file with base64 code
 Const fsAsASCII         = false ' Create base64 code file as ASCII file
 Const adTypeBinary      = 1     ' Binary file is encoded

 ' Variables for writing base64 code to file
 Dim objFSO
 Dim objFileOut

 ' Variables for encoding
 Dim objXML
 Dim objDocElem

 ' Variable for reading binary picture
 Dim objStream

 ' Open data stream from picture
 Set objStream = CreateObject("ADODB.Stream")
 objStream.Type = adTypeBinary

 ' Create XML Document object and root node
 ' that will contain the data
 Set objXML = CreateObject("MSXml2.DOMDocument")
 Set objDocElem = objXML.createElement("Base64Data")
 objDocElem.dataType = "bin.base64"

 ' Set binary value
 objDocElem.nodeTypedValue = objStream.Read()

 ' Get base64 value and write to file
 'objFileOut.Write objDocElem.text
 'msgBox (objDocElem.text)
 Bytes = objDocElem.text

 ' Clean all
 Set objFSO = Nothing
 Set objFileOut = Nothing
 Set objXML = Nothing
 Set objDocElem = Nothing
 Set objStream = Nothing
End function
I am currently busy with other tasks, planning to put detailed explanation of the above code later.

Thursday, November 17, 2011

Selenium - Build standalone jar file using ANT

  Selenium RC Common Build Tasks




Tuesday, November 15, 2011

QTP, Selenium - Black/Empty screen shots - Windows

QTP, Selenium - Black/Empty screen shots - Windows

Black screen shot happen when desktop is not available. This will happen when you lock the PC, disconnect or minimize RDP (Remote Desktop). This is fail windows screen shot function, any tool need to relay on OS APIs for taking a screen shot. It is a known issue in all versions of windows.
Also some of the tool functions fail because windows switches to GUI-Less mode and don't display windows and controls.

There are FOUR options available

Option1: When tool is installed on local machine, install caffeine so that your system is not locked automatically when ideal as per the company policy.

Option2: Install  Ultra VNC Server on the remote machine or EC2, so that it can be accessed by IP address. In this option you can lock the machine with VNC on, still you can take the screen shot.

The Microsoft Windows operating system includes the Remote Desktop component that allows you to connect to a remote computer and work with it as with your local computer. This is a common way to run and monitor automated tests on remote computers: you connect to the test computer using a Remote Desktop Connection (RDC) and use the Remote Desktop window to work with the remote computer on your PC.
There is a pitfall using this scenario: you may not minimize the Remote Desktop window (that is, the window which displays the remote computer’s desktop), or your GUI tests will fail. If you minimize this window, the operating system switches the remote session to a GUI-less mode and does not display windows and controls. As a result, TestComplete (or TestExecute) are unable to interact with the tested application’s GUI as the GUI doesn’t actually exist in this case.
Keeping the Remote Desktop window visible may be inconvenient, as it will occupy some part of or even your entire screen, and you will have less space for running your local applications.
We have found a way to bypass this limitation. The workaround is simple: you need to change Registry keys on your computer (that is, the computer from which you connect to a remote TestComplete or TestExecute workstation). Here is a step-by-step description:
  1. Close Remote Desktop sessions opened on your computer.
  2. Launch the Registry editor (Regedit.exe).
  3. Locate any of the following Registry keys:
    • HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\
      (if you want to change the RDC settings for your user account)
    • -- or --
    • HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\
      (if you want to change the RDC settings for all accounts)
  4. Create a new DWORD value in this key namedRemoteDesktop_SuppressWhenMinimized. Specify 2 as the value data (As Decimal).
  5. If you use a 64-bit operating system, add the RemoteDesktop_SuppressWhenMinimized value to the following keys under the Wow6432Node node:
    • HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Terminal Server Client\
      (for your user account)
    • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client\
      (for all user accounts)
    This way the Registry tweak will work in both 32- and 64-bit versions of the Remote Desktop client.
That’s all. Now minimizing the RDC window on your computer will not affect the remote computer’s GUI and the GUI will still be available to your automated GUI tests.

Option 4:

Here is the simple, but very useful instruction how to run GUI test automation scripts on the remote server.

1. Open "Remote desktop connection" window, click "Options" button, then "Save As..." and save "*.rdp" file in any place. 
2. Open *.rdp file in Notepad and add to the end of file string: "smart sizing:i:1" without quotes. Make sure that parameters "desktopwidth:i:1280" and "desktopheight:i:1024" has values which match desktop resolution on a server. If you wish, you can change parameter value "session bpp:i:8" to "session bpp:i:24" for more comfort colors. 
3. Use this *.rdp file for launching RDC session by clicking on it. 

After tests launch on the remote server you can change size the RDC Session window, but don't minimize and don't overlap it with another windows - it is very important. 

Optional: for keeping RDC Session window always on top, you can use free software "Hotkey manager" After install "Hotkey manager" run it, icon appears in system tray, then hold Ctrl button and right-click on "Maxmimize" button on RDC Session window, RDC window becomes always on top. For keeping window always on top, you can use other software too or just control it manually. 

In order to keep RDC closed, you can set specific registry values, as it is described at Running Tests in Minimized Remote Desktop Windows article.