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

luopaieasyjs

v1.0.135

Published

SelenaJS is an easy-to-use npm package designed to help programmers configure and write tests with Selenium and JavaScript.

Downloads

169

Readme

SelenaJS

SelenaJS is a lightweight testing framework for Node.js, designed to simplify the creation and execution of end-to-end tests. With SelenaJS, you can easily define and organize your tests, and execute them in a reliable and repeatable way.

Installation

To use SelenaJS, you need to install it through npm. Open a terminal window and type:

npm install selenajs

Requirements

To run SelenaJS or any Selenium test/automation you may need to install a driver compatible with your browser to allow it to be automated.

Usage

To use SelenaJS in your project, you need to create one or more tests and add them to a Selena instance. You can then call the run() method to execute the tests in the instance.

Here's an example of how to use Selena to execute a simple test:

import { Test, Selena } from "selenajs";

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    await driver.get("https://www.google.com");
    const title = await driver.getTitle();
    if (title === "Google") {
        passed();
    } else {
        failed(`Unexpected title: ${title}`);
    }
});

const selena = new Selena();
selena.addAllTests([test]);
selena.run();

In this example, we create a new Test object and give it a name and category. We then define a test function that uses a Selenium WebDriver instance to navigate to https://www.google.com and retrieve the page title. If the title is "Google", the test is considered to have passed. Otherwise, the test fails with an error message.

We then create a Selena instance and add the test to it using the addAllTests() method. Finally, we call run() to execute all the tests in the instance.

Creating Tests

To create a new test in Selena, you need to create a new Test object and give it a name and category. You can then define a test function that uses a Selenium WebDriver instance to perform one or more actions, and call the passed() or failed() methods to indicate whether the test has passed or failed.

Here's an example of how to create a new test in Selena:

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    // Use the Selenium WebDriver instance to perform actions here
    // Call passed() if the test passes, or failed() if it fails
    // If failed() is not called, the test will be considered passed
});

Properties that you can pass into Test constructor:

  • name: string: A name to identify your test. - Required
  • category: string: A category name for grouping the test together with other tests.
  • config: object: A custom object to be consumed in your test. You can get this object using the method Test.getConfig().
  • builder: Builder: A Builder instance for selenium-webdriver.
    • Default: new Builder().forBrowser('chrome').
    • Note: The builder instance has to be passed without .build() method because this method will be automatically called when the test starts running.

Methods that you can use with you Test instance:

  • Test.createTest(test: TTestFunction): void: This method is used to create a new test into your Test instance.
    • Ex:
    test.createTest(async (driver, passed, failed) => {
        await driver.get("https://www.google.com");
        const title = await driver.getTitle();
        if (title === "Google") {
            passed();
        } else {
            failed(`Unexpected title: ${title}`);
        }
    });
  • Test.runTest(): Promise<TLog>: This method can be used to run this single test.
  • Test.getLog(): TLog: Get the log after the test has finished.
  • Test.getConfig(): object: Get the config object that has been passed in Test constructor.
  • Test.getCategory(): string: Get the name of the category of this test.
  • Test.getName(): string: Get the name of this test.

Running Tests

To run your tests, you need to create a new instance of Selena object. This object provides a CLI that makes it easy to manage your tests. You can add all tests inside it using the method .addAllTests(). Ex:

import { Test, Selena } from "selenajs";

const test = new Test({
    name: "Example Test",
    category: "Example Category"
});

test.createTest(async (driver, passed, failed) => {
    await driver.get("https://www.google.com");
    const title = await driver.getTitle();
    if (title === "Google") {
        passed();
    } else {
        failed(`Unexpected title: ${title}`);
    }
});

const selena = new Selena();
selena.addAllTests([test]);
selena.run();

The CLI provided by Selena allows you to run a single test, all tests, or tests from a specific category. Once the tests have finished running, Selena provides a report that displays how many tests were executed, how many tests passed, and how many tests failed.

Methods that you can use with you Selena instance:

  • Selena.addTest(test: Test): void: Add a single test into your Selena instance.
  • Selena.addAllTests(tests: Test[]): void: Add multiple tests into your Selena instance.
  • Selena.getLogs(): TLog[]: Get the log from all tests after it has finished.
  • Selena.run(): void: Initiate your tests, providing a CLI.

Using SelenaJS, you can streamline your testing process by running multiple tests at once and quickly identifying which tests have passed or failed. The report provided by Selena helps you to pinpoint any issues or bugs in your code and make necessary changes to improve your software's functionality.

Contributing

Thank you for considering contributing to SelenaJS! We welcome any contributions, whether they be bug fixes, feature requests, documentation improvements, or anything in between.

To contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your contribution.
  3. Make your changes and commit them, with descriptive commit messages.
  4. Push your branch to your forked repository.
  5. Open a pull request with a clear title and description of your changes.

We appreciate your contributions and hope to work with you soon!