-
Notifications
You must be signed in to change notification settings - Fork 11
Examples
This section lists some sample code without detailed information to demonstrate the basic functionalities of the test suite.
Examples in YAML-Style:
Examples in CSV-Style:
A simple test case defined with the library's YAML syntax looks like this:
- Action:
Name: Open Website
Request:
Url: ${host}/posters/Based on this definition, the following HTTP request is constructed and fired:
| Request | |
| GET https://localhost:8443/posters/ | |
| Accept | */* |
| Accept-Encoding | gzip, deflate |
| Accept-Language | en-US |
| Connection | Keep-Alive |
| Host | localhost:8443 |
| User-Agent | Mozilla/5.0 ... |
As you can see, some request headers are added to the specified request automatically. The default method is GET since it wasn't defined otherwise.
For the response, the test suite expects a HTTP response with status code 200, which is also defaulted.
The ${host} tag is a variable, which is predefined in the properties and resolved internally.
Here, we want to adjust and overwrite some of the predefined values:
- Action :
Name : Registration
Request :
Method : POST
Url : ${hostsec}/posters/registration
Headers :
- Accept : text/html
- Accept-Language : de
- Unuseful : some value
Parameters :
- btnRegister :
- eMail : [email protected]
- firstName : first name
- name : name
- password : password
- passwordAgain : password
Response :
Httpcode : 303Based on this definition, the resulting HTTP request looks like:
| Request | |
| POST https://localhost:8443/posters/registration | |
| Accept | text/html |
| Accept-Encoding | gzip, deflate |
| Accept-Language | de |
| Content-Length | 104 |
| Connection | Keep-Alive |
| Content-Type | application/x-www-form-urlencoded |
| Host | localhost:8443 |
| Unuseful | some value |
| User-Agent | Mozilla/5.0 ... |
| Post Parameters | |
| btnRegister | |
| [email protected] | |
| firstName | first name |
| name | name |
| password | password |
| passwordAgain | password |
Here we overwrote some of the default header fields and also added another header ("Unuseful"). The parameters are encoded automatically. The expected response status code is 303.
This example demonstrates the validation options:
- Action :
Name : Open Website
Request :
Url : ${host}/posters/
Response :
Httpcode : 200
Validate :
- Validate If title exists:
Regex : "<title>Posters\\s-\\sThe\\sUltimate\\sOnline\\sShop</title>"
- Validate Navigation Item Name:
XPath : "//*[@class='topCategory0']/a"
Text : World of Nature
- Count Topcategory Items :
XPath : "//*[@id='categoryMenu']/ul/li"
Count : 4
- Count Subcategory Items :
XPath : "//*[@id='categoryMenu']//ul[@class='dropdown-menu']/li"
Count : 13
- Validate Title:
XPath : "//*[@id='titleIndex']"
Matches: "Check out our new panorama posters"
The request looks like the first one.
The expected status code is '200'. Since this value is defaulted, we could have skipped it.
Under the Validate tag, four validations are defined, which are executed sequentially.
Every validation has a 'name', an 'extraction method' to grab elements and a 'validation method' to validate the received data. For instance:
- Validate Navigation Item Name:
XPath : "//*[@id='topCategory0']/h4/a"
Text : World of NatureThe validation with the name "Validate Navigation Item Name" extracts the HTML element which can be identified with the XPath expression //*[@id='topCategory0']/h4/a and checks, whether its content equals the text "World of Nature".
See the Validation section for a detailed explanation of the various extraction and validation methods.
The test suite makes a distinction between 'general requests', like the one above, 'XMLHttpRequest' and 'static requests' (see Requests).
Therefore, if you want to load some additional static content, or send a XMLHttpRequest, which all refer to another request, the test suite offers a way to define such subrequests.
- Action :
Name : Go to Product Category
Request :
Url : ${hostsec}/posters/topCategory/Dining?categoryId=2
Subrequests :
- Xhr :
Name : Navigate to second product page.
Request :
Method : POST
Url : ${hostsec}/posters/getProductOfTopCategory
Parameters :
- categoryId : 2
- page : 2
Response :
Validate :
- Validate Product Sandwich :
XPath : "/json/products[2]/name"
Matches : "Peperoni Sandwich"
- Static :
- ${host}/posters/assets/img/products/Food/Grillables/Grillables_3.jpg
- ${host}/posters/assets/img/products/Food/Grillables/Grillables_6.jpg
- ${host}/posters/assets/img/products/Food/Sweets/Sweets_1.jpgFor a XHR request, all the necessary headers are set automatically. But in contrast to the usual request, the response may not be parsed into the DOM.
Static request can be loaded parallel, which is fast, but they cannot be validated.
Note:
A 'general request' can also be a XHR request. The response is not parsed into the DOM, too. Therefore, the XLT result browser either takes a blank page or if there was a 'general request', that wasn't an XHR, the response to the last non-XHR request as screenshot for the result screen.
With the following test case a lot of request are fired with nearly a minimal description. Only the HTTP status code is validated.
Name,URL,ResponseCode
Homepage,"${host}/posters/",200
SearchNOHIT,"${host}/posters/search?searchText=foo${RANDOM.String(5)}",200
SearchHIT,"${host}/posters/search?searchText=dish",200
ProductDetailView,"${host}/posters/productDetail/Selfmade%20Mac%20and%20Cheese?productId=43",200The following test case is more complex. It is really compact and fast to write down. Unfortunately, it is also much harder to read than YAML. The scenario despicts a user who visits an online shop, browses for a product and finally orders it.
# Just load the homepage
A,Homepage, "${host}/posters/",GET,,200,"<h1 id=""titleIndex"">(.*?)</h1>","Check out our new panorama posters!",false
# Select a category[Link Title](page-slug)
A,SelectCategory,"${host}/posters/category/Main%20Dishes?categoryId=5",GET,,200,"<h1 id=""titleCategoryName"">(.*?)</h1>","Main Dishes",false
# View the product in detail
A,ProductDetailView,"${host}/posters/productDetail/XXL%20Burger?productId=48",GET,,200,"<h1 id=""titleProductName"">XXL\s+Burger</h1>",,false
# Configure the product (select finish and size)
XA,ConfigureProduct,"${host}/posters/updatePrice",POST,size=32 x 24 in&productId=48,200,,,false
# Add the configured product to the cart
XA,AddToCart,"${host}/posters/addToCartSlider?productId=48&finish=gloss&size=32%20x%2024%20in",GET,,200,,,false
# View the cart
A,ViewCart,"${host}/posters/cart",GET,,200,"<h1 id=""titleCart"">(.*?)</h1>","Cart",false
# Proceed to checkout
A,Checkout, "${hostsec}/posters/checkout",GET,,200,"<h3 id=""titleDelAddr"">(.*?)</h3>","Select or enter a shipping address",false
# Fill out and submit shipping address form
A,COShipping,"${hostsec}/posters/shippingAddressCompleted",POST,fullName=${DATA.getFirstName(false)} ${DATA.getLastName(false)}&company=Acme Inc&addressLine=123 Rocky Rd&city=${DATA.getTown(false)}&state=California&zip=${RANDOM.Number(5)}&country=United States&billEqualShipp=Yes&btnAddDelAddr=,200,"<h3 id=""titlePayment"">(.*?)</h3>","Select or enter a payment method",false
# Fill out and submit payment form
A,COBilling,"${hostsec}/posters/paymentMethodCompleted",POST,creditCardNumber=4111111111111111&name=Dagobert Duck&expirationDateMonth=01&expirationDateYear=2017&btnAddPayment=,200,"<h1 id=""titleOrderOverview"">(.*?)</h1>","Order Overview",false
# Finally, place the order
A,PlaceOrder,"${hostsec}/posters/checkoutCompleted",POST,btnOrder=,200,,,false