Micro Focus QTP (UFT) Forums
Page Validation for Web Application - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Page Validation for Web Application (/Thread-Page-Validation-for-Web-Application)



Page Validation for Web Application - learnqtsw - 10-08-2010

Hi All,

Please show sample scripts for validating mandatory fields of a web page. I want to check if user tries to save form data without entering data for mandatory field, if the developers has called the required function or not.


Thanks
Swati


RE: Page Validation for Web Application - KavitaPriyaCR - 10-08-2010

I am assuming the scenario as: There is a webpage with fields User Name, Place and DOB. User Name is required field and other 2 are optional. Here when user selects Save button without entering data for Usert ID, system should display error as "Please enter User Name" (Developer calls error function/script at this point).
1. Check the data in that field is empty
Code:
Data1=Browser("").Page("").WEbEdit("name:=Usert ID").GetROProperty("value")
2. Fetch the Error message if displayed on the WebPage. (User descriptive programming here)
By using 1 and 2 we can validate the scenario.


RE: Page Validation for Web Application - A.Saini - 10-08-2010

Hi,

You may take the basic idea from the below code.

The logic is simple submit the form with blank mandatory field & validate the text of popup message.


Code:
'/ *    used of child object to to find out simlar objects(includes mandatory object too)
                                     Set objDef = Description.Create
                                     objDef("micclass").value="WebElement"  ' specific to app
                                     objDef("html tag").value="DIV"     ' specific to app
                                     objDef("class").value="req"        ' specific to app
                                     Set arrObj= Browser("Browser Name").Window("Window Name").Page("Page Name").Frame("Frame Name").ChildObjects(objDef)
                            
'/ *    Getting the child object count.
                                      n= arrObj.count
                            
'/ *    The loop basically used to find out all the mandatory fields visible on the chart window.
                                     For iCnt =1to n-1

'/ *    getting the "html id" value of the current child object .
                                           strReq = arrObj(iCnt).GetROProperty("html id")   ' specific to app
                                           If len(strReq)>3 Then   ' specific to app

'/ *    Using the select case to compare the "html id" to  find out the required filed.        
                                             Select Case strReq
                  
                                                      Case "FNAME_REQ"   ' specific to app
                                                        Browser("Browser Name").Window("Window Name").Page("Patient Chart Page").WebButton("Apply").Click
'/ *        Wait for popup box
                                                        Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").WinButton("OK").WaitProperty "enabled","True",4000
'/ *         Checkpoint for verifying the popup box property like text.
                                                        Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").Static("FieldMessage").Check CheckPoint("First Name")
                                                        Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").WinButton("OK").Click
'/ *       Enter the 'First Name'  in the Frame.        
                                                    Browser("Browser Name").Window("Window Name").Page("Page Name").Frame("Frame Name").WebEdit("First Name").Set "Ankur"
                                            
                                                        Case "DOB_REQ"  ' specific to app
                                                         Browser("Browser Name").Window("Window Name").Page("Patient Chart Page").WebButton("Apply").Click
'/ *        Wait for popup box  
                                                         Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").WinButton("OK").WaitProperty "enabled","True",4000
'/ *         Checkpoint for verifying the popup box property like text.
                                                         Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").Static("FieldMessage").Check CheckPoint("Birth Date")
                                                         Browser("Browser Name").Window("Window Name").Dialog("Windows Internet Explorer").WinButton("OK").Click
'/ *        Enter the 'Birth Day' in the Frame.  
                                                        Browser("Browser Name").Window("Window Name").Page("Page Name").Frame("Frame Name").WebEdit("Month").Set "01"
                                                        Browser("Browser Name").Window("Window Name").Page("Page Name").Frame("Frame Name").WebEdit("Day").Set "10"
                                                        Browser("Browser Name").Window("Window Name").Page("Page Name").Frame("Frame Name").WebEdit("Year").Set "1995"
                                                               End Select
                                            End If
                                        Next

I hope this will help you....

Smile