Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atomic-testing/core

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomic-testing/core - npm Package Compare versions

Comparing version 0.30.0 to 0.31.0

dist/locators/byLinkedElement.d.ts

2

dist/locators/byAttribute.js

@@ -8,3 +8,3 @@ "use strict";

function byAttribute(name, value, relativeTo = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const selector = `[${(0, escapeUtil_1.escapeName)(name)}="${(0, escapeUtil_1.escapeValue)(value)}"]`;
const selector = name === 'id' ? `#${(0, escapeUtil_1.escapeId)(value)}` : `[${(0, escapeUtil_1.escapeName)(name)}="${(0, escapeUtil_1.escapeValue)(value)}"]`;
return new CssLocator_1.CssLocator(selector, {

@@ -11,0 +11,0 @@ relative: relativeTo,

export { CssLocator } from './CssLocator';
export * from './LinkedCssLocator';
export { LocatorRelativePosition } from './LocatorRelativePosition';

@@ -12,2 +13,3 @@ export { LocatorTypeLookup } from './LocatorType';

export { byInputType } from './byInputType';
export { byLinkedElement } from './byLinkedElement';
export { byName } from './byName';

@@ -14,0 +16,0 @@ export { byRole } from './byRole';

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.byValue = exports.byTagName = exports.byRole = exports.byName = exports.byInputType = exports.byDataTestId = exports.byCssSelector = exports.byCssClass = exports.byChecked = exports.byAttribute = exports.LocatorTypeLookup = exports.LocatorRelativePosition = exports.CssLocator = void 0;
exports.byValue = exports.byTagName = exports.byRole = exports.byName = exports.byLinkedElement = exports.byInputType = exports.byDataTestId = exports.byCssSelector = exports.byCssClass = exports.byChecked = exports.byAttribute = exports.LocatorTypeLookup = exports.LocatorRelativePosition = exports.CssLocator = void 0;
var CssLocator_1 = require("./CssLocator");
Object.defineProperty(exports, "CssLocator", { enumerable: true, get: function () { return CssLocator_1.CssLocator; } });
__exportStar(require("./LinkedCssLocator"), exports);
var LocatorRelativePosition_1 = require("./LocatorRelativePosition");

@@ -22,2 +37,4 @@ Object.defineProperty(exports, "LocatorRelativePosition", { enumerable: true, get: function () { return LocatorRelativePosition_1.LocatorRelativePosition; } });

Object.defineProperty(exports, "byInputType", { enumerable: true, get: function () { return byInputType_1.byInputType; } });
var byLinkedElement_1 = require("./byLinkedElement");
Object.defineProperty(exports, "byLinkedElement", { enumerable: true, get: function () { return byLinkedElement_1.byLinkedElement; } });
var byName_1 = require("./byName");

@@ -24,0 +41,0 @@ Object.defineProperty(exports, "byName", { enumerable: true, get: function () { return byName_1.byName; } });

@@ -25,4 +25,4 @@ import { CssLocator, CssLocatorInitializer } from './CssLocator';

private _valueExtract;
_matchingTargetLocator: PartLocator;
_matchingTargetValueExtract: LinkedCssLocatorValueExtract;
private _matchingTargetLocator;
private _matchingTargetValueExtract;
constructor(selector: string, initializeValue: LinkedCssLocatorInitializer & Partial<CssLocatorInitializer>);

@@ -29,0 +29,0 @@ get complexity(): LocatorComplexity;

export declare function escapeName(name: string): string;
export declare function escapeValue(value: string): string;
export declare function escapeCssClassName(name: string): string;
export declare function escapeId(id: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeCssClassName = exports.escapeValue = exports.escapeName = void 0;
exports.escapeId = exports.escapeCssClassName = exports.escapeValue = exports.escapeName = void 0;
function escapeName(name) {

@@ -16,2 +16,6 @@ return encodeURIComponent(name);

exports.escapeCssClassName = escapeCssClassName;
function escapeId(id) {
return id.split(':').join('\\:');
}
exports.escapeId = escapeId;
//# sourceMappingURL=escapeUtil.js.map

@@ -0,3 +1,5 @@

import { Optional } from '../dataTypes';
import { Interactor } from '../interactor';
import { CssLocator } from '../locators/CssLocator';
import { LinkedCssLocator } from '../locators/LinkedCssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';

@@ -9,4 +11,7 @@ import { CssLocatorChain, PartLocator } from '../locators/PartLocator';

export declare function findRootLocatorIndex(locator: PartLocator): number;
export declare function getEffectiveLocator(locator: PartLocator): CssLocator[];
export declare function toPrimitiveLocators(locator: PartLocator, interactor: Interactor): Promise<CssLocator[]>;
export declare function getEffectiveLocator(locator: PartLocator, interactor: Interactor): Promise<CssLocator[]>;
export declare function toCssSelector(locator: PartLocator, interactor: Interactor): Promise<string>;
export declare function getLinkedCssLocator(locator: LinkedCssLocator, context: PartLocator, interactor: Interactor): Promise<PartLocator>;
export declare function getLinkedCssLocatorMatchingTargetValue(locator: LinkedCssLocator, context: PartLocator, interactor: Interactor): Promise<Optional<string>>;
export declare function getLocatorStatement(locator: CssLocator): string;

@@ -13,0 +18,0 @@ export interface OverrideLocatorRelativePositionOption {

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.overrideLocatorRelativePosition = exports.defaultOverrideLocatorRelativePositionOption = exports.getLocatorStatement = exports.toCssSelector = exports.getEffectiveLocator = exports.findRootLocatorIndex = exports.append = exports.toChain = exports.isChain = void 0;
exports.overrideLocatorRelativePosition = exports.defaultOverrideLocatorRelativePositionOption = exports.getLocatorStatement = exports.getLinkedCssLocatorMatchingTargetValue = exports.getLinkedCssLocator = exports.toCssSelector = exports.getEffectiveLocator = exports.toPrimitiveLocators = exports.findRootLocatorIndex = exports.append = exports.toChain = exports.isChain = void 0;
const locators_1 = require("../locators");
const LinkedCssLocator_1 = require("../locators/LinkedCssLocator");
const LocatorRelativePosition_1 = require("../locators/LocatorRelativePosition");

@@ -33,18 +44,75 @@ function isChain(locator) {

exports.findRootLocatorIndex = findRootLocatorIndex;
function getEffectiveLocator(locator) {
const list = toChain(locator);
const rootLocatorIndex = findRootLocatorIndex(list);
return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);
function toPrimitiveLocators(locator, interactor) {
return __awaiter(this, void 0, void 0, function* () {
const list = toChain(locator);
let result = [];
for (let i = 0; i < list.length; i++) {
const loc = list[i];
if (loc instanceof LinkedCssLocator_1.LinkedCssLocator) {
const currentContext = list.slice(0, i);
const resolved = yield getLinkedCssLocator(loc, currentContext, interactor);
result = result.concat(resolved);
}
else {
result.push(loc);
}
}
return result;
});
}
exports.toPrimitiveLocators = toPrimitiveLocators;
function getEffectiveLocator(locator, interactor) {
return __awaiter(this, void 0, void 0, function* () {
const list = yield toPrimitiveLocators(locator, interactor);
const rootLocatorIndex = findRootLocatorIndex(list);
// If the locator is linked, we should skip because it has matching locator
// would need the context
const shouldSkip = rootLocatorIndex === -1 || list[rootLocatorIndex].complexity === 'linked';
return shouldSkip ? list : list.slice(rootLocatorIndex);
});
}
exports.getEffectiveLocator = getEffectiveLocator;
function toCssSelector(locator, interactor) {
const effectiveLocator = getEffectiveLocator(locator);
const statements = effectiveLocator.map((loc) => {
const statement = getLocatorStatement(loc);
const separator = loc.relative === LocatorRelativePosition_1.LocatorRelativePosition.Same ? '' : ' ';
return separator + statement;
return __awaiter(this, void 0, void 0, function* () {
const effectiveLocator = yield getEffectiveLocator(locator, interactor);
const statements = [];
for (let i = 0; i < effectiveLocator.length; i++) {
let statement = '';
const loc = effectiveLocator[i];
statement = getLocatorStatement(loc);
const separator = loc.relative === LocatorRelativePosition_1.LocatorRelativePosition.Same ? '' : ' ';
statements.push(separator + statement);
}
return Promise.resolve(statements.join('').trim());
});
return Promise.resolve(statements.join('').trim());
}
exports.toCssSelector = toCssSelector;
function getLinkedCssLocator(locator, context, interactor) {
return __awaiter(this, void 0, void 0, function* () {
const matchTargetValue = yield getLinkedCssLocatorMatchingTargetValue(locator, context, interactor);
if (matchTargetValue == null) {
// TODO: Produce more descriptive error to help with troubleshooting
throw new Error('Match target not found for LinkedCssLocator');
}
let resolvedLocator;
if (locator.valueExtract.type === 'attribute') {
resolvedLocator = (0, locators_1.byAttribute)(locator.valueExtract.attributeName, matchTargetValue, locator.relative);
}
else {
throw new Error(`Cannot handle valueExtract method type ${locator.valueExtract.type}`);
}
return resolvedLocator;
});
}
exports.getLinkedCssLocator = getLinkedCssLocator;
function getLinkedCssLocatorMatchingTargetValue(locator, context, interactor) {
return __awaiter(this, void 0, void 0, function* () {
if (locator.matchingTargetValueExtract.type === 'attribute') {
const entireLocator = append(context, locator.matchingTargetLocator);
return yield interactor.getAttribute(entireLocator, locator.matchingTargetValueExtract.attributeName);
}
throw new Error(`Cannot handle valueExtract method type ${locator.matchingTargetValueExtract.type}`);
});
}
exports.getLinkedCssLocatorMatchingTargetValue = getLinkedCssLocatorMatchingTargetValue;
function getLocatorStatement(locator) {

@@ -51,0 +119,0 @@ return locator.selector;

{
"name": "@atomic-testing/core",
"version": "0.30.0",
"version": "0.31.0",
"description": "Core library for atomic-testing",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,2 +0,2 @@

import { escapeName, escapeValue } from '../utils/escapeUtil';
import { escapeId, escapeName, escapeValue } from '../utils/escapeUtil';
import { CssLocator } from './CssLocator';

@@ -17,3 +17,3 @@ import { LocatorRelativePosition } from './LocatorRelativePosition';

): CssLocator {
const selector = `[${escapeName(name)}="${escapeValue(value)}"]`;
const selector = name === 'id' ? `#${escapeId(value)}` : `[${escapeName(name)}="${escapeValue(value)}"]`;
return new CssLocator(selector, {

@@ -20,0 +20,0 @@ relative: relativeTo,

export { CssLocator } from './CssLocator';
export * from './LinkedCssLocator';
export { LocatorRelativePosition } from './LocatorRelativePosition';

@@ -12,2 +13,3 @@ export { LocatorTypeLookup } from './LocatorType';

export { byInputType } from './byInputType';
export { byLinkedElement } from './byLinkedElement';
export { byName } from './byName';

@@ -14,0 +16,0 @@ export { byRole } from './byRole';

@@ -38,4 +38,4 @@ import { byDataTestId } from './byDataTestId';

_matchingTargetLocator: PartLocator = byDataTestId('not-set');
_matchingTargetValueExtract: LinkedCssLocatorValueExtract = {
private _matchingTargetLocator: PartLocator = byDataTestId('not-set');
private _matchingTargetValueExtract: LinkedCssLocatorValueExtract = {
type: 'attribute',

@@ -42,0 +42,0 @@ attributeName: 'value',

@@ -12,1 +12,5 @@ export function escapeName(name: string): string {

}
export function escapeId(id: string): string {
return id.split(':').join('\\:');
}

@@ -0,3 +1,6 @@

import { Optional } from '../dataTypes';
import { Interactor } from '../interactor';
import { byAttribute } from '../locators';
import { CssLocator } from '../locators/CssLocator';
import { LinkedCssLocator } from '../locators/LinkedCssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';

@@ -36,15 +39,38 @@ import { CssLocatorChain, PartLocator } from '../locators/PartLocator';

export function getEffectiveLocator(locator: PartLocator): CssLocator[] {
export async function toPrimitiveLocators(locator: PartLocator, interactor: Interactor): Promise<CssLocator[]> {
const list = toChain(locator);
let result: CssLocator[] = [];
for (let i = 0; i < list.length; i++) {
const loc = list[i];
if (loc instanceof LinkedCssLocator) {
const currentContext = list.slice(0, i);
const resolved = await getLinkedCssLocator(loc, currentContext, interactor);
result = result.concat(resolved);
} else {
result.push(loc);
}
}
return result;
}
export async function getEffectiveLocator(locator: PartLocator, interactor: Interactor): Promise<CssLocator[]> {
const list = await toPrimitiveLocators(locator, interactor);
const rootLocatorIndex = findRootLocatorIndex(list);
return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);
// If the locator is linked, we should skip because it has matching locator
// would need the context
const shouldSkip = rootLocatorIndex === -1 || list[rootLocatorIndex].complexity === 'linked';
return shouldSkip ? list : list.slice(rootLocatorIndex);
}
export function toCssSelector(locator: PartLocator, interactor: Interactor): Promise<string> {
const effectiveLocator = getEffectiveLocator(locator);
const statements: string[] = effectiveLocator.map((loc) => {
const statement = getLocatorStatement(loc);
export async function toCssSelector(locator: PartLocator, interactor: Interactor): Promise<string> {
const effectiveLocator = await getEffectiveLocator(locator, interactor);
const statements: string[] = [];
for (let i = 0; i < effectiveLocator.length; i++) {
let statement = '';
const loc = effectiveLocator[i];
statement = getLocatorStatement(loc);
const separator = loc.relative === LocatorRelativePosition.Same ? '' : ' ';
return separator + statement;
});
statements.push(separator + statement);
}

@@ -54,2 +80,36 @@ return Promise.resolve(statements.join('').trim());

export async function getLinkedCssLocator(
locator: LinkedCssLocator,
context: PartLocator,
interactor: Interactor,
): Promise<PartLocator> {
const matchTargetValue = await getLinkedCssLocatorMatchingTargetValue(locator, context, interactor);
if (matchTargetValue == null) {
// TODO: Produce more descriptive error to help with troubleshooting
throw new Error('Match target not found for LinkedCssLocator');
}
let resolvedLocator: CssLocator;
if (locator.valueExtract.type === 'attribute') {
resolvedLocator = byAttribute(locator.valueExtract.attributeName, matchTargetValue, locator.relative);
} else {
throw new Error(`Cannot handle valueExtract method type ${locator.valueExtract.type}`);
}
return resolvedLocator;
}
export async function getLinkedCssLocatorMatchingTargetValue(
locator: LinkedCssLocator,
context: PartLocator,
interactor: Interactor,
): Promise<Optional<string>> {
if (locator.matchingTargetValueExtract.type === 'attribute') {
const entireLocator = append(context, locator.matchingTargetLocator);
return await interactor.getAttribute(entireLocator, locator.matchingTargetValueExtract.attributeName);
}
throw new Error(`Cannot handle valueExtract method type ${locator.matchingTargetValueExtract.type}`);
}
export function getLocatorStatement(locator: CssLocator): string {

@@ -56,0 +116,0 @@ return locator.selector;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc