Scripting Examples Demonstrate a Variety of Tricks That Can Be Used When Working with Dates And/Or Times
Total Page:16
File Type:pdf, Size:1020Kb
SSccrriippttiinngg EExxaammpplleess Table of Contents USING VARIABLES ............................................. 5 Using Environment, Test Suite, & Data Bank Variables .............................................................................. 5 Accessing Data Source .................................................................................................................................. 6 Accessing Multiple Data Sources .................................................................................................................. 7 Using Environment Variables ....................................................................................................................... 8 Use Datasource Value & Return in XML - Jython (UG) .............................................................................. 9 Use Datasource Value & Return in XML - Javascript (UG) ....................................................................... 10 Access XML Data Bank .............................................................................................................................. 11 Sharing Data Between Two Extension Tools .............................................................................................. 12 Create Test Suite Variable ........................................................................................................................... 13 Test Suite Variables pt. 1 ............................................................................................................................ 14 Test Suite Variables pt. 2 ............................................................................................................................ 15 Test Suite Variables pt. 3 ............................................................................................................................ 16 Test Suite Variables pt. 4 ............................................................................................................................ 17 Change Test Suite Variable By Script ......................................................................................................... 18 BROWSER TESTING SCRIPTS ....................... 19 Accessing DOM of Browser Testing Tool .................................................................................................. 19 Accessing DOM of Browser - Retrieve <title> text of Frame .................................................................... 20 Return Title from Frame in Browser ........................................................................................................... 21 Get HTML Contents from Frame ................................................................................................................ 22 Access HTML Content as String (UG) ....................................................................................................... 23 Create Xpath Hook – Browser Testing (UG) .............................................................................................. 24 Using an XPath with a parameterized value (UG) ...................................................................................... 26 Scripting Element Locators (UG) ................................................................................................................ 27 How to invoke javascript in the browser context ........................................................................................ 28 BROWSER VALIDATION SCRIPTS ............... 30 Complex Browser Testing Validations (UG) .............................................................................................. 30 Validating a “Checked” property of HTML check box .............................................................................. 32 Return Actual Value for Use in Scripted Browser Validation .................................................................... 34 SCANNING TOOL .............................................. 35 Scanning Hook - Alert (UG) ....................................................................................................................... 35 Scanning Hook – Alert 2 (UG).................................................................................................................... 36 Scanning Hook – Confirm and Prompt (UG) ............................................................................................. 37 Scanning Hook – Realm Password (UG) ................................................................................................... 38 2 Scanning Hook – URL Logging (UG) ....................................................................................................... 39 READING/WRITING TO FILES ...................... 40 Writing Elements to a CSV/Excel File W/ a Timestamp ............................................................................ 40 Read Contents of File into String ................................................................................................................ 42 Log/Write Info (xml data bank) to file(old) ................................................................................................ 43 Writing information to a file ....................................................................................................................... 44 Customize File names with datasource values ............................................................................................ 45 How to read the contents of a file into a string ........................................................................................... 46 Reading Text using IOUtil.readTextFile(File) ............................................................................................ 47 Reading Binary file using IOUtil.readBinaryFile(File) ............................................................................... 48 LOAD TEST SCRIPTS ....................................... 49 Load Test Stop Script – Print to Console Merged data ............................................................................... 49 Load Test Stop Script – Print to console current data ................................................................................. 50 Load Test Stop Script – Stop if # of errors exceed N .................................................................................. 51 Load Test Stop Script – Stop if N is above threshold for M measurements ............................................... 52 Simple Monitor which Returns Memory Metrics in Current JVM Environment ....................................... 53 Returning memory metrics in the current JVM ........................................................................................... 54 DATE-TIME SCRIPTS ....................................... 55 Date/Time Scripting Tricks ......................................................................................................................... 55 Date/Time Scripting Tricks ......................................................................................................................... 56 Generates XML Schema dateTime string ................................................................................................... 57 Get a XML Representation of a date ........................................................................................................... 58 Return String containing XML schema dateTime....................................................................................... 59 JDBC SCRIPTS ................................................... 60 Calling Methods on JDBC Objects – DB tool (UG) ................................................................................... 60 How to Query a Database using Jython ...................................................................................................... 61 JDBC Programming pt.1 – Get Connection ................................................................................................ 62 JDBC Programming pt.2 - Create Table ................................................................................................... 63 JDBC Programming pt.3 - Populate Table ................................................................................................ 64 JDBC Programming pt.4 - Select Statement .............................................................................................. 65 JDBC Programming pt.5 - Test GetDriver .................................................................................................. 66 JDBC Programming pt.6 - Test GetDriver ................................................................................................ 67 JDBC Programming pt.7 - Drop Table ...................................................................................................... 68 JDBC Programming pt.8 - Close Connection ............................................................................................ 69 CHANGING PROTOCOLS ............................... 70 3 Switch all Tests’ Protocols to HTTP 1.0 ..................................................................................................... 70 Switch all Tests’ Protocols to HTTP 1.1 ..................................................................................................... 71 GENERATING UUIDS ....................................... 72 Generate & Return Universally Unique ID (UUID) ................................................................................... 72 Generating Unique Number to Write to XML Data Bank