![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
js-auto-test
Advanced tools
Scaffolding on top of Protractor to follow a Page Object pattern for Automated UI tests.
The purpose of js-auto-test
is to provide some scaffolding on top of protractor to follow a Page Object pattern for Automated UI tests. The Library contains some classes to help structure and automate your tests. This is developed in parallel with the docker-auto-test-starter kit as the library that the Docker implementation is built upon. The starter kit has more of a complete example than what is provided below.
v2 comes with many enhancements including:
The library consists of two main classes: Fragment and Sequence.
A Fragment is a reusable group of HTML element references that can be tested. For instance, a top level navigation bar is a reusable group of HTML elements that could show up on many pages. It can be used as a shared Fragment component that can be associated with other Fragments. If you have unique content on the home page, you can make a home page Fragment that is associated with your navigation Fragment above. The purpose of a Fragment is for testing its elements and optionally performing actions against its elements.
Fragment provides basic testing functionality for getting/setting elements stored in a Map. It also provides some basic test methods to test any child fragments as well as check if the elements exist on the page. To perform more complex tests, extend the functionality of the class with additional test methods as needed. Don't forget to override testElements to call your new methods after calling await super.testElements()
to run the provided test methods.
A Sequence defines the steps an automated UI test specification needs to perform. It is also responsible to setting the entry point to the test sequence. It provides a Fragment cache to reference for each step in the sequence that will need to be defined.
I've started out with some basics and will be adding more over time (and open to feature requests).
The information below provides more details on each objects' methods in the interim until I've integrated with a documentation generator.
getElement (selector)
Gets the element stored in the Fragment's Map.
selector
- String
that represents the CSS selector for the elementelement
or element.all
fragment.getElement('#test')
setElement (selector, all = false)
Sets the element to store in the Fragment's Map of elements.
selector
- String
that represents the CSS selector for the elementall
- Truthy value to toggle selecting a single element if false or all elements if trueelement
or element.all
fragment.setElement('#test')
fragment.setElement('#test .all', true)
async testElements ()
Invokes the tests for all elements defined in a Fragment and any child Fragments referenced in the original Fragment. By default it only tests if the elements exist on the page. This should be overridden to add any additional tests specific to the Fragment.
Promise
fragment.testElements()
async testExists ()
Tests if all elements defined in a Fragment exist on the page. This is called in testElements
above.
Promise
fragment.testExists()
async testText (selector, text)
Tests the text of an element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementtext
- String
that represents the expected text of the elementPromise
fragment.testText('#test', 'text')
async testState (selector, state)
Tests the state of an element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementstate
- String|Array
that represents the possible state(s) of the element
displayed
enabled
selected
Promise
fragment.testState('#test', 'displayed')
fragment.testState('#test', ['displayed', 'enabled', 'selected'])
async testAttribute (selector, attribute, text)
Tests any attribute of an element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementattribute
- String
that represents the attribute you want to testtext
- String
that represents the expected text of the element's attributePromise
fragment.testAttribute('#test', 'type', 'text')
async elementClear (selector)
Clears any value set in a form text input element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementPromise
fragment.elementClear('#test')
async elementClick (selector)
Clicks an element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementPromise
fragment.elementClick('#test')
async elementSendKeys (selector, keys)
Sends keys to an element defined in a Fragment. This is useful for filling in form data or other complex keystrokes that a user may perform on a element.
selector
- String
that represents the CSS selector for the elementkeys
- String|Array
that represents the desired keys to press
Promise
fragment.elementSendKeys('#test', 'some text')
async elementSubmit (selector)
Submits a form element defined in a Fragment.
selector
- String
that represents the CSS selector for the elementPromise
fragment.elementSubmit('#test')
getFragment (key)
Gets the fragment stored in the Sequence's Map.
key
- String|Symbol
that represents the fragmentfragment
sequence.getFragment('test')
setFragment (key, fragment)
Sets the fragment to store in the Sequence's Map.
key
- String|Symbol
that represents the fragmentfragment
- Fragment objectfragment
sequence.setFragment('test', new Fragment())
setStep (step)
Sets the test steps to store in the Sequence's Array.
step
- Function|Array
to return an AsyncFunction that represents a test stepundefined
sequence.setStep(() => sequence.getUrl('/'))
sequence.setStep([
() => sequence.getUrl('/'),
() => fragment.testElements(),
() => fragment.elementClick('#testLink')
])
async getUrl (url)
Gets the page to test.
url
- String
that represents the relative or absolute URL of a page to testPromise
sequence.getUrl('/home')
async runSequence ()
Runs the array of steps defined in the Sequence.
Promise
sequence.runSequence()
Here is a simple example of an implementation using js-auto-test
. When testing a larger site with many tests, you will want to consider some structure around your code. I've added a suggested minimal folder structure below. I have also created a starter kit that contains a more advanced test than below with additional support scripts and environment/execution specifics.
./constants.js
// Selectors
export const IMG_SELECTOR = '#hplogo';
// Fragments
export const GOOGLE_FRAGMENT = Symbol('google fragment');
./fragments/GoogleFragment.js
import { IMG_SELECTOR } from '../constants';
import { Fragment } from 'js-auto-test';
export default class GoogleFragment extends Fragment {
constructor(fragments) {
super(fragments);
this.setElement(IMG_SELECTOR);
}
}
./sequences/GoogleSequence.js
import { GOOGLE_FRAGMENT } from '../constants';
import { Sequence } from 'js-auto-test';
import GoogleFragment from '../fragments/GoogleFragment';
export default class GoogleSequence extends Sequence {
constructor() {
super();
this.setFragment(GOOGLE_FRAGMENT, new GoogleFragment());
this.setStep(() => this.getUrl('/'));
this.setStep(this.getFragment(GOOGLE_FRAGMENT).testElements);
}
}
./specs/google.spec.js
import GoogleSequence from '../sequences/GoogleSequence';
browser.ignoreSynchronization = true;
describe('google homepage img test', () => {
let googleSequence;
before(() => {
googleSequence = new GoogleSequence();
});
it('expects img to exist on the google homepage', async () => {
await googleSequence.runSequence();
});
after(() => {
googleSequence = null;
});
});
./conf/config.js
exports.config = {
directConnect: true,
capabilities: {
browserName: 'chrome',
platform: 'ANY',
version: ''
},
baseUrl: 'https://www.google.com',
framework: 'mocha',
mochaOpts: {
reporter: 'spec',
timeout: 5000
},
specs: ['../dist/**/*spec.js']
};
FAQs
Scaffolding on top of Protractor to follow a Page Object pattern for Automated UI tests.
The npm package js-auto-test receives a total of 0 weekly downloads. As such, js-auto-test popularity was classified as not popular.
We found that js-auto-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.