Wednesday 19 June 2013

XML File Parsing

XML File Parsing - Generic - VB code

Objective : Parse the XML to get all the nodes of any XML file .

First get the root node of the XML using oXml.documentElement.
Then check whether that root node has child nodes and do it repeatedly for all the nodes until its the last node.
The above can be achieved easily using recursion.

Belwo code can be used to parse any XML - To get all the nodes of XML

PS: The code is in VB but the same approach can be used for other languages and can be customized.

**************Code******************************

' Declare the variables
Dim oXml As DOMDocument
Dim oRoot As IXMLDOMNode
Dim Childnode As IXMLDOMNode

Sub ParseXml()

'Load the xml File
 Set oXml = CreateObject("Msxml2.DOMDocument")
 oXml.async = True
 xmlFile = ReadXMLfile(AnyFileLocation)
 oXml.loadXML xmlFile

'Set the root of the XML
Set oRoot = oXml.documentElement

'Call Recursive function and pass the root node of the XML
Call getChildNodes(oRoot)

End Sub

'Recursive function
Function getChildNodes(curNode As IXMLDOMNode)

'Çheck if the node has child nodes
If curNode.hasChildNodes = True Then
   For Each Childnode In curNode.childNodes
  
    'If yes then again call the recursive function

   Call getChildNodes(Childnode)
   Next
  
Else

   'If not then its doesnt have any more child nodes and we can print the node
   MsgBox curNode.nodeName

End Function


Friday 24 May 2013

Selenium IDE- Capture ScreenShot

Selenium IDE- Capture Screen

In Selenium IDE,below command can be used to take screens shots and save in particular location.

Command: captureEntirePageScreenshot

Target :  D:\Ia2tech.png

Driectory will not be created if they don't exist and an exception will be thrown.



 

Selenium - Adding User Extensions

Selenium - Adding User Extensions

Parametrization and looping is not supported in Selenium IDE so for that user extensions(.js) files can be loaded in Selenium as below :

Go to Options -> Options -> Selenium Core extensions -> Browse and load the .js files from your local machine.


Selenium IDE - Flow control and Looping statements

Selenium IDE - Flow control and Looping statements

Selenium IDE does not support Flow control and Looping statements like While,Goto directly.
So to achieve flow control and looping in Selenium IDE  goto_sel_ide.js  user extensions have to be added in Selenium Core Extensions.

User extension goto_sel_ide.js can be downloaded form here.

Adding Selenium Core Extensions:

To add user exstension in Selenium , goto Options >> Options >> Selenium Core extensions
Browse goto_sel_ide.js  file from  local disk and click ok.

After adding goto_sel_ide.js we can see while goto statements in the command list of the IDE.




Now lets see a simple While loop script :

We can use store command to save the initial value in variable counter.
Then in While we can use the value of counter  via Storedvars and compare against any  vlaue or vairable if required as shown below.

Before endWhile the value of  counter needs to be increased whcih can be done in a javascript code enclosed in braces.


Command
Target
Value
store
0
counter
while
storedVars.counter<3

Other statements


store
javascript{storedVars.counter++;}

endWhile




Sample script for While loop in Selenium IDE :