Selenium Framework Design in Data-Driven Testing 9781788473576

4,161 778 6MB

English Pages 447 Year 2018

Report DMCA / Copyright

DOWNLOAD FILE

Selenium Framework Design in Data-Driven Testing
 9781788473576

Table of contents :
Preface......Page 21
Who this book is for......Page 22
What this book covers......Page 23
To get the most out of this book......Page 25
Download the example code files......Page 26
Conventions used......Page 27
Get in touch......Page 28
Reviews......Page 29
Building a Scalable Selenium Test Driver Class for Web and Mobile Applications......Page 30
Introduction......Page 32
Data-driven testing......Page 33
Selenium Page Object Model......Page 34
DRY......Page 35
What you will learn......Page 36
The singleton driver class......Page 37
Requirements......Page 38
The class signature......Page 39
Class variables......Page 40
JavaDoc......Page 41
Parameters......Page 42
Class methods......Page 43
Using preferences to support browsers and platforms......Page 47
Browser preferences......Page 48
Platforms......Page 52
Using preferences to support mobile device simulators, emulators, and real devices......Page 53
iOS preferences......Page 54
Android preferences......Page 55
Multithreading support for parallel and distributed testing......Page 56
Passing optional arguments and parameters to the driver......Page 59
varargs......Page 60
The parameter for setDriver......Page 62
JVM argument – -Dswitch......Page 63
Parameter processing methods......Page 64
Selenium Grid Architecture support using the RemoteWebDriver and AppiumDriver classes......Page 66
Third-party grid architecture support including the Sauce Labs Test Cloud......Page 68
Using property files to select browsers, devices, versions, platforms, languages, and many more......Page 70
Summary......Page 72
Selenium Framework Utility Classes......Page 73
Introduction......Page 74
Global variables......Page 75
Synchronization utility classes......Page 76
Selenium synchronization classes......Page 77
The ExpectedConditions class......Page 78
WebDriverWait/FluentWait classes......Page 80
Custom synchronization methods......Page 81
The JavascriptExecutor class......Page 84
The TestNG Listener class......Page 87
Building the test listener class......Page 88
Logging the results to the console or log file......Page 89
Including the test runner in the test class or suite......Page 91
File I/O class......Page 92
Property files......Page 93
Lookup table files......Page 95
CSV files......Page 96
Log files......Page 97
The image capture class......Page 99
The capture screen method......Page 100
The capture image method......Page 101
The compare image method......Page 103
The reporter class......Page 105
The JavaMail class......Page 107
Summary......Page 110
Best Practices for Building Selenium Page Object Classes......Page 111
Introduction......Page 112
What you will learn......Page 113
Best practices for naming conventions, comments, and folder structures......Page 114
Naming conventions......Page 115
Comments......Page 117
Folder names and structures......Page 118
Designing and building the abstract base classes for the AUT......Page 121
The abstract class......Page 122
Abstract methods......Page 123
Common locators......Page 124
Common methods......Page 125
Wrap up on base classes......Page 128
Designing and building subclasses for feature-specific pages using inheritance techniques......Page 129
Encapsulation and using getter/setter methods to retrieve objects from the page object classes......Page 136
Exception handling and synchronization in page object class methods......Page 138
Implicit exception handling......Page 140
TestNG difference viewer......Page 142
Explicit exception handling......Page 143
Try...catch exception handling......Page 144
Synchronizing methods......Page 146
Table classes......Page 148
Summary......Page 152
Defining WebDriver and AppiumDriver Page Object Elements......Page 153
Introduction......Page 154
Inspecting page elements on browser applications......Page 155
Types of locators......Page 156
Inheriting WebElements......Page 157
Inspecting WebElements......Page 159
Third-party plugins/tools......Page 162
Inspection of page elements on mobile applications......Page 163
Appium inspector......Page 164
Inspecting mobile elements......Page 166
Standards for using static locators......Page 168
Rules for using standard locators......Page 169
Simple locators......Page 170
CSS locators......Page 172
XPath query locators......Page 173
Referencing static elements in methods......Page 174
Retrieving static elements from other classes......Page 176
Standards for using dynamic locators......Page 177
Single attribute XPath versus CSS locators......Page 178
WebElements......Page 179
MobileElements......Page 183
Multiple attribute XPath versus CSS locators......Page 187
Using dynamic locators in methods......Page 189
Summary......Page 191
Building a JSON Data Provider......Page 192
Introduction......Page 193
What you will learn......Page 194
The TestNG Data Provider class......Page 195
The @DataProvider annotation......Page 196
The @Test annotation......Page 197
Extracting JSON data into Java objects......Page 198
Filtering test data......Page 201
Filtering include and exclude patterns......Page 202
JSON Data File formats......Page 204
The JSONObject class......Page 206
Summary......Page 211
Developing Data-Driven Test Classes......Page 212
Introduction......Page 213
Annotating test class methods using TestNG......Page 215
TestNG annotations......Page 216
@Test......Page 217
TestNG setup/teardown methods......Page 220
Setup methods......Page 221
@BeforeSuite, @BeforeTest, @BeforeGroups, @BeforeClass, and @BeforeMethod......Page 222
Teardown methods......Page 224
@AfterSuite, @AfterTest, @AfterGroups, @AfterClass, and @AfterMethod......Page 225
Order of precedence......Page 226
Naming conventions for test methods......Page 228
Test classes and data files......Page 229
Test methods......Page 230
Test parameters......Page 231
Test groups......Page 232
Test setup/teardown methods......Page 233
Using the TestNG DataProvider......Page 235
Calling page object methods in test classes......Page 238
Exception handling in test classes......Page 242
Test methods......Page 243
The setup/teardown methods......Page 244
The ITestResult class......Page 245
Test listener/reporter classes......Page 246
Designing base setup classes......Page 247
TestNG suite file structure......Page 251
Suite section: ......Page 252
Groups section: ......Page 253
Listeners section: ......Page 255
Test section: ......Page 256
Suite parameters......Page 257
@Parameters......Page 258
Summary......Page 260
Encapsulating Data in Data-Driven Testing......Page 261
Introduction......Page 262
Casting JSON data to Java objects......Page 263
JSON object......Page 264
Sequential numbering of row IDs in the data file......Page 265
Using Java object getter/setter methods......Page 266
Passing data to page object methods......Page 267
Building in positive, negative, boundary, and limit testing......Page 268
Negative testing......Page 269
Confirmation and exception property files......Page 272
Property files......Page 273
Lookup method in DataProvider......Page 274
JSON data file data......Page 275
Converting confirmation/error code on the fly......Page 276
Property files and parsing test data on the fly......Page 277
Environment property files......Page 278
System properties......Page 279
Initializing property file data......Page 280
Global variables versus dynamic data......Page 281
Processing JVM args......Page 283
Retrieving JSON data outside of test methods......Page 284
Supporting multibranded applications......Page 286
Multilocators......Page 287
Conditional code......Page 288
Runtime flags......Page 290
Multiple driver support......Page 291
Dual WebDriver testing......Page 292
Dual WebDriver and AppiumDriver testing......Page 294
Parallel testing......Page 296
Suite XML file......Page 297
Parallel properties method......Page 299
Common setup......Page 300
Summary......Page 302
Designing a Selenium Grid......Page 303
Introduction......Page 304
Virtual grids......Page 306
Grid structure......Page 307
Single browser nodes......Page 308
Multibrowser nodes......Page 309
Single mobile device nodes......Page 310
Multimobile/browser nodes......Page 311
Selenium driver class – WebDriver versus RemoteWebDriver......Page 312
The setDriver method for browser......Page 313
The setDriver method for mobile......Page 315
Overloaded setDriver method for browser......Page 317
Switching from local to remote driver......Page 318
Suite parameters......Page 319
JVM argument......Page 320
Default global variables......Page 321
Processing runtime parameters......Page 322
Selenium standalone server and client drivers......Page 323
Local use of drivers......Page 324
Remote use of drivers......Page 326
Selenium standalone server and browser driver command-line options......Page 327
Selenium hub......Page 328
Selenium hub JSON configuration file......Page 330
Selenium nodes......Page 331
Selenium node JSON configuration file......Page 333
Appium server and mobile simulator/emulator command-line options......Page 336
Appium nodes......Page 337
Appium node JSON configuration file......Page 338
Selenium Grid console......Page 340
Directing traffic to Selenium nodes......Page 343
Multiple nodes of the same platform and version......Page 344
Directing traffic using desired capabilities......Page 345
Maintenance of the Selenium Grid......Page 346
Summary......Page 347
Third-Party Tools and Plugins......Page 348
Introduction......Page 349
IntelliJ IDEA Selenium plugin......Page 350
Sample project files......Page 351
Generating element locators......Page 353
Wrap-up on Selenium Plugin......Page 355
TestNG results in IntelliJ and Jenkins......Page 356
IntelliJ TestNG results......Page 357
Jenkins TestNG results......Page 358
HTML Publisher Plugin......Page 361
Installation......Page 362
BrowserMob Proxy Plugin......Page 363
Getting started......Page 364
ExtentReports Reporter API class......Page 365
ExtentHTMLReporter......Page 366
Dashboard page......Page 367
Categories page......Page 369
Tests page......Page 371
Code sample......Page 375
Sauce Labs Test Cloud services......Page 377
Sauce Labs Test Cloud features......Page 378
Browser and mobile platforms......Page 379
Driver code changes......Page 380
Dashboard......Page 382
SauceConnect tunnel......Page 383
TestObject Real Device Cloud......Page 384
Jenkins plugin......Page 386
Advantages and disadvantages of using in-house versus third-party grids......Page 387
Summary......Page 389
Working Selenium WebDriver Framework Samples......Page 390
Introduction......Page 391
Selenium driver and DataProvider classes......Page 393
CreateDriver.java......Page 394
JSONDataProvider class......Page 398
Selenium utility classes......Page 401
BrowserUtils.java......Page 402
Global_VARS.java......Page 404
TestNG_ConsoleRunner.java......Page 405
selenium.properties......Page 411
ExtentReports classes......Page 412
ExtentTestNGIReporterListener.java......Page 413
extent-config.xml......Page 419
Browser page object base and subclasses......Page 421
PassionTeaCoBasePO.java......Page 422
PassionTeaCoWelcomePO.java......Page 425
Browser test class and data files......Page 429
PassionTeaCoTest.java......Page 430
PassionTeaCo.json......Page 436
Browser Suite XML and Maven Pom XML files......Page 440
PassionTeaCo.xml......Page 441
pom.xml file......Page 443
Summary......Page 447

Polecaj historie