Presentation is loading. Please wait.

Presentation is loading. Please wait.

VB Script 9/11/2018 VB Scripting.

Similar presentations


Presentation on theme: "VB Script 9/11/2018 VB Scripting."— Presentation transcript:

1 VB Script 9/11/2018 VB Scripting

2 VB Script Data Types 9/11/2018 MANUAL TESTING

3 VB Script Data Types VB Script doesn’t support explicit declaration of data types. Only data type of VB script is Variant (Dim) Example Dim a a= “Hyderabad” --- a= 1234 ----- -- A=10.25 etc… 9/11/2018 MANUAL TESTING

4 VB Script Data Types Dim Val
Msgbox Vartype(Val) ‘0 for empty or Uninitialized Val=“Pradeep” Msgbox Vartype(Val) ‘8 for String Msgbox Vartype(“Arun”) ‘8 for String Msgbox Vartype(“123”) ‘8 for String Msgbox Vartype(100) ‘2 for Integer Msgbox Vartype(10.12) ‘5 for Double Msgbox Vartype(#10/10/2015#) ‘7 for Date Set a = CreateObject(“Scripting.FileSystemObject”) Msgbox Vartype(a) ‘9 for Automation Objects 9/11/2018 MANUAL TESTING

5 VB Script Data Types Dim a,b,c a=10 b=3 c=a+b Msgbox c ‘13 a=“10”
9/11/2018 MANUAL TESTING

6 VB Script Data Types Dim a,b,c a=“Hyderabad” b=“123” c=a+b
Msgbox c ‘Hyderabad123 a=“Hydera” b=“bad” Msgbox c ‘Hyderabad b=3 Msgbox c ‘Error 9/11/2018 MANUAL TESTING

7 a=InputBox(“Enter A Value”) b=InputBox(“Enter B Value”)
Get 2 numbers Find which is big number. Also verify if any alphabets are present say as only Numbers should be given as Input. Also check if there is any Blank data say that “Blank Value, Please enter a value” Dim a,b a=InputBox(“Enter A Value”) b=InputBox(“Enter B Value”) If a<>”” And b<>”” Then If IsNumeric(a)= True And IsNumeric(b)= True Then If Cint (a) > Cint(b) Then Msgbox “A is bigger Number” Else End If Msgbox “Only Numbers should be provided as Input” Msgbox “Blank Value, Please enter a value” 9/11/2018 MANUAL TESTING

8 Functions 9/11/2018 MANUAL TESTING

9 Functions Function Name Function Description Abs Function
Returns the absolute value of a number. Array Function Returns a Variant containing an array. Asc Function Returns the ANSI character code corresponding to the first letter in a string. Atn Function Returns the arctangent of a number. CBool Function Returns an expression that has been converted to a Variant of subtype Boolean. CByte Function Returns an expression that has been converted to a Variant of subtype Byte. CCur Function Returns an expression that has been converted to a Variant of subtype Currency. CDate Function Returns an expression that has been converted to a Variant of subtype Date. CDbl Function Returns an expression that has been converted to a Variant of subtype Double. Chr Function Returns the character associated with the specified ANSI character code. CInt Function Returns an expression that has been converted to a Variant of subtype Integer. CLng Function Returns an expression that has been converted to a Variant of subtype Long. Cos Function Returns the cosine of an angle. 9/11/2018 MANUAL TESTING

10 Functions Function Name Function Description CreateObject Function
Creates and returns a reference to an Automation object. CSng Function Returns an expression that has been converted to a Variant of subtype Single. CStr Function Returns an expression that has been converted to a Variant of subtype String. Date Function Returns the current system date. DateAdd Function Returns a date to which a specified time interval has been added. DateDiff Function Returns the number of intervals between two dates. DatePart Function Returns the specified part of a given date. DateSerial Function Returns a Variant of subtype Date for a specified year, month, and day. DateValue Function Returns a Variant of subtype Date. Day Function Returns a whole number between 1 and 31, inclusive, representing the day of the month. Eval Function Evaluates an expression and returns the result. Exp Function Returns e (the base of natural logarithms) raised to a power. Filter Function Returns a zero-based array containing subset of a string array based on a specified filter criteria. 9/11/2018 MANUAL TESTING

11 Functions Function Name Function Description Fix Function
Returns the integer portion of a number. FormatCurrency Function Returns an expression formatted as a currency value using the currency symbol defined in the system control panel. FormatDateTime Function Returns an expression formatted as a date or time. FormatNumber Function Returns an expression formatted as a number. FormatPercent Function Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character. GetLocale Function Returns the current locale ID value. GetObject Function Returns a reference to an Automation object from a file. GetRef Function Returns a reference to a procedure that can be bound to an event. Hex Function Returns a string representing the hexadecimal value of a number. Hour Function Returns a whole number between 0 and 23, inclusive, representing the hour of the day. InputBox Function Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box. InStr Function Returns the position of the first occurrence of one string within another. InStrRev Function Returns the position of an occurrence of one string within another, from the end of string. 9/11/2018 MANUAL TESTING

12 Functions Function Name Function Description
Int Function Returns the integer portion of a number. IsArray Function Returns a Boolean value indicating whether a variable is an array. IsDate Function Returns a Boolean value indicating whether an expression can be converted to a date. IsEmpty Function Returns a Boolean value indicating whether a variable has been initialized. IsNull Function Returns a Boolean value that indicates whether an expression contains no valid data (Null). IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number. IsObject Function Returns a Boolean value indicating whether an expression references a valid Automation object. Join Function Returns a string created by joining a number of substrings contained in an array. LBound Function Returns the smallest available subscript for the indicated dimension of an array. LCase Function Returns a string that has been converted to lowercase. Left Function Returns a specified number of characters from the left side of a string. Len Function Returns the number of characters in a string or the number of bytes required to store a variable. LoadPicture Function Returns a picture object. Available only on 32-bit platforms. 9/11/2018 MANUAL TESTING

13 Functions Function Name Function Description Log Function
Returns the natural logarithm of a number. LTrim Function Returns a copy of a string without leading spaces. Mid Function Returns a specified number of characters from a string. Minute Function Returns a whole number between 0 and 59, inclusive, representing the minute of the hour. Month Function Returns a whole number between 1 and 12, inclusive, representing the month of the year. MonthName Function Returns a string indicating the specified month. MsgBox Function Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked. Now Function Returns the current date and time according to the setting of your computer's system date and time. Oct Function Returns a string representing the octal value of a number. Replace Function Returns a string in which a specified substring has been replaced with another substring a specified number of times. RGB Function Returns a whole number representing an RGB color value. Right Function Returns a specified number of characters from the right side of a string. Rnd Function Returns a random number. 9/11/2018 MANUAL TESTING

14 Functions Function Name Function Description Round Function
Returns a number rounded to a specified number of decimal places. RTrim Function Returns a copy of a string without trailing spaces. ScriptEngine Function Returns a string representing the scripting language in use. ScriptEngineBuildVersion Function Returns the build version number of the scripting engine in use. ScriptEngineMajorVersion Function Returns the major version number of the scripting engine in use. ScriptEngineMinorVersion Function Returns the minor version number of the scripting engine in use. Second Function Returns a whole number between 0 and 59, inclusive, representing the second of the minute. SetLocale Function Sets the global locale and returns the previous locale. Sgn Function Returns an integer indicating the sign of a number. Sin Function Returns the sine of an angle. Space Function Returns a string consisting of the specified number of spaces. Split Function Returns a zero-based, one-dimensional array containing a specified number of substrings. Sqr Function Returns the square root of a number. 9/11/2018 MANUAL TESTING

15 Functions Function Name Function Description StrComp Function
Returns a value indicating the result of a string comparison. String Function Returns a repeating character string of the length specified. StrReverse Function Returns a string in which the character order of a specified string is reversed. Tan Function Returns the tangent of an angle. Time Function Returns a Variant of subtype Date indicating the current system time. Timer Function Returns the number of seconds that have elapsed since 12:00 AM (midnight). TimeSerial Function Returns a Variant of subtype Date containing the time for a specific hour, minute, and second. TimeValue Function Returns a Variant of subtype Date containing the time. Trim Function Returns a copy of a string without leading or trailing spaces. TypeName Function Returns a string that provides Variant subtype information about a variable. UBound Function Returns the largest available subscript for the indicated dimension of an array. UCase Function Returns a string that has been converted to uppercase. VarType Function Returns a value indicating the subtype of a variable. 9/11/2018 MANUAL TESTING

16 Functions Function Name Function Description Weekday Function
Returns a whole number representing the day of the week. WeekdayName Function Returns a string indicating the specified day of the week. Year Function Returns a whole number representing the year. 9/11/2018 MANUAL TESTING

17 Functions 9/11/2018 MANUAL TESTING

18 Functions 9/11/2018 MANUAL TESTING

19 Functions 9/11/2018 MANUAL TESTING

20 Functions 9/11/2018 MANUAL TESTING

21 Functions 9/11/2018 MANUAL TESTING

22 Functions 9/11/2018 MANUAL TESTING

23 Functions 9/11/2018 MANUAL TESTING

24 Functions 9/11/2018 MANUAL TESTING

25 Functions 9/11/2018 MANUAL TESTING

26 Functions 9/11/2018 MANUAL TESTING

27 Functions 9/11/2018 MANUAL TESTING

28 Functions 9/11/2018 MANUAL TESTING

29 Functions 9/11/2018 MANUAL TESTING

30 Functions 9/11/2018 MANUAL TESTING

31 Functions 9/11/2018 MANUAL TESTING

32 Conditional Statements
9/11/2018 MANUAL TESTING

33 Conditional Statements
If Statements: Executes the set of code when condition is TRUE If…. THEN … Else Use the If...Then...Else statement if you want to Execute some code if a condition is true Select one of two blocks of code to execute If…. THEN … ElseIf You can use the If...Then...ElseIf statement if you want to execute many blocks of code. 9/11/2018 MANUAL TESTING

34 DO LOOP Statement 9/11/2018 MANUAL TESTING

35 DO WHILE LOOP Statement
9/11/2018 MANUAL TESTING

36 DO UNTIL LOOP Statement
9/11/2018 MANUAL TESTING

37 EXIT DO WHILE LOOP Statement
9/11/2018 MANUAL TESTING

38 EXIT DO WHILE LOOP Statement
9/11/2018 MANUAL TESTING

39 WHILE WEND Statement 9/11/2018 MANUAL TESTING

40 WHILE WEND Statement 9/11/2018 MANUAL TESTING

41 WHITH Statement 9/11/2018 MANUAL TESTING

42 Looping Statements 9/11/2018 MANUAL TESTING

43 Looping Statements Loop Type Description for loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. for ..each loop This is executed if there is at least one element in group and reiterated for each element in a group. while..wend loop This tests the condition before executing the loop body. do..while loops The do..While statements will be executed as long as condition is True.(i.e.,) The Loop should be repeated till the condition is False. do..until loops The do..Until statements will be executed as long as condition is False.(i.e.,) The Loop should be repeated till the condition is True. 9/11/2018 MANUAL TESTING

44 Looping Statements 9/11/2018 MANUAL TESTING

45 FOR NEXT Loop Statements
9/11/2018 MANUAL TESTING

46 EXIT FOR Loop Statements
9/11/2018 MANUAL TESTING

47 FOR EACH Loop Statements
9/11/2018 MANUAL TESTING

48 IF … THEN… ELSE Loop Statements
9/11/2018 MANUAL TESTING

49 IF … THEN… ELSE Loop Statements
9/11/2018 MANUAL TESTING

50 IF … ELSEIF Loop Statements
9/11/2018 MANUAL TESTING

51 SELECT CASE Statements
9/11/2018 MANUAL TESTING

52 SELECT CASE Statements
9/11/2018 MANUAL TESTING

53 Object Oriented VB Script
9/11/2018 MANUAL TESTING

54 Object Oriented VB Script
VBScript runtime objects help us to accomplish various tasks. Syntax In order to work with objects seamlessly, we need to declare the object and instantiate it using Set Keyword. Dim objectname 'Declare the object name Set objectname = CreateObject(object_type) Destroying the Objects The significance of destroying the Object is to free the memory and reset the object variable. In order to destroy the objects, we need to use Set Keyword followed by the object name and point it to Nothing. Set objectname = Nothing 'Destroy the object. 9/11/2018 MANUAL TESTING

55 Object Oriented VB Script
Object Type Description Class Class is a container, which holds methods and variables associated with it and accessed by creating an object of Type Class. Scripting.FileSystemObject It is the group of objects with which we can work with file system. Scripting.Dictionary A Group of objects, which are used for creating the dictionary objects. Debug A Global Object with which we can send output to the Microsoft script debugger. 9/11/2018 MANUAL TESTING

56 Object Oriented VB Script
Object Type Description Drive Drive is an Object. Contains methods and properties that allow you to gather information about a drive attached to the system Drives Drives is a Collection. It Provides a list of the drives attached to the system, either physically or logically. File File is an Object. It Contains methods and properties that allow developers to create, delete or move a file. Files Files is a Collection. It Provides a list of all files contained within a folder. Folder Folder is an Object. It Provides methods and properties that allow developers to create, delete or move folders. Folders Folders is a Collection. It Provides a list of all the folders within a Folder. TextStream TextStream is an Object. It enables developers to read and write text files. 9/11/2018 MANUAL TESTING

57 DRIVE Drive: Drive is an object, which provides access to the properties of a particular disk drive or network share. The Following properties are supported by Drive object: AvailableSpace DriveLetter DriveType FileSystem FreeSpace IsReady Path RootFolder SerialNumber ShareName TotalSize VolumeName 9/11/2018 MANUAL TESTING

58 DRIVES Drives: Drives is a collection, which provides details of all the drives attached to the system, either physically or logically. It carries two properties: Count Property Item Property 9/11/2018 MANUAL TESTING

59 FILE File: File is an Object, which contains both properties and methods that allow the developers to create, delete or move a file. Methods Copy Delete Move openasTextStream Properties Attributes DateCreated DateLastAccessed DateLastModified Drive Name ParentFolder Path ShortName ShortPath Size Type 9/11/2018 MANUAL TESTING

60 FILES Files Files is a collection, which provides a list of all files contained within a folder. Properties Count Item 9/11/2018 MANUAL TESTING

61 FOLDER Folder: Folder is an Object, which contains both properties and methods that allow the developers to create, delete or move a folder. Methods Copy Delete Move CreateTextFile Properties Attributes DateCreated DateLastAccessed DateLastModified Drive Files IsRootFolder Name ParentFolder Path ShortName ShortPath Size SubFolders Type 9/11/2018 MANUAL TESTING

62 FOLDER Folders: Folders is an collection of all Folder Objects within a Folder object. Methods Add Properties Count Item 9/11/2018 MANUAL TESTING

63 FILE SYSTEM OPERATIONS
9/11/2018 MANUAL TESTING

64 FILE SYSTEM OPERATIONS
Create a Folder Copy a Folder Delete a folder Create a Text File Write data Read Data Compare Data Delete a Text File 9/11/2018 MANUAL TESTING

65 CREATE A FOLDER Dim ObjFso, FolderPath
FolderPath = C:\Users\pradeemo\Desktop\UFT Set ObjFso = CreateObject(“Scripting.FileSystemObject”) If Not ObjFso.FolderExists(FolderPath) Then ObjFso.CreateFolder FolderPath End If Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

66 COPY A FOLDER Dim ObjFso, FolderPath
FolderPath = C:\Users\pradeemo\Desktop\UFT Set ObjFso = CreateObject(“Scripting.FileSystemObject”) ObjFso.CopyFolder FolderPath, “C:/” Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

67 DELETE A FOLDER Dim ObjFso, FolderPath
FolderPath = C:\Users\pradeemo\Desktop\UFT Set ObjFso = CreateObject(“Scripting.FileSystemObject”) ObjFso.DeleteFolder FolderPath Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

68 DELETE A FOLDER If the folder Exists
Dim ObjFso, FolderPath FolderPath = C:\Users\pradeemo\Desktop\UFT Set ObjFso = CreateObject(“Scripting.FileSystemObject”) If ObjFso.FolderExists (FolderPath) Then ObjFso.DeleteFolder (FolderPath) End If Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

69 CREATE A TEXT FILE Dim ObjFso
Set ObjFso = CreateObject(“Scripting.FileSystemObject”) ObjFso.CreateTextFile “C:\Users\pradeemo\Desktop\UFT.txt” ObjFso.CreateTextFile “C:\Users\pradeemo\Desktop\UFT.doc” ObjFso.CreateTextFile “C:\Users\pradeemo\Desktop\UFT.xlsx” ObjFso.CreateTextFile “C:\Users\pradeemo\Desktop\UFT.PDF” Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

70 TEXT STREAM Object It is used to perform Text related operations.
Create text stream Object Set Variable = FileSystemObject.CreateTextFile/OpenTextFile (“FilePath”, File Mode) 9/11/2018 MANUAL TESTING

71 TEXT STREAM Object Read a text File character by Character.
Dim ObjFso, ObjTextStream, MyChar Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextStream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) Do Until ObjTextStream.AtEndofStream MyChar = ObjTextStream.Read(1) Msgbox MyChar Loop ObjTextStream.Close Set ObjTextStream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

72 TEXT STREAM Object Read a text File Line by Line.
Dim ObjFso, ObjTextStream, MyLine Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextStream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) Do Until ObjTextStream.AtEndofStream MyLine = ObjTextStream.ReadLine Msgbox MyLine Loop ObjTextStream.Close Set ObjTextStream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

73 TEXT STREAM Object Read a text File All Line
Dim ObjFso, ObjTextStream, MyAllLine Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextStream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) MyAllLine = ObjTextStream.ReadAll Msgbox MyAllLine ObjTextStream.Close Set ObjTextStream = Nothing Set ObjFso = Nothing Note: For a big file to display use “PRINT” command. PRINT is NOT a VB Script command it is a UFT tool feature. Print MyAllLine 9/11/2018 MANUAL TESTING

74 TEXT STREAM Object Read data from Text file and perform data driven testing Dim ObjFso, ObjTextStream, MyLine, MyField Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextstream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) ObjTextstream.SkipLine While ObjTextstream.AtEndOfStream = False MyLine = ObjTextstream.ReadLine MyField = Split(MyLine, “,”) SystemUtil.Run “Path of the application” Dialog(“Login”).Activate Dialog(“login”).WinEdit(“Agent Name:”).Set MyField(0) Dialog(“login”).WinEdit(“Password:”).Set MyField(1) Dialog(“login”).WinButton(“Ok”).Click Window(“Flight Reservation”).Close Wend ObjTextstream.Close Set ObjTextstream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

75 TEXT STREAM Object Read data from Text file and perform data driven testing for certain range of rows Dim ObjFso, ObjTextStream, MyLine, MyField Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextstream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) LineCount =0 While ObjTextstream.AtEndOfStream = False MyLine = ObjTextstream.ReadLine LineCount = LineCount + 1 If LineCount > 4 AND LineCount < 9 Then MyField = Split(MyLine, “,”) SystemUtil.Run “Path of the application” Dialog(“Login”).Activate Dialog(“login”).WinEdit(“Agent Name:”).Set MyField(0) Dialog(“login”).WinEdit(“Password:”).Set MyField(1) Dialog(“login”).WinButton(“Ok”).Click Window(“Flight Reservation”).Close Wend ObjTextstream.Close Set ObjTextstream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

76 TEXT STREAM Object Read data from Text file and perform data driven testing for a Particular record say 5th Record Dim ObjFso, ObjTextStream, MyLine, MyField Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextstream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) LineCount =0 While ObjTextstream.AtEndOfStream = False MyLine = ObjTextstream.ReadLine LineCount = LineCount + 1 If LineCount = 6 Then MyField = Split(MyLine, “,”) SystemUtil.Run “Path of the application” Dialog(“Login”).Activate Dialog(“login”).WinEdit(“Agent Name:”).Set MyField(0) Dialog(“login”).WinEdit(“Password:”).Set MyField(1) Dialog(“login”).WinButton(“Ok”).Click Window(“Flight Reservation”).Close Wend ObjTextstream.Close Set ObjTextstream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

77 WRITE DATA Write a data on the text file
Dim ObjFso, ObjTextStream, Num1, Num2, result Num1 =10 : Num2 = 20 : result = Num1 + Num2 Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextstream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) ObjTextstream.Write “Addition of Num1, Num2 is : & result ObjTextstream.Close Set ObjTextstream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

78 WRITE DATA Write Data Line by :Line
Read Link Names from Rediff home page and export it to a text file. Dim ObjFso, ObjTextStream, oLink, Links, I Set ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjTextstream = Objfso.OpenTextFile(“C:\Users\pradeemo\Desktop\UFT.txt”) Set oLink = Description.Create oLink(“micclass”).Value = “Link”. Set Links = Browser(“Rediff.com). .Page(fvv).ChildObjects(oLink ) objTextstream.WriteLine “Link Names” For i= 0 to Links.Count-1 Step 1 objTextstream.WriteLine i+1 &”) “ & Links(i).GetRoProperty(“text”) Next ObjTextstream.Close Set ObjTextstream = Nothing Set ObjFso = Nothing 9/11/2018 MANUAL TESTING

79 EXCEL APPLICATIONS OBJECTS
9/11/2018 MANUAL TESTING

80 EXCEL APPLICATIONS OBJECTS
It deals with Excel File/ Excel workbook / Excel Sheet / Excel Work Sheet. Create Excel Take Row Count Take Column Count Read Data Write Data Class Value for creating excel application object (“Excel.Application”) 9/11/2018 MANUAL TESTING

81 CREATE AN EXCEL FILE Dim ObjExcel
Set ObjExcel = CreateObject(“Excel.Application”) ObjExcel.Visible ObjExcel.Workbooks.Add ObjExcel.ActiveWorkbook.SaveAs “C:/UFT.xlsx ObjExcel.Quit Set ObjExcel = Nothing 9/11/2018 MANUAL TESTING

82 Existance of excel file, If NOT CREATE AN EXCEL FILE
Dim ObjFso, ObjExcel, FilePath FilePath = “C:\UFT.xlsx Set.ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjExcel = CreateObject(“Excel.Application”) If Not ObjFso.FileExists(FilePath) Then ObjExcel.Workbooks.Add ObjExcel.ActiveWorkbook.SaveAs FilePath End If ObjExcel.Quit Set ObjExcel = Nothing 9/11/2018 MANUAL TESTING

83 Check the Existance of excel file, If exists enter some data
Check the Existance of excel file, If exists enter some data.If NOT CREATE AN EXCEL FILE Dim ObjFso, ObjExcel, FilePath FilePath = “C:\UFT.xlsx Set.ObjFso = CreateObject(“Scripting.FileSystemObject”) Set ObjExcel = CreateObject(“Excel.Application”) If Not ObjFso.FileExists(FilePath) Then ObjExcel.Workbooks.Open(FilePath) ObjExcel.Worksheets(1).Cells(1,1) = “Hello UFT” ObjExcel.ActiveWorkbook.Save Else ObjExcel.Workbooks.Add ObjExcel.Worksheets(1).Cells(1,1) = “Hello UFT1” ObjExcel.ActiveWorkbook.SaveAs FilePath End If ObjExcel.Quit Set ObjExcel = Nothing 9/11/2018 MANUAL TESTING

84 Read data from excel file and Perform data driven testing
Dim ObjExcel, ObjWorkbook, ObjWorksheet, RowCount Set ObjExcel = CreateObject(“Excel.Application”) Set ObjWorkbook = ObjExcel.Workbooks..Open(“C:\Uft.xlxs”) Set ObjWorksheet = ObjWorkbook.Worksheets(1) RowsCount = ObjWorksheet.UsedRange.Rows.Count For I = 2 to RowsCount Step1 SystemUtil.Run “Path of Fligt App Application” Dialog(“Login”).Activate Dialog(“Login”).WinEdit(“AgentName”).Set ObjWorksheet.Cells(I,1) Dialog(“Login”).WinEdit(“Password”).Set ObjWorksheet.Cells(I,”B”) Dialog(“Login”).Click(“OK”) If Window(“Flight Reservation”).Exists(12) Then Window(“Flight Reservation”).Close ObjWorksheet.Cells(I,3) = “Login successful - Passed” 9/11/2018 MANUAL TESTING

85 Read data from excel file and Perform data driven testing
Else object.Worksheet.Cells(I,4)= Dialog(“Login”). Dialog(“Flight Reservation”).Static(“Agent Name must be at”).GetROProperty(“text”) SystemUtil.CloseDescendentProcesses End If Next ObjWorkbook.Save Obj.Excel.Quit Set ObjExcel = Nothing Set ObjWorksheet = Nothing Set ObjWorkbook = Nothing 9/11/2018 MANUAL TESTING

86 WORD APPLICATIONS OBJECTS
9/11/2018 MANUAL TESTING

87 WORD APPLICATION OBJECTS
It is used to automate word applications operations. Class Value for creating word application object (“Word.Application”) 9/11/2018 MANUAL TESTING

88 DATABASE OPERATIONS 9/11/2018 MANUAL TESTING

89 DATABASE OPERATIONS Database Connection Object:
It is used to connect to databases. Class Value for creating for Database connection object (“Adodb.Connection”) b. Database Record set Object It is used to perform operations on Data Tables / Records Class Value for creating for Database Record Set object (“Adodb.Recordset”) 9/11/2018 MANUAL TESTING

90 DICTIONARY OBJECTS 9/11/2018 MANUAL TESTING

91 DICTIONARY OBJECTS It is used to define key value pairs.
Class Value for creating Dictionary object (“Scripting.Dictionary”) 9/11/2018 MANUAL TESTING

92 Any Questions ??? THANK YOU… 
9/11/2018 MANUAL TESTING


Download ppt "VB Script 9/11/2018 VB Scripting."

Similar presentations


Ads by Google