Top Banner
24

Grails Functional Testing

Apr 11, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Grails Functional Testing
Page 2: Grails Functional Testing

Grails Functional Testing

Page 3: Grails Functional Testing

● Isthe site content meaningful?● Isthis application easy to use?● How about browsercompatible?● Are we using the right tools?● How reliable is ourtechnology?● Do the Servers have enough power?● How many visitors are we expecting?● Arethe machines fast enough?● How much activity can the site

handle?

The NEED to Test (Are we wondering…)

Page 4: Grails Functional Testing

Set of skilled approaches and procedures which systematically verify that the application’s components and process modules, are available and working as expected

(Compliance with Business rules, Technical requirements, System Documentation, and User manuals is of course… Mandatory!)

4

Functionality Testing

Page 5: Grails Functional Testing

Functionality Testing - Functional Test

5

Page 6: Grails Functional Testing

••

6

Functional TestFunctional testing is centered around the following items:• Valid Input - identified classes of

valid input must be accepted• Invalid Input - identified classes

of invalid input must be rejected• Functions - identified func tions

must be exercised• Output - identified classes of

application outputs must be exercised

• Systems/Procedures - interfacing systems or procedures must be invoked

Functionality Testing - Functional Test

Page 7: Grails Functional Testing

Testing that is performed in whole or part by a computer Typically involves recording user actions that are later played

back to re-create those steps Characteristics are:

– Standardization– Scope– Speed– It issues get post calls and then inspect the result

7

Grails Functional Testing

Page 8: Grails Functional Testing

A consistent and reliable process Increases test coverage Test more in lesstime Higher quality software released in less

time!

8

Benefits

Page 9: Grails Functional Testing

8

Installation

InstallationRun: grails install-plugin functional-test

Usage1)Run: grails create-functional-test HelloWorld (String FunctionalTest wil automatically append to the test HelloWorld )

2) Add code to the test methods (method name should start with test)

3)Run: grails functional-tests <URL>(If test is not for the current application)

4) View the output in test/reportsProperties cookiespagecookiesEnabledjavaScriptEnabledredirectEnabled

Page 10: Grails Functional Testing

assertContent <value> (compare with the text supplied with the last response)

assertContentStrict <value> (Strict supports Case sensitive comparison) assertContentContains <value> (just like contains method) assertContentContainsStrict <value> assertContentType <value> (e,g; a"text/html")

10

Assert Methods

Page 11: Grails Functional Testing

assertContentContains <value> assertContentContainsStrict <value>assertHeader <value> (response header contains thevalue or not) assertHeaderStrict <value> assertHeaderContains <value> assertHeaderContainsStrict <value>

11

Assert Methods

Page 12: Grails Functional Testing

assertRedirectUrl <value> assertRedirectUrlContains <value> assertTitle <value> (Title of current

page) assertTitleContains <value> assertMeta <name>, <value> assertMetaContains <name>, <value>

12

Assert Methods

Page 13: Grails Functional Testing

13

assertCookieExists <name> assertCookieExistsInDomain <name>, <domain>

assertCookieContains <name>, <content> assertCookieContainsStrict <name>, <content>assertTrue( condition )

assertFalse ( condition )

Assert Methods

• Methods get(uri)

post(uri)click(idOrLinkText) followRedirect() form(name) clearCache()

Page 14: Grails Functional Testing

14

byId(elementID) byName(elementName) byXPath(xpathQuery)

Methods to retrieve HTML element of page

Page 15: Grails Functional Testing

void testSearch() { get('http://www.twitter.com') click "Search"

assertStatus 200 assertContentContains "search" form('searchForm') {q ="#grails"

selects['currency.id'].select "GBP" agreedTsAndCs trueradioButtons.typeOfService ="POWERUSER" click "Search"

}assertStatus 200 assertContentContains "#grails"

}

15

Page 16: Grails Functional Testing

• form(’formName’) {yourFileName.contentType =“text/plain” yourFileName.data =new File(’something.txt’).bytes click “submit”

}

16

File Upload

Page 17: Grails Functional Testing

Page Click() String getTextContent() setTexContent() Node getFirstChild() Node getLastChild() String getValueAttribute() DomNode getParentNode()

17

Methods of HTML UNITs

Page 18: Grails Functional Testing

18

initialize() Page refresh()String getTitleText()void setTitleText(String message)List<HtmlForm> getForms()HtmlForm getFormByName(String name) List<HtmlAnchor> getAnchors() HtmlAnchor getAnchorByName(String name) HtmlElement getElementById(String elementId) HtmlAnchor getFirstAnchorByText(String text) HtmlAnchor getAnchorByHref(String href)

Page

Page 19: Grails Functional Testing

HtmlTableRow getRow(int index) HtmlTableRow getRowById(String id) int getRowCount() List<HtmlTableRow> getRows() HtmlTableCell getCellAt(int rowIndex, int columnIndex)

19

Table

Page 20: Grails Functional Testing

HtmlTableCell getCell(int index) List<HtmlTableCell> getCells() HtmlTable

getEnclosingTable()

20

Table Row

Page 21: Grails Functional Testing

String getDefaultValue() HtmlOption getOption(int index) HtmlOption getOptionByValue(String value) List<HtmlOption> getOptions() int getOptionSize() List<HtmlOption> getSelectedOptions()

21

Select

Page 22: Grails Functional Testing

HtmlSelect getEnclosingSelect() String getText() boolean isDisabled() boolean isSelected()

22

Option

Page 23: Grails Functional Testing

● http://www.grails.org/Grails+Functional+Testing● http://htmlunit.sourceforge.net/apidocs/com/gargoyles

oftware/htmlunit/html/package-tree.html

23

References

Page 24: Grails Functional Testing

Contact us

Our Office

Client Location

Click Here To Know More!

Have more queries on Grails? Talk to our GRAILS experts Now!

Talk To Our Experts

Here's how the world's biggest Grails team is building enterprise applications on Grails!