Socket
Socket
Sign inDemoInstall

@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.27.0 to 0.28.0

dist/locators/byCssSelector.d.ts

10

dist/drivers/ComponentDriver.d.ts
import { Optional } from '../dataTypes';
import { Interactor } from '../interactor';
import { LocatorChain, LocatorRelativePosition } from '../locators';
import { LocatorRelativePosition, PartLocator } from '../locators';
import { IComponentDriver, IComponentDriverOption, PartName, ScenePart, ScenePartDriver } from '../partTypes';

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

readonly commutableOption: IComponentDriverOption<T>;
constructor(locator: LocatorChain, interactor: Interactor, option?: Partial<IComponentDriverOption<T>>);
constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IComponentDriverOption<T>>);
/**

@@ -24,7 +24,7 @@ * Usually this should be undefined as the component driver corresponds to a component nested inside the parent DOM, thus

* When the component is rendered outside the parent's DOM, which usually happens when the component is a modal or popup,
* supply the LocatorChain on how to locate the component with the component's own locator.
* supply the PartLocator on how to locate the component with the component's own locator.
*
* Caution of usage: this function is called before the construction of the driver, so it should not use any instance properties
*/
overriddenParentLocator(): Optional<LocatorChain>;
overriddenParentLocator(): Optional<PartLocator>;
/**

@@ -49,3 +49,3 @@ * Usually this should be undefined when the locator is defined by the ScenePart, thus it reflects the natural relative position

*/
get locator(): LocatorChain;
get locator(): PartLocator;
/**

@@ -52,0 +52,0 @@ * Check the specified parts' existences, and throw MissPartError if any of the part is found not existence.

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

* When the component is rendered outside the parent's DOM, which usually happens when the component is a modal or popup,
* supply the LocatorChain on how to locate the component with the component's own locator.
* supply the PartLocator on how to locate the component with the component's own locator.
*

@@ -57,0 +57,0 @@ * Caution of usage: this function is called before the construction of the driver, so it should not use any instance properties

import { Interactor } from '../interactor';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { IComponentDriver, IContainerDriverOption, ScenePart, ScenePartDriver } from '../partTypes';

@@ -7,4 +7,4 @@ import { ComponentDriver } from './ComponentDriver';

private readonly _content;
constructor(locator: LocatorChain, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>);
constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>);
get content(): ScenePartDriver<ContentT>;
}

@@ -0,4 +1,4 @@

import { PartLocator } from '..';
import { Interactor } from '../interactor';
import { LocatorChain } from '../locators';
import { IComponentDriverOption, ScenePart, ScenePartDriver } from '../partTypes';
export declare function getPartFromDefinition<T extends ScenePart>(partDefinition: T, parentLocator: LocatorChain, interactor: Interactor, option: Partial<IComponentDriverOption<T>>): ScenePartDriver<T>;
export declare function getPartFromDefinition<T extends ScenePart>(partDefinition: T, parentLocator: PartLocator, interactor: Interactor, option: Partial<IComponentDriverOption<T>>): ScenePartDriver<T>;

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

for (const [nestedComponentName, scenePart2] of Object.entries(partDefinition)) {
const { locator = nestedComponentName, driver, option: optionOverride } = scenePart2;
const { locator, driver, option: optionOverride } = scenePart2;
const componentOption = Object.assign(Object.assign(Object.assign({}, option), optionOverride), { parts: undefined });

@@ -12,0 +12,0 @@ const locatorContext = (_a = driver.prototype.overriddenParentLocator()) !== null && _a !== void 0 ? _a : parentLocator;

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

import { LocatorChain, PartLocatorType } from '../locators';
import { PartLocator } from '../locators';
import { ComponentDriverClass } from '../partTypes';

@@ -13,3 +13,3 @@ import { ComponentDriver } from './ComponentDriver';

*/
export declare function getListItemByIndex<T extends ComponentDriver>(host: ComponentDriver<any>, itemLocatorBase: LocatorChain | PartLocatorType, index: number, driverClass: ComponentDriverClass<T>): Promise<T | null>;
export declare function getListItemByIndex<T extends ComponentDriver>(host: ComponentDriver<any>, itemLocatorBase: PartLocator, index: number, driverClass: ComponentDriverClass<T>): Promise<T | null>;
/**

@@ -22,2 +22,2 @@ * Get an iterator of list item driver.

*/
export declare function getListItemIterator<T extends ComponentDriver>(host: ComponentDriver<any>, itemLocatorBase: LocatorChain | PartLocatorType, driverClass: ComponentDriverClass<T>): AsyncGenerator<T, void, unknown>;
export declare function getListItemIterator<T extends ComponentDriver>(host: ComponentDriver<any>, itemLocatorBase: PartLocator | PartLocator, driverClass: ComponentDriverClass<T>): AsyncGenerator<T, void, unknown>;

@@ -38,7 +38,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
const nthLocator = {
type: locators_1.LocatorType.Css,
selector: `:nth-of-type(${index + 1})`,
relative: locators_1.LocatorRelativePosition.Same,
};
const nthLocator = (0, locators_1.byCssSelector)(`:nth-of-type(${index + 1})`, locators_1.LocatorRelativePosition.Same);
const itemLocator = (0, locatorUtil_1.append)(itemLocatorBase, nthLocator);

@@ -45,0 +41,0 @@ const exists = yield host.interactor.exists(itemLocator);

import { ComponentDriver } from '../drivers/ComponentDriver';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { ErrorBase } from './ErrorBase';
export declare const ItemNotFoundErrorId = "ItemNotFoundError";
export declare class ItemNotFoundError extends ErrorBase {
readonly locator: LocatorChain;
readonly locator: PartLocator;
readonly driver: ComponentDriver<any>;
constructor(locator: LocatorChain, driver: ComponentDriver<any>);
constructor(locator: PartLocator, driver: ComponentDriver<any>);
}
import { ComponentDriver } from '../drivers/ComponentDriver';
import { PartLocatorType } from '../locators/PartLocatorType';
import { PartLocator } from '../locators/PartLocator';
import { ErrorBase } from './ErrorBase';
export declare const TooManyMatchingElementErrorId = "TooManyMatchingElementError";
export declare class TooManyMatchingElementError extends ErrorBase {
readonly query: PartLocatorType;
readonly query: PartLocator;
readonly driver: ComponentDriver<any>;
constructor(query: PartLocatorType, driver: ComponentDriver<any>);
constructor(query: PartLocator, driver: ComponentDriver<any>);
}
import { ComponentDriver } from '../drivers/ComponentDriver';
import { WaitForOption } from '../drivers/WaitForOption';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { ErrorBase } from './ErrorBase';
export declare const WaitForFailureErrorId = "WaitForFailureError";
export declare class WaitForFailureError extends ErrorBase {
readonly locator: LocatorChain;
readonly locator: PartLocator;
readonly driver: ComponentDriver<any>;
constructor(locator: LocatorChain, option: WaitForOption, driver: ComponentDriver<any>);
constructor(locator: PartLocator, option: WaitForOption, driver: ComponentDriver<any>);
}
import { Optional } from '../dataTypes';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { ClickOption } from './ClickOption';

@@ -12,3 +12,3 @@ import type { CssProperty } from './CssProperty';

*/
click(locator: LocatorChain, option?: Partial<ClickOption>): Promise<void>;
click(locator: PartLocator, option?: Partial<ClickOption>): Promise<void>;
/**

@@ -19,3 +19,3 @@ * Type text into the desired element

*/
enterText(locator: LocatorChain, text: string, option?: Partial<EnterTextOption>): Promise<void>;
enterText(locator: PartLocator, text: string, option?: Partial<EnterTextOption>): Promise<void>;
/**

@@ -26,3 +26,3 @@ * Select option by value from a select element

*/
selectOptionValue(locator: LocatorChain, values: string[]): Promise<void>;
selectOptionValue(locator: PartLocator, values: string[]): Promise<void>;
/**

@@ -32,3 +32,3 @@ * Perform a mouse hover on the desired element

*/
hover(locator: LocatorChain): Promise<void>;
hover(locator: PartLocator): Promise<void>;
/**

@@ -39,3 +39,3 @@ * Wait for a given amount of time in milliseconds

wait(ms: number): Promise<void>;
getInputValue(locator: LocatorChain): Promise<Optional<string>>;
getInputValue(locator: PartLocator): Promise<Optional<string>>;
/**

@@ -45,3 +45,3 @@ * Get the select element's selected options' values

*/
getSelectValues(locator: LocatorChain): Promise<Optional<readonly string[]>>;
getSelectValues(locator: PartLocator): Promise<Optional<readonly string[]>>;
/**

@@ -51,6 +51,6 @@ * Get the select element's selected options' labels

*/
getSelectLabels(locator: LocatorChain): Promise<Optional<readonly string[]>>;
getAttribute(locator: LocatorChain, name: string, isMultiple: true): Promise<readonly string[]>;
getAttribute(locator: LocatorChain, name: string, isMultiple: false): Promise<Optional<string>>;
getAttribute(locator: LocatorChain, name: string): Promise<Optional<string>>;
getSelectLabels(locator: PartLocator): Promise<Optional<readonly string[]>>;
getAttribute(locator: PartLocator, name: string, isMultiple: true): Promise<readonly string[]>;
getAttribute(locator: PartLocator, name: string, isMultiple: false): Promise<Optional<string>>;
getAttribute(locator: PartLocator, name: string): Promise<Optional<string>>;
/**

@@ -61,12 +61,12 @@ * Get the value of a style property

*/
getStyleValue(locator: LocatorChain, propertyName: CssProperty): Promise<Optional<string>>;
getText(locator: LocatorChain): Promise<Optional<string>>;
exists(locator: LocatorChain): Promise<boolean>;
isChecked(locator: LocatorChain): Promise<boolean>;
isDisabled(locator: LocatorChain): Promise<boolean>;
isReadonly(locator: LocatorChain): Promise<boolean>;
isVisible(locator: LocatorChain): Promise<boolean>;
hasCssClass(locator: LocatorChain, className: string): Promise<boolean>;
hasAttribute(locator: LocatorChain, name: string): Promise<boolean>;
getStyleValue(locator: PartLocator, propertyName: CssProperty): Promise<Optional<string>>;
getText(locator: PartLocator): Promise<Optional<string>>;
exists(locator: PartLocator): Promise<boolean>;
isChecked(locator: PartLocator): Promise<boolean>;
isDisabled(locator: PartLocator): Promise<boolean>;
isReadonly(locator: PartLocator): Promise<boolean>;
isVisible(locator: PartLocator): Promise<boolean>;
hasCssClass(locator: PartLocator, className: string): Promise<boolean>;
hasAttribute(locator: PartLocator, name: string): Promise<boolean>;
clone(): Interactor;
}

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byAttribute(name: string, value: string, relativeTo?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByAttributeSource = {
_id: 'byAttribute';
name: string;
value: string;
relativeTo: LocatorRelativePosition;
};
export declare function byAttribute(name: string, value: string, relativeTo?: LocatorRelativePosition): CssLocator;

@@ -5,12 +5,17 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byAttribute(name, value, relativeTo = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byAttribute(name, value, relativeTo = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const selector = `[${(0, escapeUtil_1.escapeName)(name)}="${(0, escapeUtil_1.escapeValue)(value)}"]`;
return {
type: PartLocatorType_1.LocatorType.Css,
selector,
return new CssLocator_1.CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byAttribute',
name,
value,
relativeTo,
},
});
}
exports.byAttribute = byAttribute;
//# sourceMappingURL=byAttribute.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byChecked(checked?: boolean, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByCheckedSource = {
_id: 'byChecked';
checked: boolean;
relative: LocatorRelativePosition;
};
export declare function byChecked(checked?: boolean, relative?: LocatorRelativePosition): CssLocator;
"use strict";
// TODO: Use descriptive selector instead of css selector so the selector can be reintepreted
Object.defineProperty(exports, "__esModule", { value: true });
exports.byChecked = void 0;
const PartLocatorType_1 = require("./PartLocatorType");
// to implementation other than CSS selector
function byChecked(checked = true, relative = PartLocatorType_1.LocatorRelativePosition.Same) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byChecked(checked = true, relative = LocatorRelativePosition_1.LocatorRelativePosition.Same) {
let selector = ':checked';

@@ -12,9 +11,12 @@ if (!checked) {

}
return {
type: PartLocatorType_1.LocatorType.Css,
selector,
return new CssLocator_1.CssLocator(selector, {
relative,
};
source: {
_id: 'byChecked',
checked,
relative,
},
});
}
exports.byChecked = byChecked;
//# sourceMappingURL=byChecked.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byCssClass(className: string | string[], relativeTo?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByCssClassSource = {
_id: 'byCssClass';
className: string | string[];
relative: LocatorRelativePosition;
};
export declare function byCssClass(className: string | string[], relativeTo?: LocatorRelativePosition): CssLocator;

@@ -5,13 +5,17 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byCssClass(className, relativeTo = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byCssClass(className, relativeTo = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const classNames = Array.isArray(className) ? className : [className];
const selector = classNames.map((cls) => `.${(0, escapeUtil_1.escapeCssClassName)(cls)}`).join('');
return {
type: PartLocatorType_1.LocatorType.Css,
selector,
return new CssLocator_1.CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byCssClass',
className,
relative: relativeTo,
},
});
}
exports.byCssClass = byCssClass;
//# sourceMappingURL=byCssClass.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byDataTestId(id: string | string[], relativeTo?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByDataTestIdSource = {
_id: 'byDataTestId';
id: string | string[];
relative: LocatorRelativePosition;
};
export declare function byDataTestId(id: string | string[], relativeTo?: LocatorRelativePosition): CssLocator;

@@ -5,13 +5,17 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byDataTestId(id, relativeTo = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byDataTestId(id, relativeTo = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const ids = Array.isArray(id) ? id : [id];
const selector = ids.map((idVal) => `[data-testid="${(0, escapeUtil_1.escapeValue)(idVal)}"]`).join(' ');
return {
type: PartLocatorType_1.LocatorType.Css,
selector,
return new CssLocator_1.CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byDataTestId',
id,
relative: relativeTo,
},
});
}
exports.byDataTestId = byDataTestId;
//# sourceMappingURL=byDataTestId.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byInputType(type: string, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByInputTypeSource = {
_id: 'byInputType';
type: string;
relative: LocatorRelativePosition;
};
export declare function byInputType(type: string, relative?: LocatorRelativePosition): CssLocator;

@@ -6,13 +6,17 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
// to implementation other than CSS selector
function byInputType(type, relative = PartLocatorType_1.LocatorRelativePosition.Descendent) {
function byInputType(type, relative = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const selector = `input[type=${(0, escapeUtil_1.escapeValue)(type)}]`;
return {
type: PartLocatorType_1.LocatorType.Css,
selector,
return new CssLocator_1.CssLocator(selector, {
relative,
};
source: {
_id: 'byInputType',
type,
relative,
},
});
}
exports.byInputType = byInputType;
//# sourceMappingURL=byInputType.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byName(value: string, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByNameSource = {
_id: 'byName';
value: string;
relative: LocatorRelativePosition;
};
export declare function byName(value: string, relative?: LocatorRelativePosition): CssLocator;

@@ -5,12 +5,16 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byName(value, relative = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byName(value, relative = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const sanitized = (0, escapeUtil_1.escapeValue)(value);
return {
type: PartLocatorType_1.LocatorType.Css,
selector: `[name="${sanitized}"]`,
return new CssLocator_1.CssLocator(`[name="${sanitized}"]`, {
relative,
};
source: {
_id: 'byName',
value,
relative,
},
});
}
exports.byName = byName;
//# sourceMappingURL=byName.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byRole(value: string, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByRoleSource = {
_id: 'byRole';
value: string;
relative: LocatorRelativePosition;
};
export declare function byRole(value: string, relative?: LocatorRelativePosition): CssLocator;

@@ -5,12 +5,16 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byRole(value, relative = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byRole(value, relative = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const sanitized = (0, escapeUtil_1.escapeValue)(value);
return {
type: PartLocatorType_1.LocatorType.Css,
selector: `[role="${sanitized}"]`,
return new CssLocator_1.CssLocator(`[role="${sanitized}"]`, {
relative,
};
source: {
_id: 'byRole',
value,
relative,
},
});
}
exports.byRole = byRole;
//# sourceMappingURL=byRole.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byTagName(tagName: string, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByTagNameSource = {
_id: 'byTagName';
tagName: string;
relative: LocatorRelativePosition;
};
export declare function byTagName(tagName: string, relative?: LocatorRelativePosition): CssLocator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.byTagName = void 0;
const PartLocatorType_1 = require("./PartLocatorType");
function byTagName(tagName, relative = PartLocatorType_1.LocatorRelativePosition.Descendent) {
return {
type: PartLocatorType_1.LocatorType.Css,
selector: tagName,
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byTagName(tagName, relative = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
return new CssLocator_1.CssLocator(tagName, {
relative,
};
source: {
_id: 'byTagName',
tagName,
relative,
},
});
}
exports.byTagName = byTagName;
//# sourceMappingURL=byTagName.js.map

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

import { LocatorRelativePosition, PartLocatorType } from './PartLocatorType';
export declare function byValue(value: string, relative?: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByValueSource = {
_id: 'byValue';
value: string;
relative: LocatorRelativePosition;
};
export declare function byValue(value: string, relative?: LocatorRelativePosition): CssLocator;

@@ -5,12 +5,16 @@ "use strict";

const escapeUtil_1 = require("../utils/escapeUtil");
const PartLocatorType_1 = require("./PartLocatorType");
function byValue(value, relative = PartLocatorType_1.LocatorRelativePosition.Descendent) {
const CssLocator_1 = require("./CssLocator");
const LocatorRelativePosition_1 = require("./LocatorRelativePosition");
function byValue(value, relative = LocatorRelativePosition_1.LocatorRelativePosition.Descendent) {
const sanitized = (0, escapeUtil_1.escapeValue)(value);
return {
type: PartLocatorType_1.LocatorType.Css,
selector: `[value="${sanitized}"]`,
return new CssLocator_1.CssLocator(`[value="${sanitized}"]`, {
relative,
};
source: {
_id: 'byValue',
value,
relative,
},
});
}
exports.byValue = byValue;
//# sourceMappingURL=byValue.js.map

@@ -0,4 +1,10 @@

export { CssLocator } from './CssLocator';
export { LocatorRelativePosition } from './LocatorRelativePosition';
export { LocatorTypeLookup } from './LocatorType';
export type { LocatorType } from './LocatorType';
export type { PartLocator } from './PartLocator';
export { byAttribute } from './byAttribute';
export { byChecked } from './byChecked';
export { byCssClass } from './byCssClass';
export { byCssSelector } from './byCssSelector';
export { byDataTestId } from './byDataTestId';

@@ -10,4 +16,1 @@ export { byInputType } from './byInputType';

export { byValue } from './byValue';
export type { LocatorChain } from './LocatorChain';
export type { CssLocator, PartLocatorType } from './PartLocatorType';
export { LocatorRelativePosition, LocatorType } from './PartLocatorType';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocatorType = exports.LocatorRelativePosition = exports.byValue = exports.byTagName = exports.byRole = exports.byName = exports.byInputType = exports.byDataTestId = exports.byCssClass = exports.byChecked = exports.byAttribute = void 0;
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;
var CssLocator_1 = require("./CssLocator");
Object.defineProperty(exports, "CssLocator", { enumerable: true, get: function () { return CssLocator_1.CssLocator; } });
var LocatorRelativePosition_1 = require("./LocatorRelativePosition");
Object.defineProperty(exports, "LocatorRelativePosition", { enumerable: true, get: function () { return LocatorRelativePosition_1.LocatorRelativePosition; } });
var LocatorType_1 = require("./LocatorType");
Object.defineProperty(exports, "LocatorTypeLookup", { enumerable: true, get: function () { return LocatorType_1.LocatorTypeLookup; } });
var byAttribute_1 = require("./byAttribute");

@@ -10,2 +16,4 @@ Object.defineProperty(exports, "byAttribute", { enumerable: true, get: function () { return byAttribute_1.byAttribute; } });

Object.defineProperty(exports, "byCssClass", { enumerable: true, get: function () { return byCssClass_1.byCssClass; } });
var byCssSelector_1 = require("./byCssSelector");
Object.defineProperty(exports, "byCssSelector", { enumerable: true, get: function () { return byCssSelector_1.byCssSelector; } });
var byDataTestId_1 = require("./byDataTestId");

@@ -23,5 +31,2 @@ Object.defineProperty(exports, "byDataTestId", { enumerable: true, get: function () { return byDataTestId_1.byDataTestId; } });

Object.defineProperty(exports, "byValue", { enumerable: true, get: function () { return byValue_1.byValue; } });
var PartLocatorType_1 = require("./PartLocatorType");
Object.defineProperty(exports, "LocatorRelativePosition", { enumerable: true, get: function () { return PartLocatorType_1.LocatorRelativePosition; } });
Object.defineProperty(exports, "LocatorType", { enumerable: true, get: function () { return PartLocatorType_1.LocatorType; } });
//# sourceMappingURL=index.js.map

@@ -6,6 +6,5 @@ import { Optional } from './dataTypes';

import { Interactor } from './interactor';
import { LocatorChain } from './locators/LocatorChain';
import { PartLocatorType } from './locators/PartLocatorType';
import { PartLocator } from './locators/PartLocator';
export type PartName<T extends ScenePart> = keyof T;
export type ComponentDriverClass<T extends ComponentDriver<P>, P extends ScenePart = {}> = new (locator: LocatorChain, interactor: Interactor, option?: Partial<IComponentDriverOption<P>>) => T;
export type ComponentDriverClass<T extends ComponentDriver<P>, P extends ScenePart = {}> = new (locator: PartLocator, interactor: Interactor, option?: Partial<IComponentDriverOption<P>>) => T;
export interface ComponentPartDefinition<T extends ScenePart> {

@@ -15,3 +14,3 @@ /**

*/
locator?: PartLocatorType;
locator: PartLocator;
/**

@@ -30,7 +29,7 @@ * The class of driver which is used to interact with the element

*/
locator?: PartLocatorType;
locator: PartLocator;
/**
* The class of driver which is used to interact with the element
*/
driver: typeof ContainerDriver<ContentT, T> | (new (locator: LocatorChain, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>) => ContainerDriver<ContentT, T>);
driver: typeof ContainerDriver<ContentT, T> | (new (locator: PartLocator, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>) => ContainerDriver<ContentT, T>);
/**

@@ -64,3 +63,3 @@ * Option for the driver

*/
readonly locator: LocatorChain;
readonly locator: PartLocator;
/**

@@ -67,0 +66,0 @@ * Get the combined text content of the component

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

import { IComponentDriverOption, Interactor, LocatorChain } from '@atomic-testing/core';
import { IComponentDriverOption, Interactor, PartLocator } from '@atomic-testing/core';
import { ComponentDriver } from './drivers/ComponentDriver';

@@ -7,5 +7,5 @@ import { ScenePart } from './partTypes';

private readonly _cleanUp;
constructor(locator: LocatorChain, interactor: Interactor, option?: IComponentDriverOption<T>, cleanUp?: () => Promise<void>);
constructor(locator: PartLocator, interactor: Interactor, option?: IComponentDriverOption<T>, cleanUp?: () => Promise<void>);
cleanUp(): Promise<void>;
get driverName(): string;
}

@@ -1,8 +0,9 @@

import type { LocatorChain } from '../locators/LocatorChain';
import { LocatorRelativePosition, PartLocatorType } from '../locators/PartLocatorType';
export declare function append(locatorBase: Readonly<LocatorChain> | Readonly<PartLocatorType>, ...locatorsToAppend: (PartLocatorType | Readonly<LocatorChain>)[]): LocatorChain;
export declare function findRootLocatorIndex(locator: LocatorChain): number;
export declare function getEffectiveLocator(locator: LocatorChain): LocatorChain;
export declare function toCssSelector(locator: LocatorChain): string;
export declare function getLocatorStatement(locator: PartLocatorType): string;
export declare function overrideLocatorRelativePosition(locator: PartLocatorType, relative: LocatorRelativePosition): PartLocatorType;
import { CssLocator } from '../locators/CssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';
import { PartLocator } from '../locators/PartLocator';
export declare function append(locatorBase: PartLocator, ...locatorsToAppend: PartLocator[]): PartLocator;
export declare function findRootLocatorIndex(locator: PartLocator): number;
export declare function getEffectiveLocator(locator: PartLocator): CssLocator[];
export declare function toCssSelector(locator: PartLocator): string;
export declare function getLocatorStatement(locator: CssLocator): string;
export declare function overrideLocatorRelativePosition(locator: PartLocator, relative: LocatorRelativePosition): PartLocator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.overrideLocatorRelativePosition = exports.getLocatorStatement = exports.toCssSelector = exports.getEffectiveLocator = exports.findRootLocatorIndex = exports.append = void 0;
const PartLocatorType_1 = require("../locators/PartLocatorType");
const LocatorRelativePosition_1 = require("../locators/LocatorRelativePosition");
function append(locatorBase, ...locatorsToAppend) {

@@ -14,10 +14,8 @@ const baseLocator = Array.isArray(locatorBase) ? locatorBase : [locatorBase];

function findRootLocatorIndex(locator) {
const length = locator.length;
const list = Array.isArray(locator) ? locator : [locator];
const length = list.length;
for (let i = length - 1; i >= 0; i--) {
const loc = locator[i];
if (typeof loc === 'object') {
const l = loc;
if (l.relative === PartLocatorType_1.LocatorRelativePosition.Root) {
return i;
}
const loc = list[i];
if (loc.relative === LocatorRelativePosition_1.LocatorRelativePosition.Root) {
return i;
}

@@ -29,4 +27,5 @@ }

function getEffectiveLocator(locator) {
const rootLocatorIndex = findRootLocatorIndex(locator);
return rootLocatorIndex === -1 ? locator : locator.slice(rootLocatorIndex);
const list = Array.isArray(locator) ? locator : [locator];
const rootLocatorIndex = findRootLocatorIndex(list);
return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);
}

@@ -41,3 +40,3 @@ exports.getEffectiveLocator = getEffectiveLocator;

const l = loc;
if (l.relative === PartLocatorType_1.LocatorRelativePosition.Same) {
if (l.relative === LocatorRelativePosition_1.LocatorRelativePosition.Same) {
separator = '';

@@ -52,24 +51,16 @@ }

function getLocatorStatement(locator) {
let statement = '';
if (typeof locator === 'string') {
statement = locator;
}
else {
const l = locator;
statement = l.selector;
}
return statement;
return locator.selector;
}
exports.getLocatorStatement = getLocatorStatement;
function overrideLocatorRelativePosition(locator, relative) {
if (typeof locator === 'string') {
return {
type: PartLocatorType_1.LocatorType.Css,
selector: locator,
if (Array.isArray(locator)) {
return locator.map((loc) => loc.clone({
relative,
};
}));
}
return Object.assign(Object.assign({}, locator), { relative });
return locator.clone({
relative,
});
}
exports.overrideLocatorRelativePosition = overrideLocatorRelativePosition;
//# sourceMappingURL=locatorUtil.js.map
{
"name": "@atomic-testing/core",
"version": "0.27.0",
"version": "0.28.0",
"description": "Core library for atomic-testing",

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

@@ -5,3 +5,3 @@ import { Optional } from '../dataTypes';

import { Interactor } from '../interactor';
import { LocatorChain, LocatorRelativePosition } from '../locators';
import { LocatorRelativePosition, PartLocator } from '../locators';
import { IComponentDriver, IComponentDriverOption, PartName, ScenePart, ScenePartDriver } from '../partTypes';

@@ -13,3 +13,3 @@ import * as timingUtil from '../utils/timingUtil';

export abstract class ComponentDriver<T extends ScenePart = {}> implements IComponentDriver<T> {
private _locator: LocatorChain;
private _locator: PartLocator;
private readonly _parts: ScenePartDriver<T>;

@@ -26,3 +26,3 @@

constructor(
locator: LocatorChain,
locator: PartLocator,
public readonly interactor: Interactor,

@@ -44,7 +44,7 @@ option?: Partial<IComponentDriverOption<T>>,

* When the component is rendered outside the parent's DOM, which usually happens when the component is a modal or popup,
* supply the LocatorChain on how to locate the component with the component's own locator.
* supply the PartLocator on how to locate the component with the component's own locator.
*
* Caution of usage: this function is called before the construction of the driver, so it should not use any instance properties
*/
overriddenParentLocator(): Optional<LocatorChain> {
overriddenParentLocator(): Optional<PartLocator> {
return undefined;

@@ -78,3 +78,3 @@ }

*/
get locator(): LocatorChain {
get locator(): PartLocator {
return this._locator;

@@ -81,0 +81,0 @@ }

import { Interactor } from '../interactor';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { IComponentDriver, IContainerDriverOption, ScenePart, ScenePartDriver } from '../partTypes';

@@ -13,3 +13,3 @@ import { ComponentDriver } from './ComponentDriver';

constructor(locator: LocatorChain, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>) {
constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IContainerDriverOption<ContentT, T>>) {
super(locator, interactor, option);

@@ -16,0 +16,0 @@ const contentOption = {

@@ -1,4 +0,3 @@

import { locatorUtil, PartLocatorType } from '..';
import { locatorUtil, PartLocator } from '..';
import { Interactor } from '../interactor';
import { LocatorChain } from '../locators';
import { IComponentDriverOption, ScenePart, ScenePartDriver } from '../partTypes';

@@ -8,3 +7,3 @@

partDefinition: T,
parentLocator: LocatorChain,
parentLocator: PartLocator,
interactor: Interactor,

@@ -16,3 +15,3 @@ option: Partial<IComponentDriverOption<T>>,

for (const [nestedComponentName, scenePart2] of Object.entries(partDefinition)) {
const { locator = nestedComponentName as string, driver, option: optionOverride } = scenePart2;
const { locator, driver, option: optionOverride } = scenePart2;

@@ -25,4 +24,4 @@ const componentOption: Partial<IComponentDriverOption> = {

const locatorContext: LocatorChain = driver.prototype.overriddenParentLocator() ?? parentLocator;
const actualLocator: PartLocatorType =
const locatorContext: PartLocator = driver.prototype.overriddenParentLocator() ?? parentLocator;
const actualLocator: PartLocator =
driver.prototype.overrideLocatorRelativePosition() != null

@@ -29,0 +28,0 @@ ? locatorUtil.overrideLocatorRelativePosition(locator, driver.prototype.overrideLocatorRelativePosition()!)

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

import { CssLocator, LocatorChain, LocatorRelativePosition, LocatorType, PartLocatorType } from '../locators';
import { byCssSelector, CssLocator, LocatorRelativePosition, PartLocator } from '../locators';
import { ComponentDriverClass } from '../partTypes';

@@ -17,11 +17,7 @@ import { append } from '../utils/locatorUtil';

host: ComponentDriver<any>,
itemLocatorBase: LocatorChain | PartLocatorType,
itemLocatorBase: PartLocator,
index: number,
driverClass: ComponentDriverClass<T>,
): Promise<T | null> {
const nthLocator: CssLocator = {
type: LocatorType.Css,
selector: `:nth-of-type(${index + 1})`,
relative: LocatorRelativePosition.Same,
};
const nthLocator: CssLocator = byCssSelector(`:nth-of-type(${index + 1})`, LocatorRelativePosition.Same);
const itemLocator = append(itemLocatorBase, nthLocator);

@@ -44,3 +40,3 @@ const exists = await host.interactor.exists(itemLocator);

host: ComponentDriver<any>,
itemLocatorBase: LocatorChain | PartLocatorType,
itemLocatorBase: PartLocator | PartLocator,
driverClass: ComponentDriverClass<T>,

@@ -47,0 +43,0 @@ ): AsyncGenerator<T, void, unknown> {

import { ComponentDriver } from '../drivers/ComponentDriver';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { toCssSelector } from '../utils/locatorUtil';

@@ -8,3 +8,3 @@ import { ErrorBase } from './ErrorBase';

function getErrorMessage(locator: LocatorChain): string {
function getErrorMessage(locator: PartLocator): string {
const cssLocator = toCssSelector(locator);

@@ -15,3 +15,3 @@ return `Item not found. Locator: ${cssLocator}`;

export class ItemNotFoundError extends ErrorBase {
constructor(public readonly locator: LocatorChain, public readonly driver: ComponentDriver<any>) {
constructor(public readonly locator: PartLocator, public readonly driver: ComponentDriver<any>) {
super(getErrorMessage(locator), driver);

@@ -18,0 +18,0 @@ this.name = ItemNotFoundErrorId;

import { ComponentDriver } from '../drivers/ComponentDriver';
import { PartLocatorType } from '../locators/PartLocatorType';
import { PartLocator } from '../locators/PartLocator';
import { ErrorBase } from './ErrorBase';

@@ -8,3 +8,3 @@

export class TooManyMatchingElementError extends ErrorBase {
constructor(public readonly query: PartLocatorType, public readonly driver: ComponentDriver<any>) {
constructor(public readonly query: PartLocator, public readonly driver: ComponentDriver<any>) {
super('Too many matching element', driver);

@@ -11,0 +11,0 @@ this.name = TooManyMatchingElementErrorId;

import { ComponentDriver } from '../drivers/ComponentDriver';
import { WaitForOption } from '../drivers/WaitForOption';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { toCssSelector } from '../utils/locatorUtil';

@@ -9,3 +9,3 @@ import { ErrorBase } from './ErrorBase';

function getErrorMessage(locator: LocatorChain, option: WaitForOption): string {
function getErrorMessage(locator: PartLocator, option: WaitForOption): string {
const cssLocator = toCssSelector(locator);

@@ -17,3 +17,3 @@ return `Wait for element to be ${option.condition} failed after ${option.timeoutMs}ms: ${cssLocator}`;

constructor(
public readonly locator: LocatorChain,
public readonly locator: PartLocator,
option: WaitForOption,

@@ -20,0 +20,0 @@ public readonly driver: ComponentDriver<any>,

import { Optional } from '../dataTypes';
import { LocatorChain } from '../locators';
import { PartLocator } from '../locators';
import { ClickOption } from './ClickOption';

@@ -14,3 +14,3 @@ import type { CssProperty } from './CssProperty';

*/
click(locator: LocatorChain, option?: Partial<ClickOption>): Promise<void>;
click(locator: PartLocator, option?: Partial<ClickOption>): Promise<void>;

@@ -22,3 +22,3 @@ /**

*/
enterText(locator: LocatorChain, text: string, option?: Partial<EnterTextOption>): Promise<void>;
enterText(locator: PartLocator, text: string, option?: Partial<EnterTextOption>): Promise<void>;

@@ -30,3 +30,3 @@ /**

*/
selectOptionValue(locator: LocatorChain, values: string[]): Promise<void>;
selectOptionValue(locator: PartLocator, values: string[]): Promise<void>;

@@ -37,3 +37,3 @@ /**

*/
hover(locator: LocatorChain): Promise<void>;
hover(locator: PartLocator): Promise<void>;

@@ -48,3 +48,3 @@ /**

//#region Read only interactions
getInputValue(locator: LocatorChain): Promise<Optional<string>>;
getInputValue(locator: PartLocator): Promise<Optional<string>>;
/**

@@ -54,3 +54,3 @@ * Get the select element's selected options' values

*/
getSelectValues(locator: LocatorChain): Promise<Optional<readonly string[]>>;
getSelectValues(locator: PartLocator): Promise<Optional<readonly string[]>>;
/**

@@ -60,7 +60,7 @@ * Get the select element's selected options' labels

*/
getSelectLabels(locator: LocatorChain): Promise<Optional<readonly string[]>>;
getSelectLabels(locator: PartLocator): Promise<Optional<readonly string[]>>;
getAttribute(locator: LocatorChain, name: string, isMultiple: true): Promise<readonly string[]>;
getAttribute(locator: LocatorChain, name: string, isMultiple: false): Promise<Optional<string>>;
getAttribute(locator: LocatorChain, name: string): Promise<Optional<string>>;
getAttribute(locator: PartLocator, name: string, isMultiple: true): Promise<readonly string[]>;
getAttribute(locator: PartLocator, name: string, isMultiple: false): Promise<Optional<string>>;
getAttribute(locator: PartLocator, name: string): Promise<Optional<string>>;

@@ -72,13 +72,13 @@ /**

*/
getStyleValue(locator: LocatorChain, propertyName: CssProperty): Promise<Optional<string>>;
getStyleValue(locator: PartLocator, propertyName: CssProperty): Promise<Optional<string>>;
getText(locator: LocatorChain): Promise<Optional<string>>;
exists(locator: LocatorChain): Promise<boolean>;
isChecked(locator: LocatorChain): Promise<boolean>;
isDisabled(locator: LocatorChain): Promise<boolean>;
isReadonly(locator: LocatorChain): Promise<boolean>;
isVisible(locator: LocatorChain): Promise<boolean>;
getText(locator: PartLocator): Promise<Optional<string>>;
exists(locator: PartLocator): Promise<boolean>;
isChecked(locator: PartLocator): Promise<boolean>;
isDisabled(locator: PartLocator): Promise<boolean>;
isReadonly(locator: PartLocator): Promise<boolean>;
isVisible(locator: PartLocator): Promise<boolean>;
hasCssClass(locator: LocatorChain, className: string): Promise<boolean>;
hasAttribute(locator: LocatorChain, name: string): Promise<boolean>;
hasCssClass(locator: PartLocator, className: string): Promise<boolean>;
hasAttribute(locator: PartLocator, name: string): Promise<boolean>;
//#endregion

@@ -85,0 +85,0 @@

import { escapeName, escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByAttributeSource = {
_id: 'byAttribute';
name: string;
value: string;
relativeTo: LocatorRelativePosition;
};
export function byAttribute(

@@ -8,10 +16,13 @@ name: string,

relativeTo: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const selector = `[${escapeName(name)}="${escapeValue(value)}"]`;
return {
type: LocatorType.Css,
selector,
return new CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byAttribute',
name,
value,
relativeTo,
},
});
}

@@ -1,10 +0,14 @@

// TODO: Use descriptive selector instead of css selector so the selector can be reintepreted
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
export type ByCheckedSource = {
_id: 'byChecked';
checked: boolean;
relative: LocatorRelativePosition;
};
// to implementation other than CSS selector
export function byChecked(
checked = true,
relative: LocatorRelativePosition = LocatorRelativePosition.Same,
): PartLocatorType {
): CssLocator {
let selector = ':checked';

@@ -14,7 +18,10 @@ if (!checked) {

}
return {
type: LocatorType.Css,
selector,
return new CssLocator(selector, {
relative,
};
source: {
_id: 'byChecked',
checked,
relative,
},
});
}
import { escapeCssClassName } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByCssClassSource = {
_id: 'byCssClass';
className: string | string[];
relative: LocatorRelativePosition;
};
export function byCssClass(
className: string | string[],
relativeTo: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const classNames = Array.isArray(className) ? className : [className];
const selector = classNames.map((cls) => `.${escapeCssClassName(cls)}`).join('');
return {
type: LocatorType.Css,
selector,
return new CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byCssClass',
className,
relative: relativeTo,
},
});
}
import { escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByDataTestIdSource = {
_id: 'byDataTestId';
id: string | string[];
relative: LocatorRelativePosition;
};
export function byDataTestId(
id: string | string[],
relativeTo: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const ids = Array.isArray(id) ? id : [id];
const selector = ids.map((idVal) => `[data-testid="${escapeValue(idVal)}"]`).join(' ');
return {
type: LocatorType.Css,
selector,
return new CssLocator(selector, {
relative: relativeTo,
};
source: {
_id: 'byDataTestId',
id,
relative: relativeTo,
},
});
}
// TODO: Use descriptive selector instead of css selector so the selector can be reintepreted
import { escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByInputTypeSource = {
_id: 'byInputType';
type: string;
relative: LocatorRelativePosition;
};
// to implementation other than CSS selector

@@ -10,9 +17,12 @@ export function byInputType(

relative: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const selector = `input[type=${escapeValue(type)}]`;
return {
type: LocatorType.Css,
selector,
return new CssLocator(selector, {
relative,
};
source: {
_id: 'byInputType',
type,
relative,
},
});
}
import { escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByNameSource = {
_id: 'byName';
value: string;
relative: LocatorRelativePosition;
};
export function byName(
value: string,
relative: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const sanitized = escapeValue(value);
return {
type: LocatorType.Css,
selector: `[name="${sanitized}"]`,
return new CssLocator(`[name="${sanitized}"]`, {
relative,
};
source: {
_id: 'byName',
value,
relative,
},
});
}
import { escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByRoleSource = {
_id: 'byRole';
value: string;
relative: LocatorRelativePosition;
};
export function byRole(
value: string,
relative: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const sanitized = escapeValue(value);
return {
type: LocatorType.Css,
selector: `[role="${sanitized}"]`,
return new CssLocator(`[role="${sanitized}"]`, {
relative,
};
source: {
_id: 'byRole',
value,
relative,
},
});
}

@@ -1,12 +0,22 @@

import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByTagNameSource = {
_id: 'byTagName';
tagName: string;
relative: LocatorRelativePosition;
};
export function byTagName(
tagName: string,
relative: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
return {
type: LocatorType.Css,
selector: tagName,
): CssLocator {
return new CssLocator(tagName, {
relative,
};
source: {
_id: 'byTagName',
tagName,
relative,
},
});
}
import { escapeValue } from '../utils/escapeUtil';
import { LocatorRelativePosition, LocatorType, PartLocatorType } from './PartLocatorType';
import { CssLocator } from './CssLocator';
import { LocatorRelativePosition } from './LocatorRelativePosition';
export type ByValueSource = {
_id: 'byValue';
value: string;
relative: LocatorRelativePosition;
};
export function byValue(
value: string,
relative: LocatorRelativePosition = LocatorRelativePosition.Descendent,
): PartLocatorType {
): CssLocator {
const sanitized = escapeValue(value);
return {
type: LocatorType.Css,
selector: `[value="${sanitized}"]`,
return new CssLocator(`[value="${sanitized}"]`, {
relative,
};
source: {
_id: 'byValue',
value,
relative,
},
});
}

@@ -0,4 +1,10 @@

export { CssLocator } from './CssLocator';
export { LocatorRelativePosition } from './LocatorRelativePosition';
export { LocatorTypeLookup } from './LocatorType';
export type { LocatorType } from './LocatorType';
export type { PartLocator } from './PartLocator';
export { byAttribute } from './byAttribute';
export { byChecked } from './byChecked';
export { byCssClass } from './byCssClass';
export { byCssSelector } from './byCssSelector';
export { byDataTestId } from './byDataTestId';

@@ -10,4 +16,1 @@ export { byInputType } from './byInputType';

export { byValue } from './byValue';
export type { LocatorChain } from './LocatorChain';
export type { CssLocator, PartLocatorType } from './PartLocatorType';
export { LocatorRelativePosition, LocatorType } from './PartLocatorType';

@@ -6,4 +6,3 @@ import { Optional } from './dataTypes';

import { Interactor } from './interactor';
import { LocatorChain } from './locators/LocatorChain';
import { PartLocatorType } from './locators/PartLocatorType';
import { PartLocator } from './locators/PartLocator';

@@ -13,3 +12,3 @@ export type PartName<T extends ScenePart> = keyof T;

export type ComponentDriverClass<T extends ComponentDriver<P>, P extends ScenePart = {}> = new (
locator: LocatorChain,
locator: PartLocator,
interactor: Interactor,

@@ -23,3 +22,3 @@ option?: Partial<IComponentDriverOption<P>>,

*/
locator?: PartLocatorType;
locator: PartLocator;

@@ -41,3 +40,3 @@ /**

*/
locator?: PartLocatorType;
locator: PartLocator;

@@ -50,3 +49,3 @@ /**

| (new (
locator: LocatorChain,
locator: PartLocator,
interactor: Interactor,

@@ -91,3 +90,3 @@ option?: Partial<IContainerDriverOption<ContentT, T>>,

*/
readonly locator: LocatorChain;
readonly locator: PartLocator;

@@ -94,0 +93,0 @@ /**

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

import { IComponentDriverOption, Interactor, LocatorChain } from '@atomic-testing/core';
import { IComponentDriverOption, Interactor, PartLocator } from '@atomic-testing/core';

@@ -10,3 +10,3 @@ import { ComponentDriver } from './drivers/ComponentDriver';

constructor(
locator: LocatorChain,
locator: PartLocator,
public readonly interactor: Interactor,

@@ -13,0 +13,0 @@ option?: IComponentDriverOption<T>,

@@ -1,10 +0,8 @@

import type { LocatorChain } from '../locators/LocatorChain';
import { CssLocator, LocatorRelativePosition, LocatorType, PartLocatorType } from '../locators/PartLocatorType';
import { CssLocator } from '../locators/CssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';
import { PartLocator } from '../locators/PartLocator';
export function append(
locatorBase: Readonly<LocatorChain> | Readonly<PartLocatorType>,
...locatorsToAppend: (PartLocatorType | Readonly<LocatorChain>)[]
): LocatorChain {
const baseLocator: LocatorChain = Array.isArray(locatorBase) ? locatorBase : [locatorBase];
const toAppend: PartLocatorType[] = locatorsToAppend.reduce((acc: PartLocatorType[], locator) => {
export function append(locatorBase: PartLocator, ...locatorsToAppend: PartLocator[]): PartLocator {
const baseLocator: CssLocator[] = Array.isArray(locatorBase) ? locatorBase : [locatorBase];
const toAppend: CssLocator[] = locatorsToAppend.reduce((acc: CssLocator[], locator) => {
return acc.concat(locator);

@@ -16,11 +14,9 @@ }, []);

export function findRootLocatorIndex(locator: LocatorChain): number {
const length = locator.length;
export function findRootLocatorIndex(locator: PartLocator): number {
const list = Array.isArray(locator) ? locator : [locator];
const length = list.length;
for (let i = length - 1; i >= 0; i--) {
const loc = locator[i];
if (typeof loc === 'object') {
const l = loc as CssLocator;
if (l.relative === LocatorRelativePosition.Root) {
return i;
}
const loc = list[i];
if (loc.relative === LocatorRelativePosition.Root) {
return i;
}

@@ -32,8 +28,9 @@ }

export function getEffectiveLocator(locator: LocatorChain): LocatorChain {
const rootLocatorIndex = findRootLocatorIndex(locator);
return rootLocatorIndex === -1 ? locator : locator.slice(rootLocatorIndex);
export function getEffectiveLocator(locator: PartLocator): CssLocator[] {
const list = Array.isArray(locator) ? locator : [locator];
const rootLocatorIndex = findRootLocatorIndex(list);
return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);
}
export function toCssSelector(locator: LocatorChain): string {
export function toCssSelector(locator: PartLocator): string {
const effectiveLocator = getEffectiveLocator(locator);

@@ -56,30 +53,17 @@ const statements = effectiveLocator.map((loc) => {

export function getLocatorStatement(locator: PartLocatorType): string {
let statement = '';
if (typeof locator === 'string') {
statement = locator;
} else {
const l = locator as CssLocator;
statement = l.selector;
}
return statement;
export function getLocatorStatement(locator: CssLocator): string {
return locator.selector;
}
export function overrideLocatorRelativePosition(
locator: PartLocatorType,
relative: LocatorRelativePosition,
): PartLocatorType {
if (typeof locator === 'string') {
return {
type: LocatorType.Css,
selector: locator,
relative,
};
export function overrideLocatorRelativePosition(locator: PartLocator, relative: LocatorRelativePosition): PartLocator {
if (Array.isArray(locator)) {
return (locator as readonly CssLocator[]).map((loc) =>
loc.clone({
relative,
}),
);
}
return {
...locator,
return (locator as CssLocator).clone({
relative,
};
});
}

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

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

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

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