Test Data Preparation: Tips and Tricks
Sargis Sargsyan
Sr. Automation QA Engineer at Workfront
SQA Days 2017
2
TABLE OF CONTENTS - OUR AGENDA
What is Test Data?

Why is it
Important?
1
What is Test Data
Generation?
2
Why should test
data be created
before test
execution?
3
Object class
generation based
on JSON
4
Maintaining
responses of HTTP
requests using
Jackson library
5
How to store login
info in browser to
avoid logging in
from UI
6
Q&A
7
Test Data
Preparation via
HTTP requests
4
SQA Days 2017
3
WHAT IS TEST DATA? WHY IS IT IMPORTANT?
1. A single Selenium test should test one and only thing. A bug in another part of the application
that is not exactly related to the test should not cause the test to fail.
2. Every test should be independent. The test outcome should not affected by another test in the
suite.
3. Make a faster tests. As quicker test suite as much useful it is.
4. Every test should create and clean the data before and the after the test run.
When we are talking about best practice in Selenium test,
some of things often come up are:
SQA Days 2017
4
WHAT IS TEST DATA? WHY IS IT IMPORTANT?
Each test run does the following
Run the testTest initialize Test clean up
SQA Days 2017
5
WHAT IS TEST DATA GENERATION?
Test Data Generators based on their approaches are typically classified into
Random Test Data Generators
Goal Oriented Generators Intelligent Test Data Generators
Pathwise Data Generators
TD
SQA Days 2017
6
WHY SHOULD TEST DATA BE CREATED BEFORE TEST EXECUTION?
!
!
Login 
Submissions 
 Pages Navigation

TD
The reason for this is that
Selenium tests often involve
setups that may include
Only after doing those things
you are ready to assert
on some aspect of the website
 Actions
Sign up   Interactions
Test Data Preparation via HTTP requests
SQA Days 2017
8
BASIC IDEA BEHIND COMBINING THESE TOOLS
These are the steps how to get started with OKHttp and Test Data Preparation
FIRST STEP
We will be creating
instances of HTTP
for various methods
like GET,PUT,POST
etc. by mentioning
the request URL
SECOND STEP
We will be
composing the
request body as
JSON
THIRD STEP
Execute the desired
HTTP method when
headers etc are all
set
FOURTH STEP
Capture the
response and
convert it to a JSON
object.
FIFTH STEP
Desterialize JSON to
any Java Object
SQA Days 2017
9
OKHTTP - WILL DO REST FOR YOU
SQA Days 2017
10
POSTMAN - BEST FRIEND OF YOU
SQA Days 2017
11
OKHTTP - BASIC EXAMPLE FOR GET
SQA Days 2017
12
OKHTTP - BASIC EXAMPLE FOR POST
SQA Days 2017
13
GENERATE JAVA OBJECT CLASS BASED ON JSON
SQA Days 2017
14
GENERATE JAVA OBJECT CLASS BASED ON JSON
SQA Days 2017
15
JACKSON- CONVERT JAVA OBJECT TO / FROM JSON
15
Let’s see how to use Jackson 2.x to convert Java object to / from JSON.
Convert Java object to
JSON

Convert JSON to Java
object

SQA Days 2017
16
JACKSON - CONVERT JAVA OBJECT TO JSON
16

SQA Days 2017
17
JACKSON - JSON FROM STRING TO OBJECT
17

SQA Days 2017
18
JACKSON - RETRIEVE OBJECT VIA API
18
Skipping login from UI
SQA Days 2017
20
AVOID CONSTANTLY TESTING LOGIN PAGE
These 3 steps to skip testing Login continuously

send an HTTP request to
log in

set the session cookie
value

Navigate to a app specific
page

Login Succeed
SQA Days 2017
21
GENERATE SESSION ID VIA API
SQA Days 2017
22
GENERATE SESSION ID VIA API
SQA Days 2017
23
A SINGLE TEST WILL LOOK LIKE
SQA Days 2017
24
SINGLE TEST RUN
Best Practice vs. Bad Practice
SQA Days 2017
26
BEST PRACTICE VS. BAD PRACTICE
Use PageObjects
pattern
"
SQA Days 2017
27
BEST PRACTICE VS. BAD PRACTICE
XPATH is the best
selector to use
#
Preferred selector order : id > name > css > xpath
SQA Days 2017
28
BEST PRACTICE VS. BAD PRACTICE
Automate
CAPTCHAS
#
CAPTCHAs can be bypassed using two strategies:
• The first idea is to disable CAPTCHAs in your test environment.
• The second idea is to add a hook to allow tests to bypass the CAPTCHA.
SQA Days 2017
29
BEST PRACTICE VS. BAD PRACTICE
Create Specific
Application User per
Test
"
SQA Days 2017
30
BEST PRACTICE VS. BAD PRACTICE
Suite Retries
#"
SQA Days 2017
31
BEST PRACTICE VS. BAD PRACTICE
Gmail and Facbook
Logins
#
WebDriver is not the ideal choice to automate login into websites like Gmail and Facebook,
firstly because it is against their policy and secondly because it is slow and unreliable.
The most appropriate choice would be to use the API that these websites provide.
SQA Days 2017
32
BEST PRACTICE VS. BAD PRACTICE
Performance Testing
Using WebDriver
#
Using selenium WebDriver is not an ideal choice for performance testing, not
because it can’t do it but because it is not meant for this job ultimately tester might
not get good results.
SQA Days 2017
33
BEST PRACTICE VS. BAD PRACTICE
Make Tests
Independent Of Each
Other
"
SQA Days 2017
34
BEST PRACTICE VS. BAD PRACTICE
Avoid Thread.sleep
prefer Wait or
FluentWait
"
QUESTIONS?
Go Ahead, Don’t Hesitate!
?
THANK YOU!
Have a Nice Day!


@sargisqa

/sargissargsyansargis.sargsyan@live.com

Test Data Preparation: Tips and Tricks

  • 1.
    Test Data Preparation:Tips and Tricks Sargis Sargsyan Sr. Automation QA Engineer at Workfront
  • 2.
    SQA Days 2017 2 TABLEOF CONTENTS - OUR AGENDA What is Test Data?
 Why is it Important? 1 What is Test Data Generation? 2 Why should test data be created before test execution? 3 Object class generation based on JSON 4 Maintaining responses of HTTP requests using Jackson library 5 How to store login info in browser to avoid logging in from UI 6 Q&A 7 Test Data Preparation via HTTP requests 4
  • 3.
    SQA Days 2017 3 WHATIS TEST DATA? WHY IS IT IMPORTANT? 1. A single Selenium test should test one and only thing. A bug in another part of the application that is not exactly related to the test should not cause the test to fail. 2. Every test should be independent. The test outcome should not affected by another test in the suite. 3. Make a faster tests. As quicker test suite as much useful it is. 4. Every test should create and clean the data before and the after the test run. When we are talking about best practice in Selenium test, some of things often come up are:
  • 4.
    SQA Days 2017 4 WHATIS TEST DATA? WHY IS IT IMPORTANT? Each test run does the following Run the testTest initialize Test clean up
  • 5.
    SQA Days 2017 5 WHATIS TEST DATA GENERATION? Test Data Generators based on their approaches are typically classified into Random Test Data Generators Goal Oriented Generators Intelligent Test Data Generators Pathwise Data Generators TD
  • 6.
    SQA Days 2017 6 WHYSHOULD TEST DATA BE CREATED BEFORE TEST EXECUTION? ! ! Login  Submissions   Pages Navigation  TD The reason for this is that Selenium tests often involve setups that may include Only after doing those things you are ready to assert on some aspect of the website  Actions Sign up   Interactions
  • 7.
    Test Data Preparationvia HTTP requests
  • 8.
    SQA Days 2017 8 BASICIDEA BEHIND COMBINING THESE TOOLS These are the steps how to get started with OKHttp and Test Data Preparation FIRST STEP We will be creating instances of HTTP for various methods like GET,PUT,POST etc. by mentioning the request URL SECOND STEP We will be composing the request body as JSON THIRD STEP Execute the desired HTTP method when headers etc are all set FOURTH STEP Capture the response and convert it to a JSON object. FIFTH STEP Desterialize JSON to any Java Object
  • 9.
    SQA Days 2017 9 OKHTTP- WILL DO REST FOR YOU
  • 10.
    SQA Days 2017 10 POSTMAN- BEST FRIEND OF YOU
  • 11.
    SQA Days 2017 11 OKHTTP- BASIC EXAMPLE FOR GET
  • 12.
    SQA Days 2017 12 OKHTTP- BASIC EXAMPLE FOR POST
  • 13.
    SQA Days 2017 13 GENERATEJAVA OBJECT CLASS BASED ON JSON
  • 14.
    SQA Days 2017 14 GENERATEJAVA OBJECT CLASS BASED ON JSON
  • 15.
    SQA Days 2017 15 JACKSON-CONVERT JAVA OBJECT TO / FROM JSON 15 Let’s see how to use Jackson 2.x to convert Java object to / from JSON. Convert Java object to JSON  Convert JSON to Java object 
  • 16.
    SQA Days 2017 16 JACKSON- CONVERT JAVA OBJECT TO JSON 16 
  • 17.
    SQA Days 2017 17 JACKSON- JSON FROM STRING TO OBJECT 17 
  • 18.
    SQA Days 2017 18 JACKSON- RETRIEVE OBJECT VIA API 18
  • 19.
  • 20.
    SQA Days 2017 20 AVOIDCONSTANTLY TESTING LOGIN PAGE These 3 steps to skip testing Login continuously  send an HTTP request to log in  set the session cookie value  Navigate to a app specific page  Login Succeed
  • 21.
    SQA Days 2017 21 GENERATESESSION ID VIA API
  • 22.
    SQA Days 2017 22 GENERATESESSION ID VIA API
  • 23.
    SQA Days 2017 23 ASINGLE TEST WILL LOOK LIKE
  • 24.
  • 25.
    Best Practice vs.Bad Practice
  • 26.
    SQA Days 2017 26 BESTPRACTICE VS. BAD PRACTICE Use PageObjects pattern "
  • 27.
    SQA Days 2017 27 BESTPRACTICE VS. BAD PRACTICE XPATH is the best selector to use # Preferred selector order : id > name > css > xpath
  • 28.
    SQA Days 2017 28 BESTPRACTICE VS. BAD PRACTICE Automate CAPTCHAS # CAPTCHAs can be bypassed using two strategies: • The first idea is to disable CAPTCHAs in your test environment. • The second idea is to add a hook to allow tests to bypass the CAPTCHA.
  • 29.
    SQA Days 2017 29 BESTPRACTICE VS. BAD PRACTICE Create Specific Application User per Test "
  • 30.
    SQA Days 2017 30 BESTPRACTICE VS. BAD PRACTICE Suite Retries #"
  • 31.
    SQA Days 2017 31 BESTPRACTICE VS. BAD PRACTICE Gmail and Facbook Logins # WebDriver is not the ideal choice to automate login into websites like Gmail and Facebook, firstly because it is against their policy and secondly because it is slow and unreliable. The most appropriate choice would be to use the API that these websites provide.
  • 32.
    SQA Days 2017 32 BESTPRACTICE VS. BAD PRACTICE Performance Testing Using WebDriver # Using selenium WebDriver is not an ideal choice for performance testing, not because it can’t do it but because it is not meant for this job ultimately tester might not get good results.
  • 33.
    SQA Days 2017 33 BESTPRACTICE VS. BAD PRACTICE Make Tests Independent Of Each Other "
  • 34.
    SQA Days 2017 34 BESTPRACTICE VS. BAD PRACTICE Avoid Thread.sleep prefer Wait or FluentWait "
  • 35.
  • 36.
    THANK YOU! Have aNice Day!   @sargisqa  /sargissargsyansargis.sargsyan@live.com