Professional Documents
Culture Documents
IPG-MTech
by
Abhishek Garain(2017IMT-002)
2021
1
CANDIDATES DECLARATION
I hereby certify that the work, which is being presented in the report, entitled Develop-
ment of a cross-platform Code Coverage calculation tool for automated and inter-
action based testing using Playwright, Cypress and Electron, submitted to the insti-
tution is an authentic record of my own work carried out during the period 22 February
2021 to 30 June 2021. I have also cited the reference about the text(s)/figure(s)/table(s)
from where they have been taken.
This is in furtherance to your resignation dated June 30 , 2021, wherein you had requested to be relieved from the services.
Kindly note we have completed all your Full & Final Settlement formalities and you are relieved from the services of “Rakuten India Enterprise Private
Limited” with effect from June 30 , 2021.
We thank you for your association with Rakuten India. We wish you great success in your future endeavours.
*Nisha Verma
nisha.verma@rakuten.com
*This is a system generated letter and does not require any signature
3
ABSTRACT
ACKNOWLEDGEMENTS
I take this opportunity to express my profound gratitude and deep regards to all my men-
tors for their exemplary guidance, monitoring and constant encouragement throughout
the course of this internship. The blessing, help and guidance given by them time to
time shall carry me a long way in the journey of life on which I am about to embark. I
also take this opportunity to express a deep sense of gratitude to my internship mentors
Mr. Madhusudan Ganda(Senior Engineering Manager, GATD Team, Rakuten India),
Mr. Rakhsit Arora(QA Lead, GATD Team, Rakuten India), Mrs. Sona Ojus(Software
Engineer, GATD Team, Rakuten India) for their cordial support, valuable information
and guidance, which helped me in completing the tasks through various stages.
(Abhishek Garain)
TABLE OF CONTENTS
ABSTRACT 3
LIST OF TABLES 6
LIST OF FIGURES 7
1 Company Profile 10
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2 About the GATD team . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.1 About Atssa2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3 Mission and Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3.1 Always Improve, Always Advance . . . . . . . . . . . . . . . . 12
1.3.2 Passionately Professional . . . . . . . . . . . . . . . . . . . . . 12
1.3.3 Hypothesize → Practice → Validate → Shikumika . . . . . . . 12
1.3.4 Maximize Customer Satisfaction . . . . . . . . . . . . . . . . . 13
1.3.5 Speed!! Speed!! Speed!! . . . . . . . . . . . . . . . . . . . . . 13
1.4 How Rakuten is transforming India . . . . . . . . . . . . . . . . . . . . 13
3 Literature Review 16
3.1 Code Coverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Importance of Code Coverage for a project . . . . . . . . . . . . . . . . 16
3.2.1 Examples of why code coverage is important . . . . . . . . . . 17
3.3 Types of Code Coverage metrics used in a project . . . . . . . . . . . . 17
3.4 Existing tools and platforms . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.1 BrowserStack: . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.2 Cypress: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.3 Zalenium: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.4 Disadvantages of existing platforms: . . . . . . . . . . . . . . . 19
5
TABLE OF CONTENTS 6
4 Methodology 23
4.1 Tools and Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1.1 Cypress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1.2 Instrumentation of code . . . . . . . . . . . . . . . . . . . . . 24
4.1.3 IstanbulJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.1.4 nyc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.1.5 Playwright . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.1.6 XtermJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.1.7 Jenkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.1.8 ElectronJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.1.9 ReactJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.1.10 NodeJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.1.11 ngrok . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.1.12 Docker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2 System Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.2.1 Steps to achieve the final code coverage reports . . . . . . . . . 28
4.2.1.1 Instrumenting customer’s code . . . . . . . . . . . . 28
4.2.1.2 Choice of testsuite: Manual testcase execution . . . . 28
4.2.1.3 Choice of testsuite: Automated testcase execution . . 30
4.2.1.4 Generation of code coverage reports . . . . . . . . . 30
4.2.2 Sending the reports back to the cloud platform . . . . . . . . . 33
REFERENCES 35
LIST OF TABLES
7
LIST OF FIGURES
8
LIST OF FIGURES 9
ABBREVIATIONS
Company Profile
This chapter includes the profile of Rakuten, Rakuten India and the Global AdTech
Team at Rakuten India of which I was a part of, during my four months internship.
1.1 Introduction
Rakuten Group, Inc. is a Japanese electronic commerce and online retailing company
based in Tokyo, founded by Hiroshi Mikitani in 1997. Centered around Rakuten Ichiba,
its a business-to-many E-Commerce platform and one of the largest e-commerce sites
in Japan, its businesses include financial services utilizing fintech, as well as digital
content and communication services such as messaging app Viber, e-book distribu-
tor Kobo, and Japan’s fourth mobile carrier Rakuten Mobile. Rakuten has 18,000+
employees worldwide, operating in 29 countries and regions, and its revenues totaled
US$7.2 billion with operating profits of about US$347.9 million as of 2016. It is often
referred to as "the Amazon of Japan".
Its major investments include Buy.com (now Rakuten.com in the US), Priceminister,
Ikeda, Tradoria, Play.com, Wuaki.tv, Ebates, Viki, The Grommet. The company also
has stakes in Ozon.ru, AHA Life, Lyft, Cabify, Careem, Carousell and Acorns. [1]
10
CHAPTER 1. COMPANY PROFILE 11
This chapter deals with the problem statement that acted pivotal for the internship
project and the objectives set forth and accomplished during the internship period. The
internship mainly focused on one problem to solve: There are no available platforms
that can find code coverage based on real-time software testing.
• To create a codeless automated code coverage calculation tool that can measure
code coverage for any particular project based on manual testing or automation
testing.
• To integrate the code coverage tool with the existing Atssa2.0 platform for pre-
serving the code coverage reports for all the testcases present in the portal.
14
CHAPTER 2. PROBLEM STATEMENT AND OBJECTIVES 15
2.2 Objectives
• To develop a method to fulfill the requirements.
• To choose the tech stack to develop the project based on high level research and
PoC.
• To choose the platform on which the tool needs to be developed based on discus-
sion with PMs and stakeholders.
• To design the high level system architecture of the whole project and get it ap-
proved from senior EMs and leads.
Literature Review
The sole purpose of doing an extemsive literature review of all the available technolo-
gies was needed to create a market viable product that can be shipped easily to the
customers without any hassle. Following are the topics that were explored in-depth
during the course of the internship.
• This will also enforce a culture of writing unit tests using code coverage rules.
• A high code coverage is crucial to investors to pitch them that we are not wasting
lot of capital in maintaining big piece of code.
16
CHAPTER 3. LITERATURE REVIEW 17
• A high code coverage matters to some potential customers and brings confidence
in them.
• A low code coverage could lead to code refactoring making it more optimal.
• Code coverage reports also signifies whether tests are executed or not.
• Knight Capital Group, a HFT firm lost $460m in 45 minutes on 01 August, 2012
due to deployment of a new algorithm. While the algorithm was perfectly tested
to check for the presence of bugs, what they forgot was, removing old pieces
of code, and that interfered with the newly added algorithm and that brought
down the servers during the peak business hours. The RCA report stated that
their mistake was to not have any code coverage calculation tool that could have
reported them the correct usage of the code before deployment of the algorithm.
[6]
Figure 3.1: Knight Capital Group’s stocks went down within minutes
4. Line Coverage: Line Coverage refers to the number of lines of code evaluated
by the tests. [7]
3.4.1 BrowserStack:
BrowserStack is an Indian cloud web and mobile testing platform providing develop-
ers the power to test their websites and mobile applications across different types of
browsers in different platform in real-time. BrowserStack is a leading platform for
testcase execution but it doesn’t provide any feature to calculate code coverage for the
testcases. [8]
3.4.2 Cypress:
Cypress is a newly launched front-end testing tool built for the modern web. They
address the key difficulties developers and QA engineers face when testing modern web
applications. They make it possible to set up tests, write tests, run tests, debug tests.
It is often compared to Selenium and other browser automation framework, however
Cypress is both fundamentally and architecturally different. [9]
Cypress provides this library called @cypress/instrument-cra that helps to instrument
code written in ReactJS.
3.4.3 Zalenium:
Zalenium is a flexible and scalable container based Selenium Grid with video recording,
live preview, basic auth & dashboard. Zalenium is a very powerful platform to execute
testcases but at the same time, to generate code coverage reports, we need to write
scripts manually. [10]
CHAPTER 3. LITERATURE REVIEW 19
• The JSON coverage variable resides in the devtools of the browser but normal
browsers can’t provide a programmatic interface to access those variables.
• So, we need a platform to trigger our own browser, and that’s where the desktop
app comes into picture.
• Also, we had to execute some scripts in the user’s syatem, and this couldn’t be
done from a browser as we get access to a virtualized environment in a browser
but we can easily get access to user’s system through a desktop app.
3.6 Testcases
A test case is a set of steps that are performed on a project to determine if it satisfies
software requirements and functions correctly. The purpose of a test case is to deter-
mine if various features within a system are performing as desired and to confirm that
the system satisfies all related standards, guidelines and stakeholder requirements. The
process of writing a test case can also help reveal errors or defects within the system.
3.7 Testsuites
Testsuites are softwares that are used to run automated testcases, it helps to track which
particular testcases are currently running, the testcases that have already completed
execution and the testcases that are yet to be executed.
tester according to the end user’s perspective. It ensures whether the application is
working as mentioned in the requirements document or Jira tickets.
So, the tests will be written by developers or the QA engineers and it will be the re-
sponsibility of the QA engineers or the developers to execute the testcases manually to
check for performance degradation or presence/absence of bugs in the project.
Methodology
4.1.1 Cypress
Cypress is a newly launched front-end testing tool built for the modern web. They
address the key difficulties developers and QA engineers face when testing modern web
applications. They make it possible to set up tests, write tests, run tests, debug tests.
It is often compared to Selenium and other browser automation framework, however
Cypress is both fundamentally and architecturally different. [9]
Cypress provides this library called @cypress/instrument-cra that helps to instrument
code written in ReactJS.
23
CHAPTER 4. METHODOLOGY 24
4.1.3 IstanbulJS
IstanbulJS helps to instrument ES5 and ES2015+ JavaScript code with line counters,
so that we can track the quality of our unit-tests exercise the given codebase. IstanbulJS
comes as a NPM package that needs to be installed in any ES5+ projects and it needs
to be run with react-scripts to instrument the codebase.
4.1.4 nyc
nyc is a command-line-client for Istanbul that works well with most JavaScript testing
frameworks: tap, mocha, AVA, etc. In my project, nyc was used to generate code
coverage reports from binary data containing counters of each line of code.
4.1.5 Playwright
Playwright is a NodeJS library to automate Chromium, Firefox and WebKit with a
single API. Playwright is built to enable cross-browser web automation that is ever-
green, capable, reliable and fast. Headless execution is supported for all the browsers
on all platforms.
4.1.6 XtermJS
XtermJS is a front-end component written in TypeScript that lets applications bring
fully-featured terminals to their users in the browser. XtermJS was used to integrate
a terminal inside the desktop app such that users can execute any command inside the
desktop app that will help to ease the lives of users. Also, all the commands that are
run by the desktop app will be executed in these terminals directly and not behind the
scenes such that user has clarity that what all commands are executed in their system.
4.1.7 Jenkins
Jenkins is the leading open-source automation server, it provides hundreds of plugins
to support building, deploying and automating any project. Jenkins is a self-contained,
open source automation server which can be used to automate all sorts of tasks related
to building, testing, and delivering or deploying software.
4.1.8 ElectronJS
Electron is a free and open-source software framework developed and maintained by
GitHub. It helps to develop desktop GUI applications using web technologies: it com-
bines the Chromium rendering engine and the NodeJS runtime.
The code coverage desktop app was built on top of ElectronJS, it was chosen on the
basis of the literature review and PoC that our team did in the initial sprint.
CHAPTER 4. METHODOLOGY 26
4.1.9 ReactJS
React is a free and open-source front-end JavaScript library for building user interfaces
or UI components. It is maintained by Facebook and a community of individual devel-
opers and companies. React can be used as a base in the development of single-page or
mobile applications
ReactJS was used to create the UI for the code coverage desktop app. MaterialUI
was the UI library used to design the components.
4.1.10 NodeJS
NodeJS is an open-source, cross-platform, back-end JavaScript runtime environment
that runs on the V8 engine and executes JavaScript code outside a web browser.
NodeJS was used as the runtime to power the desktop app and connect it with the
frontend packages and to render the UI.
4.1.11 ngrok
ngrok provides a real-time web UI that can introspect all HTTP traffic running over
tunnels. It is a cross-platform application that enables developers to expose a local
development server to the internet with minimal effort.
ngrok was used in the project to tunnel the user traffic to execute testcases on a local
version of the project in our cloud based testcase execution tool i.e. Atssa2.0.
4.1.12 Docker
Docker is a set of platform as a service products that use OS-level virtualization to
deliver software in packages called containers. Containers are isolated from one another
CHAPTER 4. METHODOLOGY 27
and bundle their own software, libraries and configuration files; they can communicate
with each other through well-defined channels.
Docker images of Windows and Ubuntu were used to generate an executable file
for the ElectronJS project as I only had access to a MacOS system. Docker was also
used to dockerize the React project into a docker image such that it can run anyone’s
system without much hassle.
The first step before choosing any testsuite is to instrument the user’s code such that,
once the code is hosted and the project is used, JSON coverage variable can be tracked
and the reports can be generated. To instrument the code, we are using cypress/instrument-
cra library that is used to spawn the react-scripts process to instrument the code and host
the code at the same time.
In manual testcase execution, the users can easily test a particular scenario by manually
testing the project and finding the code coverage simultaneously.
CHAPTER 4. METHODOLOGY 29
1. To facilitate this task, we will need to record all the movements of the user in the
browser to find which features are used, and similarly, we can generate the JSON
object for the coverage data.
3. Once the choice of browser automation framework had been chosen, we inte-
grated it with the desktop app.
4. The user needs to enter two things to find the code coverage:
5. Once the user fills in all the details and starts the process, the instrumentation of
the code begins.
6. Once the instrumentation process ends, user will be provided with a choice of
browser where they want to test the scenario. They are:
All of these browsers serves as an engine that powers Google Chrome, Mozilla
Firefox and Safari browser respectively and is mostly used to develop softwares
that needs programmatic access to the browser internals.
7. The users can perform manual testing in these newly opened browsers and can
manually test their project and automatically the code coverage reports will be
updated.
CHAPTER 4. METHODOLOGY 30
In automated testcase execution, the users can use a testsuite like Atssa2.0 to execute a
testcase in the cloud and after the testcase is executed, the JSON object can be extracted
from the browser and that can be used to calculate the code coverage reports.
2. To execute the testcases and find the coverage variable, we need a tunneled URL
of user’s localhost URL. To achieve this, we are using ngrok to tunnel the local-
host URL and Atssa2.0 will use this URL to run the testcases.
3. Once the testcases are executed, the browser automation library i.e. Selenium
will extract the coverage object and it will save the response in the MongoDB
database.
4. Once the user wants to explore the results of the executed testcases in Atssa2.0
dashboard, the code coverage variable will be sent as an API response to the
dashboard.
5. The user needs to enter two things to find the code coverage:
(a) The user needs to copy the coverage object from the dashboard and paste it
in the desktop app.
(b) The folder that contains the project.
6. Once the user fill in all the details and starts the process, the code coverage reports
are generated.
Once the JSON coverage data has been extracted from the browser automation frame-
work and accessible to the desktop app, the data will be written in the file ‘./.nyc_output/out.json‘,
after that, the nyc tool will be used to use the ‘out.json‘ file to generate code coverage
reports in HTML form.
CHAPTER 4. METHODOLOGY 31
Figure 4.10: Code coverage report in HTML format having 50% code coverage
Figure 4.11: Code coverage report in HTML format having 100% code coverage
CHAPTER 4. METHODOLOGY 33
5.1 Results
• All the proposed objectives were successfully implemented.
• The code coverage desktop app was packaged and shipped to the customers in
the form of executable files for Windows, Linux and MacOS platforms.
• The reports storage mechanism was successfully integrated with the cloud infras-
tructure.
• Enterprise users can download the desktop app to manually calculate the code
coverage, else normal users can track the JSON code coverage variable through
the dashboard of Atssa2.0.
5.2 Conclusion
The four months internship at Rakuten was a complete success in terms of understand-
ing a multi national corporation from a close point of view and in terms of learning
new technologies and experimenting new approaches to build new stuffs with a tinge
of business logic to make a product successful. One of the biggest takeaway was how
big teams manage their work and get work done with regular meetings, weekly sprints
and how agile methodology of making a software works. Several concepts which were
learned theoretically like agile methodology was used practically during the internship.
Several non-technical concepts like growth mindset, importance of diversity and inclu-
sion, necessity to pursue other passions etc. were also emphasised by the organization,
especially the senior management. This gave valuable life lessons. I also got the op-
portunity to learn several new technologies like ElectronJS, Code Coverage, System
Design etc. My manager was extremely happy with my progress right from the first
week and was impressed by the ramp-up speed and this motivated me further. My
34
CHAPTER 5. RESULTS AND CONCLUSION 35
internship was a great learning experience which was both productive and enjoyable.
REFERENCES
[5] Rafiullah Hamedy. 10 reasons why code coverage matters, 2020 (accessed
Sept 11, 2021). https://codeburst.io/10-reasons-why-code-coverage-matters-
9a6272f224ae.
[6] Bishr Tabbaa. The rise and fall of knight capital — buy high, sell low. rinse and
repeat., 2018 (accessed Sept 11, 2021). https://medium.com/dataseries/the-rise-
and-fall-of-knight-capital-buy-high-sell-low-rinse-and-repeat-ae17fae780f6.
[7] Thomas Hamilton. Code coverage tutorial: Branch, statement, decision, fsm,
2021 (accessed Sept 11, 2021). https://www.guru99.com/code-coverage.html.
36