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

@acryps/feature

v0.0.1

Published

**What is a feature and what can I do with it?**

Downloads

3

Readme

Features - Define your own web application features!

What is a feature and what can I do with it?

Usually, your application consists of several different functionalities. This could be, for example, that a user can configure a product on a web configurator or that a user is able to search for a specific product using a search prompt, and so on. Now, using Features, you can define those functionalities in code. You can define them step-by-step for your web applications.

Using those defined features, you can automatically generate guides, screenshots, and videos!. Thus, no more tedious work by hand!

Why would I want to do that?

Imagine you have finished the first version of your web application and created complete video guides for its functionalities. After a couple of weeks, the web application is redesigned. Now the videos are outdated, and you have to tediously recreate the video guides again by hand. Not with Features! With Features, you can simply re-execute the features, and the video guides are regenerated for the updated web application within seconds.

Additionally, features can be used to find bugs and unwanted UI changes across project versions. By comparing the screenshots of features across different versions, you will see unwanted changes within seconds!

Requirements

To use Features, you need to install ffmpeg.

Usage

The following shows an example where a product is configured.

Features uses method chaining in order to define the instructions of the feature. Each instruction can simply be chained after the previous one.

// define your project
const project = new Project('assembly', 'https://assembly.acryps.com');

// define your own feature
const feature = new Feature('basic usage', 'demonstrate basic usage of feature')
	// navigate to website
	.go(`https://assembly.acryps.com/`)

	// find html element 'action' which has content 'Action' and click it
	.element('action', 'Create').click()

	// wait while html element 'indicator' is present
	.waitWhile('indicator')

	// find html element 'Body Type' and click it
	.element('name', 'Body Type').click()

	.element('name', 'Wafer').click()

	.element('action', 'Save As...').click()

	// find html input element 'save-assembly input' and write 'My Configuration' into input field
	.element('save-assembly input').write('My Configuration')
	.element('action', 'Add to my Assemblies').click();

// execute the feature for a project
const result = await feature.execute(project)
	.guide() // generate a guide
	.screenshot() // generate screenshots for each step
	.video('./basic-usage/video.webm') // generate video
	.run();

// save result
await result.save('./media/basic-usage');

Elements

In order to interact with a web application, we need to be able to tell Features which elements we want to interact with. To do this, we have element to handle single elements and elements to handle multiple elements. Both of those use 'locators' to search the element on the webpage. These locators describe the HTML tags of the elements.

For example, if we have the following webpage:

<html>
	<body>
		<title>
			<name>Title</name>
		</title>

		<panels>
			<panel>
				<name>panel 1</name>
			</panel>

			<panel>
				<name>panel 2</name>
			</panel>
		</panels>
	</body>
</html>

We can select the title like this:

feature.element('title name')
	// and then interact with it
	.click();

We can interact with multiple elements, such as the panels:

// now we selected all the 'panel' elements
feature.elements('panels panel');

To interact with a single panel, we have to filter them. This can be done in various ways:

// select the first panel
feature.elements('panels panel').first()
	// then click on the selected element
	.click();

// get the element at index 1 (the second element)
feature.elements('panels panel').at(1)
	// then hover on it
	.hover();

// filter according to where conditions
feature.elements('panels panel')
	// select the panel which has an element 'name' with content 'panel 1'
	.where('name', 'panel 1')
	.first()
		.click();

This is the basic usage of element and elements. However, the chaining of elements is unlimited, so you can do much more!

Please refer to the class documentation for detailed descriptions of the functions available for Feature, SingleElement, MultipleElement and Select.

Execution and Result

After having defined your own feature, it's time to execute it!

A feature can be executed using execute, a project, and a viewport.

const project = new Project('example-project', 'https://example.com');
const viewport = { width: 1280, height: 720, deviceScaleFactor: 1 };

const execution = feature.execute(project, viewport);

This returns an instance of Execution. Using an execution, we can specify how we want to execute the feature. By adding guide, screenshot, or video, we can specify if we want to generate a guide, screenshots, or video. We can additionally tell the execution to not run in headless mode, meaning you will be able to see the browser executing the feature. This can be done by simply adding a boolean value to the run function: .run(false).

// generate guide, screenshot, and video
const result = await execution
	.guide()
	.screenshot()
	.video('./media/video.webm')
	.run();    // running headless

Finally, you can save your result using the ExecutionResult.

await result.save('./media/example');

Further Documentation

For more detailed documentation and extended usage, see here.