1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Cucumber Recipes doc

266 695 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Cover

  • Table of Contents

  • Foreword

    • Agile

    • Patterns

    • Platforms

    • Progress

  • Acknowledgments

  • Introduction

    • Who This Book Is For

    • How to Use This Book

    • Getting the Tools You'll Need

    • Online Resources

  • 1. Cucumber Techniques

    • Recipe 1. Compare and Transform Tables of Data

    • Recipe 2. Generate an RTF Report with a Custom Formatter

    • Recipe 3. Run Slow Setup/Teardown Code with Global Hooks

    • Recipe 4. Refactor to Extract Your Own Application Driver DSL

    • Recipe 5. Define Steps as Regular Ruby Methods

    • Recipe 6. Compare Images

    • Recipe 7. Test Across Multiple Cores

    • Recipe 8. Test Across Multiple Machines with SSH

    • Recipe 9. Run Your Features Automatically with Guard and Growl

    • Recipe 10. Add Cucumber to Your Continuous Integration Server

    • Recipe 11. Publish Your Documentation on Relish

    • Recipe 12. Test Through Multiple Interfaces Using Worlds

    • Recipe 13. Manipulate Time

    • Recipe 14. Drive Cucumber's Wire Protocol

    • Recipe 15. Implement a Wire Protocol Listener

  • 2. Java

    • Recipe 16. Use Cucumber Directly with JRuby

    • Recipe 17. Use Cucumber with Java via Cucumber-JVM

    • Recipe 18. Drive a Spring + Hibernate Project

    • Recipe 19. Test a Grails App Using grails-cucumber

    • Recipe 20. Test Scala Code

    • Recipe 21. Test Clojure Code

    • Recipe 22. Drive a Swing Interface with FEST

  • 3. .NET and Windows

    • Recipe 23. Get Good Text Output on Windows

    • Recipe 24. Test .NET Code with SpecFlow

    • Recipe 25. Drive a Windows App Using White

    • Recipe 26. Test Windows GUIs with AutoIt

    • Recipe 27. Test on Windows Phone

  • 4. Mobile and Web

    • Recipe 28. Test on iOS Using Frank

    • Recipe 29. Test Android Apps with Calabash

    • Recipe 30. Parse HTML Tables

    • Recipe 31. Drive JavaScript/CoffeeScript Using Cucumber-JS

    • Recipe 32. Test a Web App Using Watir

    • Recipe 33. Test a PHP App with cuke4php

    • Recipe 34. Play Back Canned Network Data Using VCR

    • Recipe 35. Drive a Flash App Using Cuke4AS3

    • Recipe 36. Monitor a Web Service Using Nagios and Cucumber

  • 5. Other Languages and Platforms

    • Recipe 37. Drive a Mac GUI Using AppleScript and System Events

    • Recipe 38. Drive a Mac GUI Using MacRuby and AXElements

    • Recipe 39. Test Python Code Using Lettuce

    • Recipe 40. Test Erlang Code

    • Recipe 41. Test Lua Code Using cucumber-lua

    • Recipe 42. Test a GUI on Linux, Mac, or Windows with Sikuli

    • Recipe 43. Test an Arduino Project Using Serial

  • A1. RSpec Expectations

    • Basics

    • Custom Matchers

    • Alternatives

  • Bibliography

  • Index

    • – SYMBOLS –

    • – DIGITS –

    • – A –

    • – B –

    • – C –

    • – D –

    • – E –

    • – F –

    • – G –

    • – H –

    • – I –

    • – J –

    • – K –

    • – L –

    • – M –

    • – N –

    • – O –

    • – P –

    • – R –

    • – S –

    • – T –

    • – U –

    • – V –

    • – W –

    • – X –

    • – Y –

Nội dung

www.it-ebooks.info www.it-ebooks.info Early Praise for Cucumber Recipes With Cucumber Recipes you feel like the authors are right there with you, offering you advice, showing you hidden gems, or gently chastising you for things you know you shouldn’t be doing. From general advice about taming unruly test suites or scaling out across multiple servers, to craziness like testing embedded Arduino hardware projects, they manage to cover an enormous amount of ground in a small space. Prepare for a fun and informative ride. ➤ Dan North Originator of BDD and author of the RSpec story runner (Cucumber’s predecessor) There are many cookbooks but very few “chef books.” Cucumber Recipes is inspiring enough to qualify as a chef book. If there’s a will and a desire to use Cucumber in the process, Cucumber Recipes will more than likely show you a way or many ways! From the basic to the esoteric, there’s something for everyone in Cucumber Recipes. ➤ Michael Larsen Senior quality assurance engineer, SocialText It is good to see that a free tool like Cucumber has been able to build up a com- munity that treats BDD as its own child and carries it to nearly every possible platform and technology. This book provides a closer look at the details. ➤ Gáspár Nagy Developer coach at TechTalk, creator of SpecFlow www.it-ebooks.info If you’re automating tests of any kind using Cucumber, in any language, against any type of software, you need this cookbook. Its recipes will help you write useful, easily maintained tests for even the most puzzling scenarios. Like all good cook- books, it teaches good techniques and principles that will help you improve all your tests. Best of all, you can actually code the examples yourself, and learn by doing. ➤ Lisa Crispin Co-author, Agile Testing: A Practical Guide for Testers and Agile Teams Cucumber Recipes has testing solutions for a variety of platforms. It is a powerful book that gives us useful tips to use BDD in our chosen environment. To realize the power of BDD, Cucumber Recipes is a must on every software test engineer’s table. ➤ Kavitha Naveen Senior lead—quality engineering www.it-ebooks.info Cucumber Recipes Automate Anything with BDD Tools and Techniques Ian Dees Matt Wynne Aslak Hellesøy The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina www.it-ebooks.info Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com . The team that produced this book includes: Jackie Carter (editor) Potomac Indexing, LLC (indexer) Kim Wimpsett (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2013 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-937785-01-7 Encoded using the finest acid-free high-entropy binary digits. Book version: P1.0—February 2013 www.it-ebooks.info Contents Foreword . . . . . . . . . . . . . vii Acknowledgments . . . . . . . . . . . xi Introduction . . . . . . . . . . . . xiii 1. Cucumber Techniques . . . . . . . . . . 1 Recipe 1. Compare and Transform Tables of Data 2 Recipe 2. Generate an RTF Report with a Custom Formatter 7 Recipe 3. Run Slow Setup/Teardown Code with Global Hooks 13 Recipe 4. Refactor to Extract Your Own Application Driver DSL 18 Recipe 5. Define Steps as Regular Ruby Methods 22 Recipe 6. Compare Images 27 Recipe 7. Test Across Multiple Cores 33 Recipe 8. Test Across Multiple Machines with SSH 36 Recipe 9. Run Your Features Automatically with Guard and Growl 41 Recipe 10. Add Cucumber to Your Continuous Integration Server 47 Recipe 11. Publish Your Documentation on Relish 55 Recipe 12. Test Through Multiple Interfaces Using Worlds 61 Recipe 13. Manipulate Time 67 Recipe 14. Drive Cucumber’s Wire Protocol 72 Recipe 15. Implement a Wire Protocol Listener 75 2. Java . . . . . . . . . . . . . . . 83 Recipe 16. Use Cucumber Directly with JRuby 84 Recipe 17. Use Cucumber with Java via Cucumber-JVM 87 Recipe 18. Drive a Spring + Hibernate Project 92 Recipe 19. Test a Grails App Using grails-cucumber 99 www.it-ebooks.info Recipe 20. Test Scala Code 104 Recipe 21. Test Clojure Code 109 Recipe 22. Drive a Swing Interface with FEST 111 3. .NET and Windows . . . . . . . . . . . 117 Recipe 23. Get Good Text Output on Windows 118 Recipe 24. Test .NET Code with SpecFlow 124 Recipe 25. Drive a Windows App Using White 130 Recipe 26. Test Windows GUIs with AutoIt 135 Recipe 27. Test on Windows Phone 139 4. Mobile and Web . . . . . . . . . . . 147 Recipe 28. Test on iOS Using Frank 148 Recipe 29. Test Android Apps with Calabash 153 Recipe 30. Parse HTML Tables 160 Recipe 31. Drive JavaScript/CoffeeScript Using Cucumber-JS 164 Recipe 32. Test a Web App Using Watir 168 Recipe 33. Test a PHP App with cuke4php 173 Recipe 34. Play Back Canned Network Data Using VCR 181 Recipe 35. Drive a Flash App Using Cuke4AS3 185 Recipe 36. Monitor a Web Service Using Nagios and Cucumber 195 5. Other Languages and Platforms . . . . . . . . 201 Recipe 37. Drive a Mac GUI Using AppleScript and System Events 202 Recipe 38. Drive a Mac GUI Using MacRuby and AXElements 209 Recipe 39. Test Python Code Using Lettuce 214 Recipe 40. Test Erlang Code 217 Recipe 41. Test Lua Code Using cucumber-lua 221 Recipe 42. Test a GUI on Linux, Mac, or Windows with Sikuli 225 Recipe 43. Test an Arduino Project Using Serial 230 A1. RSpec Expectations . . . . . . . . . . 237 A1.1 Basics 237 A1.2 Custom Matchers 238 A1.3 Alternatives 239 Bibliography . . . . . . . . . . . . 241 Index . . . . . . . . . . . . . . 243 Contents • vi www.it-ebooks.info Foreword There was a time when one could analyze all that a program needed to do and then write the program that met that need. This stopped being a winning strategy when computers got big enough and fast enough to hold a description of the problem, not just the solution. I embraced this change that went by the name of object-oriented programming. The advice was to divide large programs into parts that captured natural diversity. Then we were to program the parts to ask other parts for results without saying exactly how these results were to be achieved. This sounded simple. We no longer had to think everything through all of the time. Then, when we discovered one more case late in development, we were thankful we kept that complexity at a distance. It was a good plan, but it turned out to be not quite that simple. Not only was there more than one way to chop up a program into parts, there was no easy way to tell which approach was going to prove to be leveraged when unforeseen needs surfaced, as they always do. Agile We forged ahead. We found dozens of techniques that helped keep track of what we had done, where we were going, and, especially, how to say “yes, we can” when asked to do something never once mentioned until our programs were used. When we say Agile today, we’re distinguishing ourselves from the days when we would resist change even if it meant finishing a program that wouldn’t be used. We asked our pioneers to experiment. We asked that they try new things and share with each other how they worked out. We asked our best developers to think about these new problems: where have we been, where are we going, and how will we know when we get there? This book carries that tradition forward. Let me explain how. report erratum • discuss www.it-ebooks.info Patterns A program is a mathematical object that follows precise rules. This stops being important when we can no longer fully analyze our problems as we might a proof. Our progress toward Agile accelerated when we started cata- loging solutions rather than deriving new ones from scratch each time they occurred. A recurring pattern became an object of interest. A recurring problem in a context and a solution known to work—this is something worth sharing. When we started naming and documenting these patterns, we created a liter- ature that had not yet existed. Practical problem solving was respected. Well-worn solutions were judged valuable more valuable even than the most innovative ideas. Although Cucumber offers a new and innovative way of pushing Agile forward, there is no reason for every Cucumber user to rediscover the contents of this book. The solutions come from many, for sure. But the simple existence of this catalog will raise our collective competence as we come to know of solu- tions whether we need them right now or not. This book covers lots of ground. Some of it you will use immediately; other parts you will later. However, you will be served well to know the range of problems already solved. Platforms We appreciate how computers become more powerful each year. We hardly think of them as computers anymore. But they still need to be programmed. When we say Agile means “yes, we can,” we make a promise that becomes more difficult as capabilities proliferate. And each capability has its own constituents that want our attention. Cucumber makes much of artifacts that can be shared across disciplines. A developer and a business analyst will bring different skills to a project. But if they are to coordinate their work, there must be some things they share. Cucumber meets that need. This same distance from implementation allows Cucumber to straddle today’s diverse implementation technologies. As our customers come to know many platforms, they expect us to know them too. As developers we begin to feel new pressure. Each platform has its quirks. That is where this book excels. As you are pressed into delivery on new platforms, you can bring Cucumber with you. But how do you hook it up? Read how here. Foreword • viii report erratum • discuss www.it-ebooks.info [...]... bonus recipes on the topics we just didn’t have room for in the book We welcome guest recipe posts from anyone who’d like to fork the blog on GitHub.12 Now, let’s jump into those recipes! 9 10 11 12 http://pragprog.com/titles/dhwcr https://github.com /cucumber/ cucumber -recipes- book-code http://cukerecip.es https://github.com /cucumber/ cukerecip.es www.it-ebooks.info report erratum • discuss CHAPTER 1 Cucumber. .. a buyer When I search for available cars Then I should see the following cars: | color | model | | rust | Camaro | | blue | Gremlin | 1 2 http://rdoc.info/github /cucumber/ cucumber /Cucumber/ Ast/Table http://www.ruby -doc. org/stdlib-1.9.3/libdoc/bigdecimal/rdoc/index.html www.it-ebooks.info report erratum • discuss Compare and Transform Tables of Data •3 Your team has standardized on the U.S spelling... living documentation, no matter the software environment Who This Book Is For This book isn’t an introduction to Cucumber If you’re looking for a beginner’s guide, you might want to start with The Cucumber Book [WH11] by Matt Wynne and Aslak Hellesøy (two of the contributors to the book you’re reading now) There’s also quite a bit of getting-started information on the official Cucumber site.1 Cucumber Recipes. .. whenever it sees the start of an XML tag, the end of a document, and so on 4 5 6 https://github.com/clbustos/rtf https://github.com /cucumber/ cucumber/wiki/Custom-Formatters http://en.wikipedia.org/wiki/Rich_Text_Format www.it-ebooks.info report erratum • discuss Chapter 1 Cucumber Techniques •8 Cucumber provides a similar mechanism called events While Cucumber runs, it will see various events: the beginning... exploration, you may want to refer to Chapter 1, Cucumber Techniques, on page 1 for general tips that will serve you well, no matter what platform you’re on Getting the Tools You’ll Need This book contains recipes for Ruby, Java, C#, PHP, Scala, Clojure, Erlang, and more Cucumber- Ruby is the original and most popular flavor of Cucumber, so several of our recipes use Ruby Most of these will run across... Formatter •9 Generate a Simple Document When Cucumber starts a test run, it will create an instance of your RtfFormatter class So, the initializer is a good place to create a new RTF document formatters/support/rtf_formatter.rb Line 1 def initialize(step_mother, io, options) 2 @io = io 3 font = RTF::Font.new(RTF::Font::SWISS, 'Verdana') @rtf = RTF::Document.new font 6 end 4 5 Cucumber will always pass three... formatter shows off a lot of the functionality available.8 Third-party formatters like fuubar are another helpful learning resource.9 7 8 9 https://github.com /cucumber/ cucumber/wiki/Custom-Formatters https://github.com /cucumber/ cucumber/tree/master/lib /cucumber/ formatter/html.rb https://github.com/jeffkreeftmeijer/fuubar www.it-ebooks.info report erratum • discuss Run Slow Setup/Teardown Code with Global... domain-specific language (DSL) Let’s consider a simple scenario that tests the behavior of Squeaker,20 an up-and-coming micro-blogging platform 16 17 18 19 20 http://ruby -doc. org/core-1.9.2/Module.html http://rdoc.info/github /cucumber/ cucumber /Cucumber/ RbSupport/RbDsl:World http://rubygems.org/gems/capybara http://www.firefox.com http://squeaker.heroku.com www.it-ebooks.info report erratum • discuss Refactor... use Ruby’s built-in at_exit() method, which allows you to register a hook that runs just as Cucumber is exiting 10 http://www.ruby -doc. org/core-1.9.2/Kernel.html#method-i-at_exit 11 http://seleniumhq.org/docs/03_webdriver.html#ruby 12 http://www.firefox.com www.it-ebooks.info report erratum • discuss Chapter 1 Cucumber Techniques • 14 Let’s look at a test that suffers from repeated setup code and how... the AfterConfiguration hook instead.15 15 https://github.com /cucumber/ cucumber/wiki/Hooks www.it-ebooks.info report erratum • discuss Chapter 1 Cucumber Techniques • 18 Recipe 4 Refactor to Extract Your Own Application Driver DSL Problem Your step definition code is growing out of control When you jump down the stack from your nice, readable Cucumber scenarios into the step definitions behind them, you’re . | 1. http://rdoc.info/github /cucumber/ cucumber /Cucumber/ Ast/Table 2. http://www.ruby -doc. org/stdlib-1.9.3/libdoc/bigdecimal/rdoc/index.html Chapter 1. Cucumber. BDD, Cucumber Recipes is a must on every software test engineer’s table. ➤ Kavitha Naveen Senior lead—quality engineering www.it-ebooks.info Cucumber Recipes Automate

Ngày đăng: 18/02/2014, 05:20

TỪ KHÓA LIÊN QUAN

w