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

webdriver-reuse-session

v0.1.2

Published

Manage Webdriver sessions and make sessions id's available for e.g. Protractor and other TDD and BBD tools

Downloads

255

Readme

WebDriver Reuse Session

TL;DR

  1. run 'webdriver-reuse-browser' - get the session id from a browser that can be reused
  2. insert the session id in the config file or via the command line

The Why?

If you want better, faster and more enjoyable test, then this is the place to be

  • Better - because the more times you run your test, the more bugs you can find
  • Faster - because browser start-up time, cache warm-up (loading of images and static JS), authentication and similar is removed or reduced
  • More Enjoyable - because slow test and long feedback times, is the oposite of Flow and Programmer Happiness.

Protractor is a nice an well-behaving tool, so it closes the browsers it creates, but sometimes you want to keep it open for debugging purposes or for speeding up the next test.

And Protractor actually supports attaching to browsers, but it needs some manual to start the browser.

This tool can..

Start Webdriver, Selenium or ChromeDriver sessions and make sessions id's available for Protractor and similar Web Browser Test Automation Frameworks

Speed up your tests

The normal approach is that every test run starts a new browser, which often takes between 5 to 10 seconds. Using webdriver-reuse-session Using this can take between 5-10 seconds of your start-up time, and sometimes even more. If you have an authentication step, then this can be added. I worked a case, where I could cut off 30 seconds of overhead, every time I wanted to run a 5 seconds test.

Other tips

Resist the temptation of using ts-node, unless you are doing it for the sake of debugging. Have a terminal running next to your other terminal with 'tsc -w' This is so much faster

Assumptions

  1. The local selenium/webdriver host is always http://localhost:4444/wd/hub
  2. The way to control a Web Driver is best done using webdriver-manager. I assume that you have this installed
  3. The best way to work with multiple browser types is [Protractor](https://www.protractortest.org/#/(https://w3c.github.io/webdriver/)

If you ...

  • believe that my assumptions are flawed...
  • have found a bug...
  • need something else...

Make an issue or a pull request or reach out to me via email - [email protected] .

Installation

npm install webdriver-reuse-session

Usage

The 'webdriver-reuse-session' script can be used both in a manual mode and in an automatic mode.

Manual Approach

Start a browser or find a Chrome Browser, in the manual approach

  1. Start Webdriver-manager or a raw selenium instance
npx webdriver-manager start
  1. Start the reuse sessions script
webdriver-reuse-session
  1. Take a note of the session id

From your test tool

  1. Setup your script to use a local host Selenium

    /** in your protractor.conf.js or similar config object*/
    directConnect: undefined,  // can be omitted, but just to show that directConnect must not be set
    seleniumAddress: 'http://localhost:4444/wd/hub',
  2. Use the SessionID in the command line

    protractor --seleniumSessionId=6aec0d5861daa54d0b9be17ec47bea70

The automatic approach

  1. Get the SessionID

    const sessionIdFromFile = fs.readFileSync('.seleniumSessionId.txt')
  2. Use the SessionID

    /** in your protractor.conf.js or similar config object*/
    
    directConnect: undefined,  // can be omitted, but just to show that directConnnect must not be set
    seleniumAddress: 'http://localhost:4444/wd/hub',
    seleniumSessionId: sessionIdFromFile,

Questions and Answers

What Test runners will this work with

It is independent of the test runner, it depends on how you define your Selenium Session ID.

Does this work with Cucumber

You can use this with Cucumber, Mocha, Jest and other test automation frameworks

Feedback and Issues

This is my first package on NPMJS, so feel free to give me feedback and log issues on Github

With wishes of faster testing for all of us,

Andreas