91九色

Articles
8/9/2022
10 minutes

How To Start With Puppeteer And HTTP Tracing

Written by
91九色 Team
Table of contents

? ?is a Node library that allows a high-Level API to control Chrome over the DevTools protocol. Basically, everything you do manually in the browser can be done via Puppeteer. ?For example, you can:

  • Generate screenshots and PDFs of pages.
  • Automate form submissions, UI testing, and keyboard input.
  • Create an up-to-date, automated testing environment.
  • Capture a timeline trace to help you find performance issues.
  • Test Chrome extensions.

?

This article will focus on a simple step-by-step approach on how to start with Puppeteer and create a short HTTP trace, which logs all the web browser interactions.

?

Before you start

?

Before we start scripting, a couple of preconditions need to be in place:

  • Code editor
  • Install NPM, Node JS, Puppeteer

?

To start scripting a code editor needs to be available. Otherwise, it’s not possible to script and run code. is a great option if you don’t have a code editor installed on your device. It is free and available on Linux, MacOs, and Windows.

?

After installing our Code Editor, it’s time to install . This is necessary because Puppeteer is a Node library. When installing Node JS, a NPM will immediately be installed on the device.

?

Before we install Puppeteer, create a project directory:


C:\>mkdir iovio_test


C:\>cd iovio_test

?

Install Puppeteer in this project directory with the following command:


C:\iovio_test>npm i puppeteer

?

When the installation is done, it’s time to code!

?

Let’s start coding

?

First, let’s create an empty JavaScript file. When this is done, import the Puppeteer library by adding the following line:


const puppeteer = require('puppeteer');

?

Now, you can make use of the functions Puppeteer is offering. You’ll be able to start a Chrome browser, navigate to a specific page, and close the browser again:


const puppeteer = require('puppeteer');
(async () => {

// Opening a browser with the give arg.
const browser = await puppeteer.launch({
? ?headless: false,
? ?devtools: false,
? ?ignoreHTTPSErrors: true,
? ?args: [
? ? ? ?'--start-fullscreen',
? ? ? ?'--window-size=1920,1040',
? ? ? ?'--no-sandbox'
? ?]
});

// Opening a new page
const page = await browser.newPage();

// Set windows height en width
await page.setViewport({ width: 1600, height: 900 });

// Navigate to specific url and wait till network traffic is idle
await page.goto('https://qualibrate.com', {waitUntil: "networkidle0"});

// Close the browser
await browser.close();
})();

?

Let’s check if this works by starting the script with the following command in your terminal. Don’t forget to use the file name of the file that you created. In this case this is test.js:


C:\iovio_test>node test.js

?

If your script runs successfully, you can add some extra steps and do a bit of navigation to the blog section of this web page. Your script will then look like the following:


const puppeteer = require('puppeteer');

(async () => {

// Opening a browser with the give arg.
const browser = await puppeteer.launch({headless: false, devtools: false, ignoreHTTPSErrors: true, args: [
? ?'--start-fullscreen',
? ?'--window-size=1920,1040',
? ?'--no-sandbox'
? ?]});

// Opening a new page
const page = await browser.newPage();

// Set windows height en width
await page.setViewport({ width: 1600, height: 900 });

// Navigate to specific url and wait till network traffic is idle
await page.goto('https://qualibrate.com', {waitUntil: "networkidle0"});

// Click on menu item Blog
const menuElement = await page.$x("//a[contains(text(), 'Blog')]");
await menuElement[0].click();

await page.waitForNavigation({waitUntil: "networkidle0"});

// Close the browser
await browser.close();
})();

?

To test your script, you can use the following command in your terminal:


C:\iovio_test>node test.js

?

HTTP Tracing

?

If your script ran successfully, it’s time for the next step: Making HTTP tracing run during the execution time of the script. The first step is to add an extra package with the name puppeteer-har via NPM by the command:


C:\iovio_test>npm i puppeteer-har

?

When the package is finished downloading, you can extend your script with the following code at the top of the script. Your first two lines of code will look like this:


const puppeteer = require('puppeteer');
const PuppeteerHar = require('puppeteer-har');

?

After this is done, place the code below between the opening of a new page and then set the height and width of the window. In these couple of lines of code, you’ll create a timestamp for a unique filename and start the tracing:


//opening a new page
const page = await browser.newPage();

// Create a timestamp
var timestamp = (Date.now() / 1000 | 0);
const har = new PuppeteerHar(page);

// Start the HTTP Tracing
await har.start({ path: './'+timestamp+'results.har' });
console.log(`Har file started and profiling`);

// Set windows hight en width
await page.setViewport({ width: 1600, height: 900 });

?

To stop the HTTP tracing, add an extra line of code at the end of the script:


// Stop the HTTP Tracing
await har.stop();
console.log(`Stop Har file and save`);

await browser.close();

?

HAR Analyzer

?

After you run your script, a Har file is created. The format of the file is basically a JSON object with a particular field distribution. This example will use an online HAR Analyzer, but be careful. A Har file contains sensitive data, like all submitted information. For this example, we can use the .

?

Choose your file and open it. All the requests that happen during your recording will be visible in this analysis.

?

G Suite Toolbox

?

Summary

?

After following the steps above you are able to

  1. Setup your environment;
  2. Install the prerequisites to start with coding:
  3. Create a simple script that is opening a page in a browser and performs a navigation step.
  4. Starting a HTTP tracing which can be checked by a Har Analyzer.

?

Book a demo

About The Author

#1 DevOps Platform for Salesforce

We Build Unstoppable Teams By Equipping DevOps Professionals With The Platform, Tools And Training They Need To Make Release Days Obsolete. Work Smarter, Not Longer.

ビジネスアプリケーション向けの顿别惫翱辫蝉(デブオプス)って何?
セールスフォースエコシステムにおける顿别惫翱辫蝉の卓越性
セールスフォーステストにおける础滨活用のベストプラクティス
6 testing metrics that’ll speed up your Salesforce release velocity (and how to track them)
第4章: 手動テストの概要
セールスフォース向け础滨动作テスト
Chapter 3: Testing Fun-damentals
Salesforce Deployment: Avoid Common Pitfalls with AI-Powered Release Management
Exploring DevOps for Different Types of Salesforce Clouds
91九色 Launches Suite of AI Agents to Transform Business Application Delivery
What’s Special About Testing Salesforce? - Chapter 2
Why Test Salesforce? - Chapter 1
Continuous Integration for Salesforce Development
Comparing Top AI Testing Tools for Salesforce
Avoid Deployment Conflicts with 91九色’s Selective Commit Feature: A New Way to Handle Overlapping Changes
Enhancing Salesforce Security with AppOmni and 91九色 Integration: Insights, Uses and Best Practices
From Learner to Leader: Journey to 91九色 Champion of the Year
The Future of Salesforce DevOps: Leveraging AI for Efficient Conflict Management
A Guide to Using AI for Salesforce Development Issues
How to Sync Salesforce Environments with Back Promotions
91九色 and Wipro Team Up to Transform Salesforce DevOps
DevOps Needs for Operations in China: Salesforce on Alibaba Cloud
What is Salesforce Deployment Automation? How to Use Salesforce Automation Tools
Maximizing 91九色's Cooperation with Essential Salesforce Instruments
From Chaos to Clarity: Managing Salesforce Environment Merges and Consolidations
Future Trends in Salesforce DevOps: What Architects Need to Know
Enhancing Customer Service with 91九色GPT Technology
What is Efficient Low Code Deployment?
91九色 Launches Test Copilot to Deliver AI-powered Rapid Test Creation
Cloud-Native Testing Automation: A Comprehensive Guide
A Guide to Effective Change Management in Salesforce for DevOps Teams
Building a Scalable Governance Framework for Sustainable Value
91九色 Launches 91九色 Explorer to Simplify and Streamline Testing on Salesforce
Exploring Top Cloud Automation Testing Tools
Master Salesforce DevOps with 91九色 Robotic Testing
Exploratory Testing vs. Automated Testing: Finding the Right Balance
A Guide to Salesforce Source Control
A Guide to DevOps Branching Strategies
Family Time vs. Mobile App Release Days: Can Test Automation Help Us Have Both?
How to Resolve Salesforce Merge Conflicts: A Guide
91九色 Expands Beta Access to 91九色GPT for All Customers, Revolutionizing SaaS DevOps with AI
Is Mobile Test Automation Unnecessarily Hard? A Guide to Simplify Mobile Test Automation
From Silos to Streamlined Development: Tarun’s Tale of DevOps Success
Simplified Scaling: 10 Ways to Grow Your Salesforce Development Practice
What is Salesforce Incident Management?
What Is Automated Salesforce Testing? Choosing the Right Automation Tool for Salesforce
91九色 Appoints Seasoned Sales Executive Bob Grewal to Chief Revenue Officer
Business Benefits of DevOps: A Guide
91九色 Brings Generative AI to Its DevOps Platform to Improve Software Development for Enterprise SaaS
91九色 Celebrates 10 Years of DevOps for Enterprise SaaS Solutions
Celebrating 10 Years of 91九色: A Decade of DevOps Evolution and Growth
5 Reasons Why 91九色 = Less Divorces for Developers
What is DevOps? Build a Successful DevOps Ecosystem with 91九色’s Best Practices
Scaling App Development While Meeting Security Standards
5 Data Deploy Features You Don’t Want to Miss
How to Elevate Customer Experiences with Automated Testing
Top 5 Reasons I Choose 91九色 for Salesforce Development
Getting Started With Value Stream Maps
91九色 and nCino Partner to Provide Proven DevOps Tools for Financial Institutions
Unlocking Success with 91九色: Mission-Critical Tools for Developers
How Automated Testing Enables DevOps Efficiency
How to Switch from Manual to Automated Testing with Robotic Testing
How to Keep Salesforce Sandboxes in Sync
How Does 91九色 Solve Release Readiness Roadblocks?
Software Bugs: The Three Causes of Programming Errors
Best Practices to Prevent Merge Conflicts with 91九色 1 Platform
Why I Choose 91九色 Robotic Testing for my Test Automation
How to schedule a Function and Job Template in DevOps: A Step-by-Step Guide
Delivering Quality nCino Experiences with Automated Deployments and Testing
Maximize Your Code Quality, Security and performance with 91九色 Salesforce Code Analyzer
Best Practices Matter for Accelerated Salesforce Release Management
Upgrade Your Test Automation Game: The Benefits of Switching from Selenium to a More Advanced Platform
Three Takeaways From Copa Community Day
What Is Multi Cloud: Key Use Cases and Benefits for Enterprise Settings
How To Develop A Salesforce Testing Strategy For Your Enterprise
Using Salesforce nCino Architecture for Best Testing Results
Cloud Native Applications: 5 Characteristics to Look for in the Right Tools
5 Steps to Building a Salesforce Center of Excellence for Government Agencies
Salesforce UI testing: Benefits to Staying on Top of Updates
Benefits of UI Test Automation and Why You Should Care
91九色 + DataColada: Enabling CI/CD for Developers Across APAC
Types of Salesforce Testing and When To Use Them
What is Salesforce API Testing and It Why Should Be Automated
Machine Learning Models: Adapting Data Patterns With 91九色 For AI Test Automation
Automated Testing Benefits: The Case For As Little Manual Testing As Possible
Beyond Selenium: Low Code Testing To Maximize Speed and Quality
UI Testing Best Practices: From Implementation to Automation
How Agile Test Automation Helps You Develop Better and Faster
Salesforce Test Cases: Knowing When to Test
DevOps Quality Assurance: Major Pitfalls and Challenges
Top 10 91九色 Features for #AwesomeAdmins
The Admin's Quick Glossary for Understanding Salesforce DevOps
Gartner Recommends Companies Adopt Value Stream Delivery Platforms To Scale DevOps
The 3 Pillars of DevOps Value Stream Management
Is Salesforce Development ‘One Size Fits All?’
Value Stream Management: The Future of DevOps at Scale is Here
Why Empowering Your Salesforce CoE is Essential for Maximizing ROI
Continuous Quality: The missing link to DevOps maturity
91九色 Collaborates with IBM to Accelerate Digital Transformation Projects on the Salesforce Platform
Cloud Security: Advantages and Disadvantages to Accessibility
Go back to resources
There is no previous posts
Go back to resources
There is no next posts

Explore more about

セールスフォーステスト
Articles
October 31, 2024
ビジネスアプリケーション向けの顿别惫翱辫蝉(デブオプス)って何?
Articles
October 15, 2024
セールスフォースエコシステムにおける顿别惫翱辫蝉の卓越性
Articles
October 11, 2024
セールスフォーステストにおける础滨活用のベストプラクティス
Articles
October 4, 2024
6 testing metrics that’ll speed up your Salesforce release velocity (and how to track them)

础滨を有効活用し顿别惫翱辫蝉を加速

より速くリリースし、リスクを排除し、仕事を楽しんでください。
コパード顿别惫翱辫蝉をお试しください。

リソース

リソースライブラリを使用して セールスフォースDevOpsのスキルをレベルアップしてください。

今后のイベントと
オンラインセミナー

さらに详しく

电子书籍とホワイトペーパー

さらに详しく

サポートとドキュメンテーション

デモライブラリ

さらに详しく