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

@theia-extension-tester/locator-loader

v0.1.1

Published

Load objects from JavaScript files and apply diff changes made thorough each version.

Downloads

13

Readme

locator-loader

Modern web application constantly change and to ensure minimum quality requirements are met we test them. When creating new tests it is usually good pattern to split locators from test logic. However every update can potentially break those locators and as result break the tests.

This package was created to manage various versions of locators. Not necessary locators because the package can work with generic data. The package consists of 3 components.

  1. Locator loader - Load locators and apply diff changes.
  2. Locators - Key structure which must be partially exported by every version,
  3. Base locators - Initial locator file. The file must define every locator used in the tests.
  4. Diff locators - Locator changes. It must define only changed locators.

How to prepare locator structure

All base locators and locator changes must be in single directory. Locator file names must be in valid compare-versions format.

Let's assume we have just created ./locators/versions directory. First we must define our locator structure and create custom locator loader class.

// ./locators/MyLocators.ts

// Locator structure.
// Locator type can be Selenium By object or any other object.
export interface MyLocators {
    countryInput: Locator;
    personData: {
        firstNameInput: Locator;
        lastNameInput: Locator;
    }
    submit: Locator;
}

Define locator loader.

// ./locators/MyLocatorLoader.ts
import * as path from "path";
import { LocatorLoader } from "@theia-extension-tester/locator-loader";
import { MyLocators } from "./MyLocators";

// It is better to export path than using hardcoded ones.
export function getBaseLocatorFolder() {
    // __dirname := ./locators
    return path.join(__dirname, "versions");
}

// Locator structure. It is possible to create object directly new LocatorLoader<MyLocators>(...) as well.
export class MyLocatorLoader extends LocatorLoader<MyLocators> {
    constructor(version: string, baseVersion: string, baseFolder?: string) {
        super(version, baseVersion, baseFolder ?? getBaseLocatorFolder());
    }
}

After that it is possible to load locators but at this moment nothing can be loaded. To change that, follow create base locator guide.

// ./main.ts

import { MyLocatorLoader } from "./locators/MyLocatorLoader";
import { MyLocators } from "./MyLocators";

// Load locators
const locatorLoader = new MyLocatorLoader("2.4.1", "1.0.0");
const locators: MyLocators = locatorLoader.loadLocators();

Create base locators

Base locators are included in single file which in this guide is referred as version 1.0.0. The file must export locators: MyLocators variable. The variable name must not have different name and the variable must be legal TypeScript object (all mandatory properties must be defined).

For example:

// ./locators/versions/1.0.0.ts

export const locators: MyLocators = {
    countryInput: By.className("countryInput"),
    personData: {
        firstNameInput: By.className("firstNameInput"),
        lastNameInput: By.className("lastNameInput"),
    }
    submit: By.id("submit")
}

Patch changed locators

To create new patched locators, create new file ./locators/versions/x.y.z.ts. Versions may be skipped but the latest changes must be in file which has the highest version. Let's assume all inputs were migrated to use name attributes instead except the submit button.

Create new patch file 1.0.1.ts (version can be arbitrary but must be lower or equal than version used in locator loader). File format is similar to base locator file format but different variable is exported.

// ./locators/versions/1.0.0.ts
import { LocatorDiff } from "@theia-extension-tester/locator-loader";

export const diff: LocatorDiff<MyLocators> = {
    countryInput: By.name("country"),
    personData: {
        firstNameInput: By.name("firstName"),
        lastNameInput: By.name("lastName"),
    }
    // Unchanged locators do not have to be redefined.
    //submit: By.id("submit")
}

And thats all. For every version create new file and loader will apply changes.