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

selenium-helpers

v0.1.6

Published

Set of helper functions for Selenium webdriver

Downloads

17

Readme

npm version Build Status Coverage Status Code Climate Inch CI

Dependency Status devDependency Status

selenium-helpers

Set of helper functions for Selenium webdriver

If you have different needs regarding the functionality, please add a feature request.

Installation

npm install --save selenium-helpers

Usage

const oneSecond = 1000;
const oneMinute = 60 * oneSecond;
const TIMEOUT = 2 * oneMinute;

const seleniumHelpers = require('selenium-helpers')({ timeout: TIMEOUT });

const url = 'http://some-login-page/';

/* return */ seleniumHelpers.buildChrome()
  .then((webDriver) => seleniumHelpers.openPage(url))
  .then(()   => seleniumHelpers.debug('* Login page is loading...'))
  .then((el) => seleniumHelpers.scrollAndType('#login', username) )
  .then((el) => seleniumHelpers.scrollAndType('#password', password) )
  .then((el) => seleniumHelpers.scrollAndClick('#') )
  .then(()   => seleniumHelpers.debug('* Username/password entered, waiting for home page...'))
  .then(()   => seleniumHelpers.waitForOneOfElements([
    By.css('#page-layout-1'),
    By.css('#page-layout-2'),
    By.css('#page-layout-3')
  ], TIMEOUT))
  .then(() => seleniumHelpers.debug('* Home page loaded.'))
  .catch((reason) => {
    console.log(reason);
    return Promise.reject(reason);
  })
;

Methods

buildChrome({ proxyConfig, chromeOptions })

Build the driver for Chrome using new clean Chrome profile.

  • proxyConfig - optional: { host, port, username, password [, tempDir ] }
  • chromeOptions - optional; if set, chromeOptions will be used when build the Chrome's driver.

returns {Promise}

buildFirefox({ profilePath })

Build the driver for Firefox using new clean Firefox profile.

  • profilePath - string - optional, path to Firefox profile

returns {Promise}

buildFirefoxWithProfile(firefoxProfilePath)

Build the driver for Firefox using existing Firefox profile defined by path firefoxProfilePath.

returns {Promise}

sleep(timeout)

Delay for timeout milliseconds

scrollToBottom()

Scroll to the bottom of the page.

scrollIntoView(webElementOrCssString)

Scroll to element defined as webElement or string css selector and click on it.

scrollAndClick(webElementOrCssString)

Scroll to element defined as webElement or string css selector and then click on it.

scrollAndType(webElementOrCssString)

Scroll to element defined as webElement or string css selector and then set its value property (as if value was typed in it).

waitForOneOfElements(bySelectors, timeout, string)

Wait until one of several elements will appear on the page. Possible elements are defined by array bySelectors of webdriver.By selectors.

  • bySelectors - array of webdriver.By selectors
  • timeout - wait timeout
  • string - optional string to output if fails

Example:

waitForOneOfElements([
    By.css('.element-class-1'),         
    By.css('#element-id-1'),                
    By.id('element-id-2'),                
    By.css('[name=some-name]')   
  ], TIMEOUT);

Full set of By selectors cn be found here: http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html

waitAndAct(actions)

Simple scripting-like function which allows to define:

  • Wait rules to wait for several conditions simultaneously:
    • wait, - CSS selector to wait;
    • waitText - Text to wait (anywhere on the whole page);
    • waitJs - Javascript expression to wait until evaluates to true.
  • Actions to execute when some element defined by one of wait rules is found. Several actions may be combined. Actions in order of execution:
    • sleep - pause (value in milliseconds);
    • scroll - scroll to element;
    • click - click on the element;
    • reload - reload the page;
    • cancel - stop to wait and continue with the program execution.

Example:

const ACTIONS = [
  { wait:  '.class1', click: '.button--to-click' }, // if this element found, click the button
  { wait:  '.class2', click: '.another-button'   }, // if other element found, click another button
  { wait:  '.class2', cancel: true },               // finish to wait
];

Action click is done in two phases: (1) scroll to element (2) click

clickAllDetails(cssToClick, xpathToParent, subCssToWait)

For each of elements defined by cssToClick:

  • remember path to element's parent defined by xpathToParent (example: './../..');

  • click the element

  • wait util some element with subCssToWait will appear under the element's parent

openPage(url, actions)

Open page (using driver.navigate().to(url)), then execute actions (see waitAndAct for more info on actions)

savePageSource(pathname)

Save value of driver.getPageSource() into file pathname

saveOuterHTML(pathname)

Save value of document.documentElement.outerHTML into file pathname

Debugging

This module uses standard debug with namespace selenium-helpers. In order to get output to console you must set environment variable DEBUG to the value of namespace.

Example for Linux:

DEBUG=selenium-helpers <command-to-start>

Example for Windows:

SET DEBUG=selenium-helpers
<command-to-start>

Where <command-to-start> is the command starting the app i.e.: node app.js or npm start etc.

Credits

Alexander

Links to package pages:

github.com   npmjs.com   travis-ci.org   coveralls.io   inch-ci.org

License

MIT