Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1285: more options for locator editing #1573

Merged
merged 32 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
351dfe1
docs: update version
Iogsotot Nov 10, 2023
46bea50
feat: add getElementAttributes fn for content scripts
Iogsotot Nov 15, 2023
f14fa5d
feat: collect attributes for locator element in Content Scripts
Iogsotot Nov 15, 2023
e2436ab
refactor: fix naming in checkDuplicates fn
Iogsotot Nov 15, 2023
5001f35
fix: update tests
Iogsotot Nov 15, 2023
a7d2c7c
feat: add more node attributes into LocatorEditDialog Select options
Iogsotot Nov 17, 2023
75e483b
feat: add styles and tooltip for Locator Type Options
Iogsotot Nov 17, 2023
3d19752
feat: add a-z sort for Locator Type Options
Iogsotot Nov 17, 2023
69a72c3
feat: update interfaces for LocatorType & ElementAttributes
Iogsotot Nov 24, 2023
392ec12
feat: add new logic for work with new element attributes - add getLoc…
Iogsotot Nov 24, 2023
8b3e811
fix: update locator's tests and mock
Iogsotot Nov 24, 2023
0f51418
refactor: common styles for locator, update styles for xpath
Iogsotot Nov 24, 2023
5c21329
refactor: fix class naming for DialogWithForm
Iogsotot Nov 27, 2023
ff4a995
refactor: change console.log to warn
Iogsotot Nov 27, 2023
7327569
fix: Locator types
Iogsotot Nov 27, 2023
f03d1ea
feat: add evaluate fn for attributes (evaluateStandardLocator) instea…
Iogsotot Nov 28, 2023
575d7ae
feat: update logic for using StandardLocator instead of CssSelector; …
Iogsotot Nov 28, 2023
bdf8fa9
feat: update logic to get locator type in PageObj Setting Selector
Iogsotot Nov 28, 2023
b3e47cd
feat: update locator validation logic; fix naming
Iogsotot Nov 28, 2023
9d1920d
refactor: add async for Connector's methods
Iogsotot Nov 28, 2023
3b4f37f
fix: output locator string and locator type logic
Iogsotot Nov 28, 2023
8dfade2
fix: update dependencies for rc-filed-form
Iogsotot Nov 28, 2023
1ed8002
fix: output for CSS Selector in locator edit dialog
Iogsotot Nov 28, 2023
9007f02
fix: styles for locators dropdown
Iogsotot Nov 28, 2023
28ebf80
fix: replace replace evaluateCssSelector with evaluateStandardLocato…
Iogsotot Nov 28, 2023
c270e1b
fix: tests by type casts
Iogsotot Nov 28, 2023
f61e443
fix: UI output for CSS Selector
Iogsotot Nov 29, 2023
2de0c0f
feat: update dependencies and types for Form value
Iogsotot Nov 29, 2023
69484df
fix: add prefix for className Locator type
Iogsotot Nov 29, 2023
18bc2ed
fix: change logic for linkText. className in evaluateStandardLocator fn
Iogsotot Nov 29, 2023
6559888
refactor: code clean up
Iogsotot Nov 29, 2023
e6968b4
fix: types for build tests
Iogsotot Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add getElementAttributes fn for content scripts
  • Loading branch information
Iogsotot committed Nov 15, 2023
commit 46bea509d05ba195500bfa07c7bc6d9f9d5e3c79
54 changes: 54 additions & 0 deletions src/pageServices/contentScripts/utils.ts
Original file line number Diff line number Diff line change
@@ -78,3 +78,57 @@ export const sendMessage = (msg: { message: ScriptMsg; param: any }) =>
chrome.runtime.sendMessage(msg).catch((error) => {
if (error.message !== 'The message port closed before a response was received.') throw new Error(error.message);
});

export interface ElementAttributes {
id?: string | null;
name?: string | null;
tagName?: string | null;
className?: string | null;
linkText?: string | null;
partialLinkText?: string | null;
dataAttributes?: { [key: string]: string | null } | null;
}

export const getElementAttributes = (element: HTMLElement): ElementAttributes => {
let attributes: ElementAttributes = {};

if (element.id) {
attributes.id = element.id;
}
// ignore for name attribute:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (element.name) {
attributes.name = element.getAttribute('name') ?? null;
}

if (element.innerText) {
// attributes.linkText = element.innerText; // не включает скрытый текст (например, скрытый CSS)
attributes.linkText = element.textContent?.trim(); // возвращает текстовое
// содержимое элемента, включая все его потомки. Оно возвращает все текстовые узлы,
// включая скрытые элементы.
// if (attributes.linkText) { // пока убрать
// attributes.partialLinkText = attributes.linkText.slice(0, Math.floor(attributes.linkText.length / 2));
// }
}

if (element.tagName) {
attributes.tagName = element.tagName.toLowerCase();
}

if (element.className) {
attributes.className = element.className;
}

// Get data attributes
const dataAttributes: { [key: string]: string } = {};
for (let i = 0; i < element.attributes.length; i++) {
const attribute = element.attributes[i];
if (attribute.name.startsWith('data-')) {
dataAttributes[attribute.name.replace('data-', '')] = attribute.value;
}
}
if (!!Object.keys(dataAttributes).length) attributes = { ...attributes, ...dataAttributes };

return attributes;
};