Download from Wow! eBook <www.wowebook.com> Download from Wow! eBook <www.wowebook.com> 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 Download from Wow! eBook <www.wowebook.com> 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 Download from Wow! eBook <www.wowebook.com> Cucumber Recipes Automate Anything with BDD Tools and Techniques Ian Dees Matt Wynne Aslak Hellesøy The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Download from Wow! eBook <www.wowebook.com> 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 Download from Wow! eBook <www.wowebook.com> 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 Download from Wow! eBook <www.wowebook.com> Contents • vi 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 Download from Wow! eBook <www.wowebook.com> 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. Download from Wow! eBook <www.wowebook.com> report erratum • discuss Foreword • viii 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. Download from Wow! eBook <www.wowebook.com> report erratum • discuss
Description: