slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Selenium: Browser-Based Automated Testing for Grails Apps PowerPoint Presentation
Download Presentation
Selenium: Browser-Based Automated Testing for Grails Apps

Loading in 2 Seconds...

play fullscreen
1 / 18

Selenium: Browser-Based Automated Testing for Grails Apps - PowerPoint PPT Presentation


  • 654 Views
  • Uploaded on

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Selenium: Browser-Based Automated Testing for Grails Apps' - guest3727


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

- Selenium -

Browser-Based Automated Testing of Grails Apps

  • Presented By
  • Chris Bedford
  • Founder & Lackey at Large
  • Build Lackey Labs
  • Company Overview
    • Founded 2009
    • Services
    • Release engineering & Build/Test Automation for Java Environments
    • Spring/Hibernate & Groovy/Grails App Development
    • Training: Spring/Groovy/Grails & Build/Test Automation Technologies
    • Employees
    • Chris Bedford
    • Mike Jackson
slide2

Agenda

KEY

TAKE-AWAYS

Different Ways To Test a Grails App

Unit, Integration, Functional

Selenium

Demo of IDE

Architecture

Alternatives (CanooWebTest)

Automating Testing Using Selenium

Maven

Cargo

Viewing Test Results

Alternative Automation Strategies

grails-selenium-rcplugin

How to write functional tests with

Selenium

How to set up

Selenium Testing

On Grails Apps

In Continuous

Integration

The long way – using Maven and/or

Ant

The fast way, using the grails- selenium-rc plug-in

  • Handy to know
  • if you are working
  • with non-Grails web apps
slide3

Different Ways To Test a Grails App

Package or class level scope

  • Unit
  • Unit Tests are created and run developer and run using framework like Junit or TestNG
  • test class or package functionality in isolation
  • heavy use of mocks and stubs
  • tests should execute quickly and be run often to catch problems early on
  • Integration
  • Application is spun up within Grails running on top of servlet container
  • Uses actual underlying framework instead of mocks
  • Slower to run due to overhead of spinning up Grails
  • Functional Testing
  • Run application in container
  • Exercise functionality via a client side agent that executes Javascript.
    • Agent could be either:
    • your actual target browser (Firefox, IE, etc.) [Selenium's approach]
    • a Javascript engine embedded into test framework [CanooWebtest's approach]

Mock http requests

Mock Hibernate Functionality

Client requests from same process

Launch Grails container

Real Hibernate

increasingly coarse grained

components under test

Real http requests

Separate client

slide4

Manual Steps Involved In Running Selenium

  • Before running Selenium Functional Tests we need to
    • Compile classes
    • Run unit and integration tests
      • bail on functional tests if we catch problems with lighter weight tests
    • Package .war file
    • Install the container in which we want to run the .war (optional)
    • Deploy the .war to the container (optional – can just do ‘grails run-app’)
    • Launch target browser
    • Launch Selenium on desired test suite
slide8

Saving New or Modified Selenium Tests

Individual tests referenced by the suite are recorded using their paths relative to the suite. For simplicity put your suite and all tests in the same directory (to start)

slide9

Selenium Components

  • Selenium IDE
  • Selenese Commands
    • Enable test author to
      • simulate navigation, clicks
      • Make assertions about expected responses
  • Selenium RC
  • Client side library that enables you to program more sophistication into your tests than the IDE allows (conditions, looping, error handling)
  • The Selenium Server which launches and kills browsers, interprets and runs the Selenese commands passed from the test program, and acts as an HTTP proxy,
slide10

Selenium Client Side Library & Server In Action

(javascript)

(client side java script /

Ajax portion of application under

Test – originates from here )

HTTP

Application

under test

(server side)

Selenium-server.jar

Reports back results of test to client

HTTP

Source:

http://seleniumhq.org/docs/05_selenium_rc.html

slide11

Selenium RC Server Acting As Proxy To Avoid Same Origin Policy Restrictions

4) Server interprets the command and then triggers the corresponding javascript execution to execute that command within the browser (say open page in app under test)s

What happens when a test suite starts ?

Proxy forwards request

to app

server

6)

5) Request to open the page is routed through proxy server

2) Selenium-RC server launches a browser (or reuses an old one) with URL that injects Selenium-Core’s javascript into browser-loaded web page.

7)

App server returns

response

1) client/driver establishes

connection w.selenium-RC

3) client-driver passes a Selenese command to the server e.g.: open command

slide12

Functional Test Alternatives: CanoovsSelenium

  • Canoo Web Test
  • built on HtmlUnit
  • pros:
    • excellent test reporting allows you to pin point errors in test very easily.
    • faster to run (no browser spin up overhead)
    • better support for non HTML content (like spread sheets)
  • cons:
    • Weaker IDE (for test recording and playback)
    • develop tests in Ant or Gant only
  • Selenium
  • pros:
    • develop tests in HTML markup or 3 GL's like Java, Ruby, etc.
    • run test in actual browser
    • vs.embeddedJavascript engine used by NO popular browser platform
  • cons:
    • slower to start.
    • see 'pros' listed Canoo
slide13

Gluing together the steps in your build process

  • Before running Functional Tests need to
    • Compile
    • Run unit and integration tests
      • bail on functional tests if we catch problems with lighter weight tests
    • Package .war file
    • Install the container in which we want to run the .war (optional)
    • Deploy the .war to the container (optional – can just do ‘grails run-app’)
    • Launch your target browser
    • Launch Selenium on your desired test suite
  • To automate this process you can use
      • ant
      • maven
      • Groovy/Gant scripts
      • Gradle
    • Our example uses Maven
    • (demo)
    • (tour of pom.xml files that wire together our build steps)
slide14

Download

And Install

Tomcat

deploy

Compile

Unit Test

  • Integration Test
  • Package .war file
slide15

Maven Basics

  • Convention over configuration
    • Standardizes where things live and what they are named
    • Lets you know where to look for the things you need…
        • and what to do when you find them
  • Shared Repository for storing artifacts that result from a build
  • Build Life Cycle
    • each build project is responsible for producing a distinct artifact (a.k.a. packaging) type
        • .jar, .war, .ear, etc.
    • each packaging type has an associated life cycle (ordered set of build phases)
  • Project Object Model (pom.xml) specifies the complete ‘recipe for your build’
    • what artifact type are your producing ? (the name, the version…)
    • what are the dependencies (things you need) to produce that artifact ?
    • What plug-ins activate at what phases in the build life cycle ?
  • Nested build module structure
    • overall driver for your build project lives at top level of a directory hierarchy
    • sub-modules underneath the parent can be either
      • individual components of your product …or….
      • key phases in your build
slide16

Canoo Web Test Reports

Canoo's reports show overall test results and let you drill down into any test

slide17

Canoo Web Test Reports (cont.)

Click to review a copy of the response HTML page corresponding to the first test step that failed

slide18

Cargo

  • A set of APIs that assists in
  • installing web containers (such as Tomcat, JBoss)
  • booting and shutting them down
  • deploying web applications (.wars and .ears)
  • Invokable via
  • ant tasks
  • maven plugin
  • Java API

<target name="functional-test" >

<cargo containerId="tomcat6x" action="start" … >

<zipurlinstallerinstallurl="http://somewhere/tomcat-6.0.zip"/>

<configuration type="standalone" home="${tomcatdir}">

<deployable type="war" file="foo.war"/>

</configuration>

</cargo>

<plugin> ...

<artifactId>cargo-maven2-plugin</artifactId>

<config>

<wait>false</wait>

<container>

<containerId>tomcat6x</containerId>

<zipUrlInstaller>

<url>http://somewhere/tomcat-6.0.zip</url>

...

Installer installer =

new URL("http://somewhere/tomcat-6.0.zip"));

installer.iZipURLInstaller(new nstall();

LocalConfiguration configuration =

new DefaultConfigurationFactory().createConfiguration("tomcat6x")...)

container = new DefaultContainerFactory() .createContainer("tomcat6x"....);

container.setHome(installer.getHome());

WAR deployable = new WAR("foo.war);

deployable.setContext("ROOT");

configuration.addDeployable(deployable);