ebook img

Hands-On Selenium WebDriver with Java: A Deep Dive into the Development of End-to-End Tests PDF

422 Pages·2022·17.937 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Hands-On Selenium WebDriver with Java: A Deep Dive into the Development of End-to-End Tests

S C el ov e e ni rs u Hands-On m 4 Selenium WebDriver with Java A Deep Dive into the Development of End-to-End Tests G a r c aí Boni García Foreword by Simon Stewart Hands-On Selenium WebDriver with Java A Deep Dive into the Development of End-to-End Tests Boni García BBeeiijjiinngg BBoossttoonn FFaarrnnhhaamm SSeebbaassttooppooll TTookkyyoo Hands-On Selenium WebDriver with Java by Boni García Copyright © 2022 Boni García. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (https://oreilly.com). For more information, contact our corporate/institu‐ tional sales department: 800-998-9938 or [email protected]. Acquisitions Editor: Suzanne McQuade Indexer: Sam Arnold-Boyd Development Editor: Rita Fernando Interior Designer: David Futato Production Editor: Kristen Brown Cover Designer: Karen Montgomery Copyeditor: Piper Editorial Consulting, LLC Illustrator: Kate Dullea Proofreader: JM Olejarz April 2022: First Edition Revision History for the First Edition 2022-03-31: First Release See https://oreilly.com/catalog/errata.csp?isbn=9781098110000 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Hands-On Selenium WebDriver with Java, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-098-11000-0 [LSI] To the most precious thing to me in the world: my children, Pablo and Carlos. I love you more than anything. Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Part I. Introduction 1. A Primer on Selenium. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Selenium Core Components 3 Selenium WebDriver 5 Selenium Grid 6 Selenium IDE 8 Selenium Ecosystem 10 Language Bindings 10 Driver Managers 11 Locator Tools 12 Frameworks 12 Browser Infrastructure 14 Community 15 Software Testing Fundamentals 16 Levels of Testing 16 Types of Testing 19 Testing Methodologies 21 Test Automation Tools 24 Summary and Outlook 28 v 2. Preparing for Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Requirements 29 Java Virtual Machine 30 Text Editor or IDE 30 Browsers and Drivers 30 Build Tools 31 Optional Software 31 Project Setup 32 Project Layout 32 Dependencies 34 Hello World 45 Using Additional Browsers 48 Summary and Outlook 49 Part II. The Selenium WebDriver API 3. WebDriver Fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Basic WebDriver Usage 53 WebDriver Creation 53 WebDriver Methods 57 Session Identifier 58 WebDriver Disposal 59 Locating WebElements 59 The Document Object Model (DOM) 59 WebElement Methods 61 Location Strategies 62 Finding Locators on a Web Page 72 Compound Locators 74 Relative Locators 76 What Strategy Should You Use? 80 Keyboard Actions 82 File Uploading 83 Range Sliders 84 Mouse Actions 85 Web Navigation 85 Checkboxes and Radio Buttons 86 User Gestures 86 Right-Click and Double-Click 88 Mouseover 89 Drag and Drop 90 vi | Table of Contents Click and Hold 91 Copy and Paste 92 Waiting Strategies 94 Implicit Wait 94 Explicit Wait 96 Fluent Wait 98 Summary and Outlook 100 4. Browser-Agnostic Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Executing JavaScript 101 Synchronous Scripts 102 Pinned Scripts 108 Asynchronous Scripts 109 Timeouts 110 Page Loading Timeout 110 Script Loading Timeout 111 Screenshots 112 WebElement Screenshots 115 Window Size and Position 116 Browser History 117 The Shadow DOM 118 Cookies 120 Dropdown Lists 125 Data List Elements 127 Navigation Targets 128 Tabs and Windows 129 Frames and Iframes 131 Dialog Boxes 133 Alerts, Confirms, and Prompts 134 Modal Windows 136 Web Storage 137 Event Listeners 138 WebDriver Exceptions 142 Summary and Outlook 144 5. Browser-Specific Manipulation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Browser Capabilities 145 Headless Browser 147 Page Loading Strategies 151 Device Emulation 153 Web Extensions 155 Table of Contents | vii Geolocation 160 Notifications 162 Browser Binary 165 Web Proxies 166 Log Gathering 168 Get User Media 169 Loading Insecure Pages 171 Localization 173 Incognito 175 Edge in Internet Explorer Mode 175 The Chrome DevTools Protocol 177 CDP Selenium Wrappers 177 CDP Raw Commands 180 Location Context 191 Web Authentication 191 Print Page 193 WebDriver BiDi 194 Summary and Outlook 196 6. Remote WebDriver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Selenium WebDriver Architecture 197 Creation of RemoteWebDriver Objects 199 RemoteWebDriver Constructor 199 RemoteWebDriver Builder 201 WebDriverManager Builder 201 Selenium-Jupiter 202 Selenium Grid 203 Standalone 203 Hub-nodes 207 Fully Distributed 208 Observability 213 Configuration 216 Cloud Providers 217 Browsers in Docker Containers 219 Docker Images for Selenium Grid 220 Selenoid 222 WebDriverManager 224 Selenium-Jupiter 227 Summary and Outlook 228 viii | Table of Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.