Thursday, 30 November 2017

Vbscript: Multiple uneven spaces to single space


Input string has uneven spaces. 

sInput = "uftHelp=  User Firendly      Techy Help    additional                  string for               you"

Do while instr(1,sinput,"  ")>0
 
If instr(1,sinput,"  ")>0 Then
   
    x= replace(sInput,"  "," ")
   
    sInput=x
   
End If

Loop
   
print x

O/P:uftHelp= User Firendly Techy Help additional string for you

Vbscript: Err Object

On Error Resume Next
Err.Clear

REM Notice No Value passed in Set Method
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set

Print  err.Number&" "&err.description
REM O/P: 450 Wrong number of arguments or invalid property assignment




On Error Resume Next
Err.Clear

REM Notice Value passed in not having " "
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set x
Print  err.Number&" "&err.description

REM 0



On Error Resume Next
Err.Clear

REM Notice Value passed in not having " "
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set  "x"
Print  err.Number&" "&err.description

REM 0




Vbscript Dictionary: Deleting Particular Keys based on Item Value condition

Dim odic
 
Set odic=CreateObject("Scripting.Dictionary")
odic.Add "Shilpa",1
odic.Add "Amit",2
odic.Add "Sumit",3

For each x in odic.Keys

If odic.item(x)=2 Then
odic.Remove(x)
End If

Next

For each x in odic.Keys
print x 
Next

Set odic=nothing

'Shilpa
'Sumit

Vbscript: Finding Unique Items from space separated string


str="IBM CG CITI IBM CG"

arr=split(str," ")

final=""
 
For each x in arr

If instr(1,final,x)=0 Then

final=final&" "&x

End If
   
Next

msgbox final  'IBM CG CITI

Tuesday, 28 November 2017

Checkpoint: Find Webelement

set opage=Browser("Certificate Error: Navigation").Page("SafetyDirect : Login")

Function VerifyWebElement(objpage,strwebelement)

Dim owebelement
Set owebelement=Description.Create
owebelement("micclass").Value="WebElement"
owebelement("innertext").Value=strwebelement
 
set allwebelement=opage.Childobjects(owebelement)
For i=0 to allwebelement.Count-1

If trim(allwebelement(i).Getroproperty("innertext"))=trim(strwebelement) Then
   
VerifyWebElement=True
Reporter.ReportEvent micPass,"Checkpoint for "&strwebelement," "&strwebelement&" is Present on the webpage"

   
Else

  VerifyWebElement=False
  
End If
   
Next
End Function

Checkpoint for Verifying WebObjects

set opage1=Browser("Certificate Error: Navigation").Page("SafetyDirect : Login")
VerifyWebObj opage1,"WebEdit","ctl00\$ContentPlaceHolder1\$TextBoxUser"

Function VerifyWebObj(objpage,strobjclass,strobjname)

Dim WebObj
Set WebObj=Description.Create
WebObj("micclass").Value=cstr(strobjclass)
WebObj("name").Value=strobjname



set allwebobj=opage1.Childobjects(WebObj)
'msgbox allwebobj.Count

For i=0 to allwebobj.Count-1
If trim(allwebobj(i).Getroproperty("name"))=trim(strobjname) Then

VerifyWebObj=True
Reporter.ReportEvent micPass,"Checkpoint for "&strobjname," "&strobjname&" is Present on the webpage"
'msgbox "yes"
   
Else

 VerifyWebObj=False
   Reporter.ReportEvent micFalse,"Checkpoint for "&strobjname," "&strobjname&" is NOT Present on the
  ' msgbox "false"
  
End If
   
Next

End Function

Saturday, 18 November 2017

Vbscript: Reading XML file

'Sample File ####################################
'Const XMLDataFile="C:\Users\sunshine\Desktop\vbscriptprgm\samplexmlnanda.xml"

<Resources>
<Module1>

 <Function_Libararies>
 <Library>module1lib1.vbs</Library>
 <Library>module1lib1</Library>
 <Library>module1lib1</Library>
 </Function_Libararies>

 <Repositories>
 <Repository>module1repo.tsr</Repository>
 <Repository>module2repo.tsr</Repository>
   </Repositories>
</Module1>

<Module2>

 <Function_Libararies>
 <Library>module2lib2.vbs</Library>
 <Library>module2lib2</Library>
 <Library>module2lib2</Library>
 </Function_Libararies>

 <Repositories>
 <Repository>module2repo.tsr</Repository>
 <Repository>module2repo.tsr</Repository>
   </Repositories>
</Module2>

</Resources>
Dim Modules
Modules=Array("Module1","Module2")

Const XMLDataFile="C:\Users\sunshine\Desktop\vbscriptprgm\samplexmlnanda.xml"
Set oxml= CreateObject("Microsoft.XMLDOM")
oxml.Async = False
oxml.Load(XMLDataFile)

If oxml.Parseerror.Errorcode<>0 Then
   
msgbox "Error Parsing XMl"
   
End If

For i=lbound(Modules) To ubound(Modules) Step 1

parent=cstr(Modules(i))
   
Set Col=oxml.getElementsByTagName(parent).Item(0)

Set olibcol=Col.getElementsByTagName("Function_Libararies").Item(0)

Set lib=olibcol.Childnodes

For each  strlib in lib

msgbox strlib.text
   
Next
Next
'###############################################


'Code For Reading Nodes:

Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...