
f06bce247b6ca2535dc34ea0e047e531.ppt
- Количество слайдов: 93
Requirement Req 0001 Implementation of Requirement Req 0001 Dani Vainstein & Monika Arora Gautam 1
Topics covered n n n n Create a new business module. Open an existing test. Analyzing and designing requirements. Creating an Environment File. The Environment Object. Insert Step Using Step Generator. Insert calls to Existing action. Passing arguments to reusable actions. Dani Vainstein & Monika Arora Gautam 2
What we have done till now? n n n n We have built an infrastructure. Defined QTP global options and record & run settings. We created the gui. Login module and reusable actions “gui. Login” and “Check. Dialog” module. Mapped all the “Login” dialog objects. Learned how to use object spy. Created and saved a function library. Used function and step generator. Dani Vainstein & Monika Arora Gautam 3
Before You Start n Before starting this presentation, read the following topics from QTP help. q Environment Object. q Environment. Load. From. File Method. q q q q Reporter. Run. Status Method. LCase Function. Select Case Statement. Exit. Action Statement. Reporter Object. Parameter Object. Build. Path Method (Scripting. File. System. Object) Desktop. Capture. Bitmap Method. Dani Vainstein & Monika Arora Gautam 4
Before You Start n Before starting this presentation, read the following topics from QTP help. q System. Util. Close. Process. By. Name Method. q Dialog. Exist Property. q Set and Nothing keywords. q Window. State Property. q Path. Finder. Locate Method. q Dictionary. Remove. All Method. Dani Vainstein & Monika Arora Gautam 5
Requirement Req 0001 1 a 1 b Dani Vainstein & Monika Arora Gautam 6
Req 0001 a - Details n Action : To locate the Flight Application executable file from
Req 0001 b - Details n n Action : Invoke the Flightxx. exe from installation folder Expected : The Dialog “Login” should be displayed Dani Vainstein & Monika Arora Gautam 8
Process Design Start Report mic. Fail Req 0001 a? No Exit. Test Yes Failed Report mic. Fail Executable Passed Req 0001 b Report mic. Pass End Dani Vainstein & Monika Arora Gautam 9
Process Design n n The script starts and checks Req 0001 a ( file exists ) This check is critical for the script flow. If it fails, it means that the executable file was not found, and there is no point to continue testing. Dani Vainstein & Monika Arora Gautam 10
Things to Remember… n n The AUT embeds some Active. X objects. When you first open QTP and see the Add-in manager, be sure that only Active. X option is checked. Always open QTP before the AUT, otherwise new Active. X object will identified as Win. Objects. Note : Ask your developers if the application is using Active. X, . NET, Java or VB. Dani Vainstein & Monika Arora Gautam 11
bus. Login Module Automation n FR LIB RA Create a new test and save it with the name “bus. Login” under folder FRRABL folder. BL GL RS DOC DAT SETTING TESTS RES bus. Login BATCH ENV Dani Vainstein & Monika Arora Gautam 12
bus. Login Module - Properties Description : manages all the test-cases and business requirements on the Login form. Remark : associated add-ins : Active. X only Dani Vainstein & Monika Arora Gautam 13
bus. Login Module-Run Tab Run one iteration only Save The Test Pop up Message box Disable Smart Identification During the run session Dani Vainstein & Monika Arora Gautam 14
bus. Login. Mng ( Business Requirements ) n From Menu Edit Action Properties Dani Vainstein & Monika Arora Gautam 15
bus. Login. Mng - General Tab n Follow the modifications. Change Action Name Add Description Mark Reusable Dani Vainstein & Monika Arora Gautam 16
bus. Login. Mng - Parameters Tab n Add a new Input Parameter ( Click on + ) Add bus. Code Add Input Parameter Description Type : String Default Leave Blank Dani Vainstein & Monika Arora Gautam 17
bus. Login Module n n The bus. Login module manages all the testcases and business requirements on the Login form. A test-case can be a single requirement or/and a business process in the application e. g. Create New Order. Dani Vainstein & Monika Arora Gautam 18
bus. Login Header '************************************ '@Author : advanced. QTP '@Date Created :
Points to consider for Req 0001 a n n We need to check that the executable file is under the installation directory. After reading this, you may probably ask q q n n n Where is the installation directory located? Which exe file we need to execute? Usually the installation folder by default is under C: Program FilesMercury Interactive. BUT, what if team has installed QTP in different drive let’s say on D: or F: ? For this purpose we need to make generic scripts so that it “works” on all machines. Dani Vainstein & Monika Arora Gautam 20
Points to consider for Req 0001 a n n n The second issue is the executable file. If you look in “samplesflightapp” you’ll see 3 different versions of Flight Reservation as also described in Req 0001 a – Details Every time a new version is released we want to run the automation test-set. So we want flexibility in order to run the desired version to test. We want an independent place, where we can control this argument. Dani Vainstein & Monika Arora Gautam 21
Points to consider for Req 0001 a n n This information must be separated from the scripts. That’s what we call “dynamic data” ( OO Methodology ) The solution is the Environment Object Dani Vainstein & Monika Arora Gautam 22
Creating an Environment File – FR. xml n n Open the test settings dialog. From menu : File Settings Shortcut : ALT + F + G From Toolbar as shown below : Test Settings Dani Vainstein & Monika Arora Gautam 23
Environment Tab User Defined Dani Vainstein & Monika Arora Gautam 24
Creating Environment variable n Dani Vainstein & Monika Arora Gautam Click Add ( + ) Variable 25
Creating Environment variable n n Dani Vainstein & Monika Arora Gautam Click Export Click Save The File Name under Environment Folder 26
Creating Environment File Automation FR n LIB n RA BL GL Click Export Click Save The File Name under Environment Folder RS DOC DAT FR. xml SETTING TESTS RES BATCH ENV Dani Vainstein & Monika Arora Gautam 27
Creating Environment variable n Dani Vainstein & Monika Arora Gautam Click Cancel 28
ENVFR. xml n n Don’t create this file under Test Settings, as it is created automatically by the export environment that we’ve just seen. The Environment xml file must be in a specific format. Otherwise you’ll get a runtime error when loading the xml. In other words, the xml file must be follow the XML schema. As you can see, only one parameter is defined, for now. Dani Vainstein & Monika Arora Gautam 29
Environment XML Schema n n You can create your own Environment file. Type each variable name-value pair within
bus. Login. Mng Template Option Explicit Dim msg Select Case LCase( Parameter. Item( "bus. Code" ) ) Case. . . Case Else Reporter. Report. Event mic. Warning, "Not. Implemented. Exception", Parameter( "bus. Code" ) Exit. Action( mic. Warning ) End Select Dani Vainstein & Monika Arora Gautam 31
Branching and Validation n n The condition is bus. Code, for each keyword-value, we must provide an implementation. In case that bus. Code is invalid ( user error ) a warning message will sent to the Reporter object. The LCase VBScript function is used to reduce casesensitive errors user mistypes. Parameter. Item( "bus. Code" ) is the Parameter object we use to reference an action parameter( in our case, the input parameter ). Dani Vainstein & Monika Arora Gautam 32
Implementing Req 0001 a n n n First we’ll call the File. Exists function we have already implemented in FR. vbs. The function receives the argument file. Full. Path. Name. To call the function, we need to associate the function library ( FR. vbs ) to the test. Dani Vainstein & Monika Arora Gautam 33
Permanently associate a Function Library n n n Since FR. vbs is our main function library file, we need to associate the library function to each QTP test. QTP can help us with this repetitive task with its “Set as default” feature. By using the “Set as Default” feature, every new test will automatically get associated with FR. vbs. Dani Vainstein & Monika Arora Gautam 34
Permanently associate a Function Library n Associate the function to the bus. Login test. q q q From menu select : File Settings Resources tab Hotkey : ALT + F + G and move to resources tab. From toolbar as shown below. Test Settings Dani Vainstein & Monika Arora Gautam 35
Permanently associate a Function Library Click Dani Vainstein & Monika Arora Gautam 36
Associating Keeping Relative Path Keep Relative Path Clicking “Set as Default” Sets the current list of function libraries as the default list to be associated with all new actions. Dani Vainstein & Monika Arora Gautam 37
Associating function libraries n Caution : if you see picture A, go to Options Folders Tab and add the Path to X: AutomationFR, where “X” is the project driver. Dani Vainstein & Monika Arora Gautam 38
Permanently associating function Libraries n By clicking “Set as Default” every new script will be associated with the FR. vbs function Library File Dani Vainstein & Monika Arora Gautam 39
Declaring Variables n Declare all variables that we are going to use, since we are using Option Explicit. Dim msg, i Dim fso, exec. Path, full. Exe. Name, b. Exist Dani Vainstein & Monika Arora Gautam 40
Implementing Req 0001 a n n We need to assemble the full path of the executable file. We will use the Build. Path method, of the Scripting. File. System. Object ( FSO ) object. We need to assign a reference to the FSO. After using Build. Path we release the fso object by setting the value to Nothing. Set fso = Create. Object( "Scripting. File. System. Object" ) ' ** build the application path exec. Path = fso. Build. Path( Environment( "Product. Dir" ), APP_PATH ) full. Exe. Name = fso. Build. Path( exec. Path, Environment( "EXE_FILE" ) ) Set fso = Nothing Dani Vainstein & Monika Arora Gautam 41
Implementing Req 0001 a Set fso = Create. Object( "Scripting. File. System. Object " ) ' ** build the application path exec. Path = fso. Build. Path( Environment( "Product. Dir" ), APP_PATH ) full. Exe. Name = fso. Build. Path( exec. Path, Environment( "EXE_FILE" ) ) Set fso = Nothing n Questions you’ll probably ask : q q q What is Environment( “Product. Dir” )? How to load Environment( “EXE_FILE” )? Where are we declaring APP_PATH? Dani Vainstein & Monika Arora Gautam 42
Implementing Req 0001 a n n n To use the Build. Path method, we need to create the File. System. Object and set the reference the fso variable. fso is not a regular variable, is an object reference variable. To assign an object to a variable we must use the Set keyword. After using Build. Path we release fso reference by setting variable to Nothing. Dani Vainstein & Monika Arora Gautam 43
Settings – Environment Tab n n From Menu : File Settings Environment Tab See all available built-in environment values. Product. Dir Value Dani Vainstein & Monika Arora Gautam 44
Define APP_PATH n n Since Environment( “Product. Dir” ) returns only the qtp installation folder, we need to drill down to “samplesflightapp” until we arrive the executables. To keep a generic scripting OO methodology we will define APP_PATH as a Public Constant in FR. vbs Public Const APP_PATH = "samplesflightapp" Dani Vainstein & Monika Arora Gautam 45
Implementing Req 0001 a cont. ' ** Req 0001 a - Calling external function If File. Exists( full. Exe. Name ) Then msg = Environment( "EXE_FILE" ) & " was found under installation folder. " Reporter. Report. Event mic. Pass, "Req 0001 a", "File " & msg Else msg = Environment( "EXE_FILE" ) & " was not found under installation folder. " Reporter. Report. Event mic. Fail, "Req 0001 a", "File " & msg Exit. Test( mic. Fail ) End If n This one is simple. If the function returns True, Req 0001 a was achieved successfully, otherwise we send an error message to Reporter object and finish the test. Dani Vainstein & Monika Arora Gautam 46
Insert a step – Using Step Generator n n n Insert a call to function. Activate the Step Generator. Menu : Insert Step Generator Hotkey : Toolbar : Step Generator Dani Vainstein & Monika Arora Gautam 47
Insert a step – Using Step Generator Category : Utility Objects Object : System. Util Operation : Run Dani Vainstein & Monika Arora Gautam 48
Configure a value Parameter Environment Type EXE_FILE Dani Vainstein & Monika Arora Gautam 49
Insert a step – Using Step Generator Dani Vainstein & Monika Arora Gautam 50
Implementing Req 0001 b ' ** Activating Application FR System. Util. Run Environment. Value( "EXE_FILE" ), vb. Null. String, exec. Path, "open" n n n System. Util. Run method activates the executable file. The file name to execute is stored in Environment( “EXE_FILE” ). Remark q q You need to manually fix “execpath” ( String ) to execpath Variable ( only if used the Step Generator ). Also the Value word after Environment is not coming by itself, enter it manually. Value is the default property of Environment, so Environment (“A”) is the same as Environment. Value (“A”) Dani Vainstein & Monika Arora Gautam 51
Implementing Req 0001 b ' ** Calling gui. Login/Req 0001 Run. Action "gui. Login [gui. Login]", one. Iteration, "Req 0001" n n The Run. Action command calls the reusable Action gui. Login in [gui. Login] test file. The
Inserting a call to an existing action n Menu : Insert Call to Existing Action… Type : Alt + I + T Toolbar as shown below : Dani Vainstein & Monika Arora Gautam 53
Inserting a call to an existing action n Open gui. Login Test… Dani Vainstein & Monika Arora Gautam 54
Inserting a call to an existing action Keep Relative Path After the current step Dani Vainstein & Monika Arora Gautam 55
Inserting a call to an existing action n n After you inserted the call successfully, you should see in the action list combo-box two actions. The blue arrow means a “Local Reusable Action” The red arrow means a “External Reusable Action” External reusable action is always READ ONLY. Dani Vainstein & Monika Arora Gautam 56
bus. Login. Mng – Final Look Dani Vainstein & Monika Arora Gautam 57
Initialization Sub-Routine n n To make QTP behaves the same, every time regardless of running scripts on same or different machines, we need an initialization routine. The initialization routine, will be located in FR. vbs. The initialization routine is a sub-routine of type Sub. To learn the differences between Functions and Sub please refer to QTP help. Dani Vainstein & Monika Arora Gautam 58
Initialization Sub-Routine - Minimizing QTP n n First we want to minimize the QTP window, to see our script working on the AUT. QTP COM has a property “Window. State”, to access the properties we need to create an object reference to Quick. Test. Application Set qtp = Create. Object( "Quick. Test. Application" ) n And immediately afterwards qtp. Window. State = "Minimized" Set qtp = Nothing Dani Vainstein & Monika Arora Gautam 59
Loading Environment Xml n n n We don't want to use hard-coded values in our script e. g. “C: Program FilesMercury… “ because in the next release, it might change. So the following programming technique is also a best practice. We know that environment file is located under ENV folder by name “FR. xml”. All we need, is to build a string that specifies the project folder + the file path. In order to do so we will use Load. From. File Method of Environment Object. Since the Load. From. File method, requires the full path file name, we will use Locate method of Path. Finder Object. Dani Vainstein & Monika Arora Gautam 60
Loading Environment Xml n n The Path. Finder. Locate returns the full file path that QTP uses for the specified relative path ( resolves the path ) based on the folders specified in the Folders tab search list ( Tools Options Folders ). This “Path” was specified in the First Presentation. env. Xml = Path. Finder. Locate( "ENVFR. xml" ) Dani Vainstein & Monika Arora Gautam 61
Loading Environment Xml n Checking what Locate returns …. If env. Xml = vb. Null. String Then msg = "Environment file was not found in expected location. " Reporter. Report. Event mic. Warning, Environment("Action. Name"), msg Exit Sub End If n Loading xml… Environment. Load. From. File env. Xml Dani Vainstein & Monika Arora Gautam 62
Programmatically define Record and Run Settings n n We will configure record and run settings. For more information on Using Environment Variables to Specify the Record and Run Details for Your Test please refer to QTP documentation, topic Defining Record and Run Environment Variables Dani Vainstein & Monika Arora Gautam 63
“Killing” existing FR applications n n QTP is very sensitive to object recognition. Duplicate objects might be a problem to QTP. We must avoid this state (multiple instances ). Avoid This!!! Dani Vainstein & Monika Arora Gautam 64
“Killing” existing FR applications n n n The solution is simple, and is a built-in feature of QTP. The Close. Process. By. Name method of System. Util object closes a process according to its name. The method needs a process name to “kill” it; How do we know the process name? q q Open the flight application. Press Alt + Ctrl + Delete to view the Task Manager Dani Vainstein & Monika Arora Gautam 65
“Killing” existing FR applications Flight 4 a. exe Dani Vainstein & Monika Arora Gautam 66
“Killing” existing FR applications n And, since the process name is identical to the executable file name, we’d just loaded from environment file; we will use same executable file name. System. Util. Close. Process. By. Name Environment" )EXE_FILE( " Dani Vainstein & Monika Arora Gautam 67
Initializing Global Dictionary n n The global dictionary is in run-time memory all the time. Before running scripts it is recommended to remove all existing keys. GDictionary. Remove. All() Dani Vainstein & Monika Arora Gautam 68
The initialization Routine – Final Look EXE_ENV_1 : The executable files on which Quick. Test Place the initialization records operations when record and run sessions begin. LNCH_ENV_1 : Whether to open the application when starting routine Subup tofile executable files. You can specify in ten the record and run session (for each corresponding application). FR. vbs, just below the Possible values: CHLD_ENV_1 : Whether to File. Exists Function. record and run on processes created 0 (do not launch the application) by the application during the record and run session. 1 (launch the. File. Save the application) Possible values: 0 (do not record on descendant processes) 1 (record descendant processes) Dani Vainstein & Monika Arora Gautam 69
Implementing Req 0001 b n n Req 0001 b requires GUI operations. GUI operation are implemented in the GUI layer or in the Utils layer. Dani Vainstein & Monika Arora Gautam 70
Implementing gui. Login n n Open the gui. Login reusable action by opening the test RAGLgui. Login menu : File Open Test Hotkey : CTRL+O Toolbar : Dani Vainstein & Monika Arora Gautam 71
Open an existing test Dani Vainstein & Monika Arora Gautam 72
Gui. Login Header '************************************ '@Author : advanced. QTP '@Date Created :
Implement Req 0001 in gui. Login Option Explicit Dim msg Select Case LCase( Parameter. Item( "Step. Name" ) ) Case "req 0001" Case Else msg = "Step. Name parameter not implemented. " Reporter. Report. Event mic. Warning, "Not. Implemeted. Exception", msg Exit. Action( mic. Warning ) End Select n It is a similar template to bus. Login, the difference is the input parameter Step. Name. Dani Vainstein & Monika Arora Gautam 74
Implement Req 0001 in gui. Login Case "req 0001" If Dialog( "Login" ). Exist( 5 ) Then msg = "Dialog 'Login' is displayed" Reporter. Report. Event mic. Pass, "Req 0001 b", msg Else msg = "Dialog 'Login' is not displayed after 5 seconds. " Reporter. Report. Event mic. Fail, "Req 0001 b", msg Call Desktop. Capture. Bitmap( Reporter. Report. Path & "Req 0001 b. png", True ) Exit. Action( mic. Fail ) End If Dani Vainstein & Monika Arora Gautam 75
Implement Req 001 in gui. Login n n After activating the executable ( bus. Login ), we need to check if Dialog “Login” is displayed. Notice that the time out is now 5 seconds, because a possible delay between activation and login can occur hence it is not considered as a defect. Only if after 5 seconds, the Dialog “Login” is not displayed, then the test would fail. And if the test failed for that reason we want to “Document” this incident by sending an image screenshot of the desktop. Call Desktop. Capture. Bitmap( Reporter. Report. Path & "Req 0001 b. png", True ) Dani Vainstein & Monika Arora Gautam 76
gui. Login – Final Look Dani Vainstein & Monika Arora Gautam 77
Create Req 0001 Test Automation FR n LIB RA BL Open a new blank Test and save it under TestsReq 0001 GL RS DOC DAT SETTING Req 0001 TESTS RES BATCH ENV Dani Vainstein & Monika Arora Gautam 78
Test Settings n Modify The Test Settings… Dani Vainstein & Monika Arora Gautam 79
Insert a step – Manually Option Explicit Dim msg, b. Exists Call Initialization() If Reporter. Run. Status = mic. Fail Then msg = "Initialization Process Failed. “ Reporter. Report. Event mic. Fail, Environment( "Test. Name" ), msg Exit. Test( mic. Fail ) End If n n n We call the initialization process defined in FR. vbs If the initialization failed, the test will be terminated. Just type the call to Initialization. Dani Vainstein & Monika Arora Gautam 80
Insert a Call to Existing Action Dani Vainstein & Monika Arora Gautam 81
Insert a Call to Business Module Dani Vainstein & Monika Arora Gautam 82
Insert a Call to Existing Action Use relative path bus. Login After the current step Dani Vainstein & Monika Arora Gautam 83
Req 0001 Test – Final Look “Req 0001” should be added manually while calling reusable-action bus. Login Dani Vainstein & Monika Arora Gautam 84
Check Syntax n n It’s a good practice to check the script syntax after adding functionality and just before closing the test. Menu : Tools Check Syntax Hotkey Ctrl + F 7 Toolbar as shown below: Check Syntax n Additional quick syntax check : Switch from expert view to Keyword view Dani Vainstein & Monika Arora Gautam 85
Syntax Results n If you don’t see the Information pane. Menu : View Hotkey : Alt + V + I Toolbar Information pane Dani Vainstein & Monika Arora Gautam 86
Syntax check Report Valid syntax n n Invalid syntax Dani Vainstein & Monika Arora Gautam 87
Run the Test n n n Always run your test in debug mode. You are the developer, not the tester yet. Running tests, not in debug mode, will save all the results in the hard disk, and this is not required when you’re “debugging” your scripts. Temporary run results folder Dani Vainstein & Monika Arora Gautam 88
Result of Test Req 0001 a Dani Vainstein & Monika Arora Gautam 89
Result of Test Req 0001 b Dani Vainstein & Monika Arora Gautam 90
What’s Next? n n n n n Extending functionality on existing modules. Process design of a test. Build a new function. Adding single object to local repository. Checking single and multiple properties on an object Standard and bitmap checkpoints. Create an initialization action. Create a generic login procedure. Calling to existing reusable-actions. Build a new test. Dani Vainstein & Monika Arora Gautam 91
Special Thanks To n n n Paul Grossman from USA, Chicago. Joydeep Das from India, Hyderabad. Tali Hizkia from Israel, Tel-Aviv. Richi Sharma from USA, New Jersey. Bharathi Babu from India, Pune. Dani Vainstein & Monika Arora Gautam 92
Make sure to visit us for: n n Tutorials Articles Projects And much more @ www. advancedqtp. com Dani Vainstein & Monika Arora Gautam 93