npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shareflex/puppeteer-engine

v1.1.5

Published

The puppeteer-engine as a node_module

Downloads

394

Readme

Platform Puppeteer PR's Welcome

Introduction

@shareflex/puppeteer-engine is a simple to use TestRunner for End2End-Testing powered by puppeteer.


Table of content

Getting Started

npm install @shareflex/puppeteer-engine --save-dev

How to use:

Find an Example in "YourProjectPath/node_modules/@shareflex/puppeteer-engine/dist/Example".

Example usage:

//Import the Engine
import { Engine } from '@shareflex/puppeteer-engine';

//Import your config --Optional
//The config-object is passed as an argument to every executed testcase/testfunction. This allows you to access all properties from the given config such as "Headless" for example. 
//If you pass your own config, both configs (your's and internal) will be merged and your config-properties overwrite the internal config-properties.
//If you don't pass your own config, the engine will use it's internal config. See chapter "Config".

//CAUTION: Not passing your own config results to the fact, that tests in a pipeline cannot be executed in any other way than on your local machine.
import { Config } from './puppeteer.config';

//Import your TestCases
import { googleSomething } from './tests/googleSomething.test';
import { takeOneScreenshot } from './tests/takeOneScreenshot.test';

//Setup the Testsuites
const testSuite1 = [ googleSomething ]; //Add as much testcases/functions as you want
const testSuite2 = [ takeOneScreenshot ]; //Add as much testcases/functions as you want

//Setup a name for each Testsuite --Optional
testSuite1.name = "TestSuiteNumber1";

//Insert all Testsuites into one Array
const AllTests = [testSuite1, testSuite2];

//Create your own puppeteer-launch-config --Optional
//If you don't pass your own puppeteer-launch-config, the engine will use it's internal puppeteer-launch-config
//If you pass your own puppeteer-launch-config, that config will be used - no merge between internal puppeteer-launch-config and yours.
//See: https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerlaunchoptions
const puppeteerLaunchOptions = {
  defaultViewport: null,
  args: [
    "--incognito", //Open the browser in incognito-mode, so we can be sure, that there's no caching (for login and/or js/css - files)
    "--ignore-certificate-errors", //Ignore possible certificate-errors
    "--start-maximized" //Open the browser maximized
  ], 
};

//3...2...1...GO!
(async () => {
  const engine = await Engine(Config);
  engine.Run(AllTests, puppeteerLaunchOptions);
})();

Scripts

Add these scripts to your package.json in order to run the above sample file:

  • "test": "babel-node ./tests/Puppeteer/index.js" //run the above sample file
  • "test-watch": "nodemon --exec babel-node ./tests/Puppeteer/index.js" //run the above sample file - watching*
  • "test-watch-and-debug": "nodemon --inspect --exec babel-node ./tests/Puppeteer/index.js" //run the above sample file - watching* & enables Debbuging --start via VS Code-debugger only as described in Debugging

watching: Test script runs/starts automatically whenever the Engine notice a change in your code. Triggered via save (ctrl+s)

babelrc

Add a .babelrc to your root-folder:

{   
  "presets": [
    "@babel/preset-env"   
  ] 
}

Debugging

  • Add a .vscode -folder to your project root.
  • Add a launch.json -file inside of the new folder with this content:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "chooseShownName", //will be shown in "RUN AND DEBUG" in vs code
            "restart": true,
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${workspaceRoot}",
            "preLaunchTask": "Start Tests",
            "postDebugTask": "Kill Terminal"
          }
    ]
}
  • Add a tasks.json -file inside of the new folder with this content:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Start Tests",
            "type": "npm",
            "script": "test-watch-and-debug", //script in the package.json
            "isBackground": true,
            "problemMatcher": [
              {
                "pattern": [
                  {
                    "regexp": ".",
                    "file": 1,
                    "location": 2,
                    "message": 3
                  }
                ],
                "background": {
                  "activeOnStart": true,
                  "beginsPattern": ".",
                  "endsPattern": "."
                }
              }
            ]
          },
          {
            "label": "Kill Terminal",
            "type": "process",
            "command":[
               "${command:workbench.action.terminal.kill}"
            ],
         },
    ]
}
  • Add Breakpoints
  • Debug your tests by Start Debbuging (F5) in VS Code.

Config

The current config, the engine uses:

{
  "writeAllLogs": true,
  "Headless": false, //Displays Chrome
  "ResultDir": "/results", //Dir for test results xml -files - independet from "ScreenshotDir"
  "ScreenshotDir": "/results/screenshots", //Dir for screenshots - independet from "ResultDir"
  "TakeScreenshots": true,
  "WriteTestResults": true,
  "Attempts": 3 //Amount of attempts, the engine will make. Test fails, if the second rerun (three runs in total) fails 
}

Support

In case of experiencing an issue with @shareflex/puppeteer-engine, please contact us at [email protected].

Contribute

Contributions to @shareflex/puppeteer-engine are welcome. Here is how you can contribute:

  • Submit pull requests
  • Submit bugs & feature requests, and help verify fixes