Badak Manual Book
Badak Manual Book
Selamat datang
Sugeng rawuh
wilujeung sumping
Horas !
CONGRATULATION
Kamu adalah anggota dari blibli sekarang ,
You are now member of blibli.
Silahkan merujuk ke dokumen ini sebelum anda mulai bekerja
Please refer to this document before you start to working.
Agenda
Tak kenal maka tak sayang / if you don’t know , then you don’t love it , so let’s introduce
• Pengenalan /
Introduce
• Cara Kerja Framework Automation /
How To Our Automation work
• Cara Koding yang baik dan benar /
How to Write Automation code https://badak.gdn-app.com
• Standard dari kode automation /
Standard from automation code
Agenda
Mulai Ngoding kuy / Let’s start to code
• Mendeploy Artifactory /
deploying artifactory
• Menggunakan Module /
Module Usage
• Integrasi dengan testlink /
Integrate it with Testlink https://badak.gdn-app.com
• Git Branching
• Integrasi dengan Jenkins/
Jenkins Integration
• Setting Badak Jobs
Pengenalan
Introduce
• Automation kita mempunyai 3 macam
model ( Jmeter , UI , dan API )
Our Automation have 3 kinds of models UI
(Jmeter , UI ,and API)
• Dan Basic Codenya adalah Bahasa Java
and basic code language is Java
Let’s Code
Together Java API JMETER
JMETER
Jmeter
Note :
kami menggunakan Java 8 Sebagai standar dalam code automation
We Use Java 8 as the standard in automation Code
API testing
API testing
Write
BDD Adalah Pengembangan dari TDD , scenario
TDD Sendiri adalah Test driven
Developmen yaitu development mengacu
pada story yang telah ditulis terlebih
dahulu. Baik BDD dan TDD Scenario Develop
ditulis terlebih dahulu sebelum Code
mendevelop code.
BDD is emerged from TDD , TDD is Test
driven Development that is development
refers to the story that has been written
first . Both BDD and TDD , the Scenarios Run it !
are written first before developing the code
Konsep BDD
BDD Concept
1. Deskripsikan Behaviour (Login , Order ,
Etc)
Describe Behaviour (Login , Order , Etc) Describe
Behaviour
2. Tuliskan Step ( Klik Tombol login , etc)
Written step definition ( Click button login ,
etc) Written
Run and
Step
3. Ketika dijalankan pertama kali , hasilnya Pass
Definition
akan gagal
When it run first time , it will fail
4. Tulis kodenya agar stepnya berhasil
Write the code and make it pass
5. Jalankan kembali sehingga hasilnya akan Write Code
Run And
to make
pass step pass
Fail
Re-Run the test , so the result will be pass
Skenario BDD
BDD Scenario
Initial context Event Occurs
1. Keyword Given digunakan untuk
Initial context (Open Seoul Page, dll)
keyword given used for initial context
(Open Seoul page etc)
Given When
2. Keyword When digunakan untuk
eventnya ( Click btn a , dll)
Keyword When , Used For Event (Click
btn A , etc)
3. Keyword Then digunakan untuk
Then
assertion
Keyword Then , used for Assertion
Expected Outcome
Contoh Penulisan Skenario
Example for Writing scenario
Initial context on
• i’m on meat ball Restaurant Meat ball Restaurant
Given
Automation script
Dimapping keJava Code /
( Selenium , Appium ,
Mapped to Java code
Restassured )
Dalam Mendefinisikan Method , definisikan nama method / fungsi dengan jelas , sehingga orang lain
dapat mengerti apa maksud dari method tersebut.
When You define a method , please define clearly name for that method , so the other people will understand what the
method do.
DO DON’T
Clearly method Did’t know which Button
name to click btnLogin that want to be clicked
https://www.oracle.com/technetwork/java/codeconventions-135099.html
PERSIAPAN
Preparing your Environtment
Hal hal yang dibutuhkan / things to do
Install Java Install maven Install Intellij Install Intellij plugin Install Chrome
Lombok , Json2Pojo
, Cucumber
INSTALLING JAVA
Preparation – 1 of 5
Checking Java Instalation
• To check your java Instalation , In terminal or Command Line , please type
Java -version
• Make sure You have Java 1.8.xxxx inside that , if it’s not using Java 1.8 , please uninstall it
first , because our automation supported in Java 1.8 ( Java 1.9 is not supported Yet )
• If you have java installed , you can skip java installation and continue to setup JAVA
_HOME environtment
Installing Java
• Our Automation is Supported From Java 8 ( Please not using Java 9 or newest )
• To install java , please go to and select JDK 8
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-
2133151.html
• And download based on your operating system (Mac OS or Windows )
• And then install the Java
• After installing Java , please check again in the command line in the previous slide
, and make sure the version is same with mentioned previously
SETTING JAVA_HOME
For Windows
Add environment
Variable ( Windows)
• Right click on MyComputer / This PC in
explorer and Click on Advanced System
Settings ,
• It will Open new Window System
Properties
• Press on Environment Variables
Add environment
Variable ( Windows)
• Press New if there are no JAVA_HOME
defined in the System Variables
• Put the variable name JAVA_HOME
• And press Browse Directory
Add environment Variable (
Windows)
• In the windows select folder , choose java Instalation until
jdk.1.8.0_xxx
• And press OK
• Make sure , variable Value is correct for path
• And press Ok again
• And Done
2
1
3
SETTING JAVA_HOME
For MacOs
Setting JAVA_HOME
• But if your command is not recognized you can continue in this installation process, if you already
installed maven correctly in your workstation , you can skip this process
Downloading Maven
• Please go to this page
https://maven.apache.org/download.cgi to
download maven and extract in your folder
library
• For windows , create one folder called
appserver in C:/ and extract the
downloaded maven into that folder
rename folder to maven
Additional setting for
Windows
• Make sure in
C:\appserver\maven
The folder structure is same with this picture
Instalation Windows
• After put the installation maven folder ,
please go to environment variable and add
2 variable , M2_HOME and MAVEN_HOME
in there with the same way
• Make Sure the variable value is
“C:\appserver\maven”
Instalation maven on
windows
• Still same in Environment Variable , Find path
in that dialog and press edit
• Press new in that dialog , and type
“%MAVEN_HOME%\bin”
• Press ok until all dialog is closed
Verify installation maven on windows
• To verify your maven installation , log off or open new command prompt and
type mvn –v
• If your terminal appear like that picture , congratulation , your maven is installed
correctly
Instalation maven on Mac OS
• To install maven , the easiest way is using homebrew , what is homebrew ?
• Homebrew is a package management for Mac os
• To install maven just type “brew install maven” in your terminal and wait until
installation is finish , then verify your installation using mvn -v
Add Setting.xml into
your maven project
• Because we are using internal Repository
, we should setting maven artifactory to
pointed to our repository ,
• If you are using windows , go to explorer
and go to “C:\Users\{{your
username}}\.m2” or mac ~/.m2
• If the folder .m2 is not exist you can
create that folder from your gitbash
• Type “mkdir .m2” and make sure your
folder .m2 is exist
Add setting.xml into your folder
• Please download your setting.xml in this link
https://confluence.gdn-
app.com/display/QKBS/How+To+Run+Automation+Testing+in+Windows
• and put it on your .m2 folder
INSTALLING INTELLIJ
Preparation – 3 of 5
Installing Intellij
{
"name":"argo",
"address":"mojokerto",
"phone":"+628111111111"
}
Installing JSON2Pojo
Xpath Helper
Firefox
• If you prefer using firefox instead of Chrome , we recommend to use firefox for
developer instead of default firefox , because that version of firefox is design for
development
OR
2. Make sure
it’s Checked
Creating project
<dependency>
<groupId>com.gdn.qa.module.archetypes</groupId>
<artifactId>badak-cucumber-spring-archetype</artifactId>
<version>1.4.0</version>
</dependency>
• Back to your intellij Idea and click on Add Archetype
<dependency>
<groupId>com.gdn.qa.module.archetypes</groupId>
<artifactId>badak-cucumber-spring-archetype</artifactId>
<version>1.4.0</version>
</dependency>
2
Fill your Group id with com.gdn.qa.module.api / ui depen on
your automation and followed by your system name , in this
case we will use training as system name
Fill your artifactID with your detailed System name ( for
example if your system is payment api so you can put
payment-api-automation in there) in this case we will use
training-new-hire , after done click next
This is groupID
https://artifactory.gdn-app.com/artifactory/webapp/#/artifacts/browse/tree/General/libs-releases-
local/com/gdn/qa/module/api/hotel/content/cucumber-api-hotel-content/1.1.0-26/cucumber-api-
hotel-content-1.1.0-26.jar
• Make sure , you have correctly input your
data ,
• Please recheck again it’s correct or not.
• If you are wrong when inpputing your
data you should start to beginning from
creating project
• And if it’s already correct , you can go to
Next
Last steps
• If all already correct , you can put your
project location and proect name , please
remember it ☺ , because some of QA is
often forget about their project location
• And after that , you can click on finish
Waiting for project creation
• Click 2x on clean
under lifecycle
• And then after it’s
finished , click 2x
on Verify , it will run
your automation
Congratulation you have run your 1st Automation test
Checking report
• After you running your
automation , it will creating new
folder called “target” , it’s located
with Red / Orange folder , go to
that target->site->serenity-> and
search for index.html , it will give
you the report
• Right click on that , and select
Open with browser -> Chrome or
Your favourite browser
Reporting Result
Please remember ,
prefix is .feature ,
otherwise it will
not detected as
cucumber feature
Cut to here
XcartSteps.java SeleniumEasySteps.java
Explanation Steps Class SeleniumEasy.feature
Tag Feature
Feature Title
Tag Scenario
Scenario Title , Will became Title in
testlink
Scenario Steps ,
inside double quote
usually will be
converted
automatically as a
parameter
Code On Page Object
• Alright now you have create your mapping between your feature files and your
java code , but it will not do nothing until you add some logic in there.
• In this UI we will using Page Object Design Pattern ( One Class Page represents
One UI Page ) for example , we have blibli home page , so that page should be
mapped into one class ( for example blibliHomePage.java)
BlibliHomePage.java
Tips Creating Page Object
• You can create some Generic PageObject if that element is appear in the most of
page , some example , Search bar in header blibli page will appear in most of page
, so you can create some java class page that represent that element .
Header.java
Footer.java
HomePage.java FormPage.java
Creating HomePage.java
• Because it’s Ui so we put PageObject under class src/main/pages
• Create new class in there with name HomePage.java and extend with PageObject
from serenity
• But we usually use id or class name , or css if it’s possible if there are none of them appear ,
you can use xpath as well
ID Class name
• You can request class name by following this confluence page https://confluence.gdn-
app.com/display/GDNIT/QA+UI+Component+ID+Naming+Convention
• And also you can learn about Xpath in this page
https://www.w3schools.com/xml/xpath_intro.asp
Add element into page
• Because we have found ID in that element , we can use that as a identifier
Explanation about how to finding element
• For finding element we can use 2 kind of finding elemen t, 1st is using annotation
@FindBy(Id , xpath , somehing)
• Both of them have same functionality but have different usage. For @FindBy usually we use
it on non SPA ( single page application ) because it will scanned in the beginning
• For find(By.xxxx)) will scan element when that function is being called. Usually we use it for
dynamic DOM or SPA
Do Some Action with element
• In general , for doing some action , you just call the element and do some action
Your Browser
Waiting Until element Appear
• After you click on button Start practicing , there are some delay that make the next button
is not available for some time , like this video , so we need to wait until element is avaiable
Play Video
If you want to see Demo
Waiting Until element appear
• To wait for button we use this function
yourWebElement.waitUntilVisible();
• Default time out for waiting is 2 seconds but you can set the timeout using this
function
• There are some other ways to wait some element , you can learn in this Page (
Section 8.5 Working with timeout)
http://thucydides.info/docs/serenity-staging/#_working_with_timeouts
Searching List Element
• After clicking Start Practicing , it will show list of menu ,
Inside container
has different
Main Container menu it’s mean
has different
xpath
We want to make menu as flexible as we can , so we create one function that can click on the all menu based on parameter
Creating function to click menu
• Before clicking menu we will make sure the menu is already show in the ui
• In the HomePage.java please write this code
Find First if
founded
CHANGING
PAGE
Congratulation , your
automation now entering
new page
Create New Page Class
• Every you find new page on
your automation , you
should create new page
class inside package
“pages”. In package pages
right click on that folder and
click on new -> class . Add
name FormPage and don’t
forget to extend
pageObject and add
annotation @Component
Registering element into page object
class
• Same with previous , let’s register the component that needed in this automation
project.
https://www.seleniumeasy.com/test/basic-first-form-demo.html FormPage.java
Add function to type Input text
• For typing Object , you can use this function youBeautifulElement.type(“Your Type”)
The result for that function if it’s called from steps will be similar with Video
Add function to click Show Message and
get Text
• After typing Message , next scenario is click on buton “Show Message” and we
need to get the Text that appear in “Your Message” after it’s clicked
We need This
• Try to test it manually until message hello world is appear ( play video for detail)
because we need to get message after click btn “Show Message”
Register button and text
• Add function to click Button and get Text into FormPage.java
FormPage.java
Getting text
• As our standard , All selenium Code ( click , getText , Action dll) should placed in
the Page class , it’s not allowed to access that kind of method outside class page ,
because we want to isolate it if there are changes in selenium , so it will not
impacted to other package and the changes can be minimized.
• For getting text , we use YourElement.getText() , it will get the text from element
that you have registered.
FormPage.java
Getting text from Title “Simple Form
Demo”
• In order to wait form loaded , we need to wait a element and make sure the page
that loaded is the form that we need , in this scenario ,we are using title “Single
Input Field”
Same with previously , we will using method
.getText() for getting the title and do some
assertions in the steps
Registering Form Title
• We are using this xpath for getting the form title
(//div[@class="panel-heading"])[2]
FormPage.java
Preparing API
• There are steps to writing Api testing ,
1. Define default endpoint data for the API using properties file.
2. Define default header and parameters using properties file.
3. Define default header and parameters using interceptors.
4. Convert the response data into object using rest-web model that developer already
created.
5. Save the data using model classes for future use during runtime.
6. Preparing the request body using Java Object Model or using Template.
Getting title text
• And then we add function to getting the text
It Will return
FormPage.java
Wait until Visible
Getting Text
• Time out for waiting until visible is 2 seconds , and it can be configurable. After 2 seconds
if it’s not visible will be throw error
CODE FOR
FORMPAGE.JAVA
Assertions
In our framework we use Hamcrest as our standard assertions in order to make
sure the expected condition is same , for example in the steps {Then user should
able to see “……….”}
SeleniumEasySteps.java
Why Assertions
• Assertions is used for make sure the data or the value that get from API / UI is
expected as we want , for example
https://www.seleniumeasy.com/test/basic-first-form-demo.html
Hamcrest
• Hamcrest is an alternative assertions library that make us to make sure the data is
expected as we want ,
• Hamcrest has so many function, and we use Hamcrest as our standard assertions
tools.
• To learn more about hamcrest , you can visit http://hamcrest.org/JavaHamcrest/
• In this tutorial we will use basic function from hamcrest.
Put FormPage.Java into
SeleniumEasySteps.java
• In order to changing page , you should put the FormPage.java class into
SelenumEasySteps.java so the function from page can be called in there and can
be mapped. Play video for more detail
Do Assertions
• Back to your project and open your SeleniumEasySteps.java
Has Result
Single Input
Field
FormPage.java
https://www.seleniumeasy.com/test/basic-first-form-demo.html
CODE FOR
SELENIUMSTEPS.JAVA
RUN THE AUTOMATION TEST
Mapping the other steps
• Please continue the mapping for other steps on file SeleniumEasySteps.java
Check the automation
After you complete your code , all automation steps should be green ( all is passed )
, please play video if you want to view demonstration
Run with Maven
Parameters
You can use that response for assertions , and make sure the API is getting right.
We will make sure the data is same with the data that we post for controller add.
Demo API
Because All end point have same prefix ( /api/mahasiswa) sowe put this
in the basePath
MAHASISWA
PROPERTIES
This is full file of
application.properties
Writing interceptors
• Interceptors is a helper that help qa to
write code faster and reduce more
redundancy on API testing
• For example , some of our endpoint have
query param 1001 and it should be
available in all request , so instead of
writing 1001 in all controller , you just write
once in interceptors.
Writing interceptors
• Create new class under api/interceptor’s package , and add implementation
ServiceInterceptor
Implement interceptors method
There are 2 Method that sould be implemented during creation , you can implement it by pressing alt enter or
right click and click on show context action and click implement method ( please play video for detail)
Writing interceptors
When you implement Service interceptor’s method , there will be 2 method that created. One is isSupport , and the
other is prepare.
MahasiswaInterceptor.java application-UATA.properties
Writing interceptors Because in our API controller swagger there are
no base query param ( 1001 , web etc) so we just
define response content type same as swagger
MahasiswaInterceptor.java
http://172.18.69.207:8083/swagger-ui.html#/mahasiswa-
controller/getMahasiswaUsingGET
Complete code for interceptors
package com.gdn.qa.module.ui.training.api.interceptors;
import com.gdn.qa.automation.core.restassured.ServiceInterceptor;
import io.restassured.specification.RequestSpecification;
/**
* User: argo.triwidodo
* Date: 05-Dec-19
* Time: 17:18
*/
public class MahasiswaInterceptor
implements ServiceInterceptor {
@Override
public boolean isSupport(String serviceName) {
return serviceName.equalsIgnoreCase("mahasiswa");
}
@Override
public void prepare(RequestSpecification requestSpecification) {
requestSpecification.accept("*/*");
}
}
Implementation
for API
Tips :
Usually QA writes one
controller in one Java Class,
Writting Scenario
Preparing Data
• In our Scenario there are 2
API call activity ,
Both of this steps is • First is creating mahasiswa
using API testing data
• And second is getting
mahasiswa By ID
• Before we hit Api for add ,
we will set the data using
“Given” Keyword
• The data is including Name ,
Majors , and NIM same with
Request body that we got
from controller swagger
Writting Controller
• Create new class in controller package with name MahasiswaController , Extend it
with ServiceAPI , and add one Method For add mahasiswa
{ {
"id": 0, "id": 0,
"mahasiswaName": "string", "mahasiswaName": “Argo",
"majors": "string", "majors": “Informatika",
"nim": "string" "nim": “123456"
} }
Writing Controller
Intellij has capability to automatically reformat string that you have copied , please play video for more details
Calling Service
• For calling Service , you just need to call service(String serviceName) from
ServiceApi that has been extended previously.
• It’s indicated that your steps is not finished yet , and need to be coded later , in this tutorial
we will remove all throw new PendingExceptions() , so when we run our test , it will not
marked as pending
Please do it on all method inside MahasiswaSteps Class
Run IT!
MahasiswaController.java
(Optional) Print Body Response
• You can Print your Response Body , so in console you can see response from
Server , but this steps is optional for real condition
Convert JSON Response To Java Model
• Instead of using Json , we will use Java Model . So we will accessing Java model
instead of directly to Json
• Open swagger again and Copy the response from addMahasiswa’s end point.
Converting Response
Using Json to Pojo
• Right Click on package models ->
response -> New -> Generate Pojo’s From
Json
• Click generate and you will get the java
class