grails functional testing

24

Upload: to-the-new-technology

Post on 11-Apr-2017

230 views

Category:

Technology


0 download

TRANSCRIPT

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…)

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

Functionality Testing - Functional Test

5

••

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

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

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

time!

8

Benefits

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

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

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

11

Assert Methods

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

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

12

Assert Methods

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()

14

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

Methods to retrieve HTML element of page

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

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

}

16

File Upload

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

17

Methods of HTML UNITs

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

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

19

Table

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

getEnclosingTable()

20

Table Row

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

21

Select

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

22

Option

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

oftware/htmlunit/html/package-tree.html

23

References

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!