Skip to content

Allow list elements #167

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/build/main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/js/blocks/autoFind/AutoFind.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const AutoFind = ({ classes }) => {
const getAvailableElements = () => {
return allowRemoveElements
? (predictedElements || []).filter(
(e) => e.predicted_probability >= perception
).length
(e) => e.predicted_probability >= perception
).length
: 0;
};

Expand Down
8 changes: 4 additions & 4 deletions src/js/blocks/autoFind/autoFindProvider/AutoFindProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AutoFindProvider = inject("mainModel")(
const [pageElements, setPageElements] = useState(null);
const [predictedElements, setPredictedElements] = useState(null);
const [status, setStatus] = useState(autoFindStatus.noStatus);
const [allowIdetifyElements, setAllowIdetifyElements] = useState(true);
const [allowIdentifyElements, setAllowIdentifyElements] = useState(true);
const [allowRemoveElements, setAllowRemoveElements] = useState(false);
const [perception, setPerception] = useState(0.5);

Expand All @@ -38,7 +38,7 @@ const AutoFindProvider = inject("mainModel")(
};

const identifyElements = () => {
setAllowIdetifyElements(!allowIdetifyElements);
setAllowIdentifyElements(!allowIdentifyElements);
setStatus(autoFindStatus.loading);

const callback = () => {
Expand All @@ -60,7 +60,7 @@ const AutoFindProvider = inject("mainModel")(
};

const removeHighlighs = () => {
setAllowIdetifyElements(!allowIdetifyElements);
setAllowIdentifyElements(!allowIdentifyElements);
const callback = () => {
setStatus(autoFindStatus.removed);
setAllowRemoveElements(!allowRemoveElements);
Expand Down Expand Up @@ -90,7 +90,7 @@ const AutoFindProvider = inject("mainModel")(
pageElements,
predictedElements,
status,
allowIdetifyElements,
allowIdentifyElements,
allowRemoveElements,
perception,
},
Expand Down
2 changes: 1 addition & 1 deletion src/js/json/JavaJDILightTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class {{type}} extends WebPage {
}`,
pageElementCss: ` @UI("{{locator}}") public {{type}} {{name}};`,
pageElementXPath: ` @UI("{{locator}}") public {{type}} {{name}};`,
pageElementComplex: ` @JDropdown({{locators}})
pageElementComplex: ` @J{{type}}({{locators}})
public {{type}} {{name}};`,
locatorCss: `{{type}} = "{{locator}}",`,
locatorXPath: `{{type}} = "{{locator}}",`,
Expand Down
29 changes: 21 additions & 8 deletions src/js/models/ConversionToCodeModel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ const isSection = (type, mainModel) => {
function complexCode(type, locator, name, mainModel) {
const template = mainModel.settingsModel.template;
let complexTemplate = template.pageElementComplex;
complexTemplate = complexTemplate.replace(/({{annotation}})/g, type);
complexTemplate = complexTemplate.replace(/({{type}})/g, type);
complexTemplate = complexTemplate.replace(/({{locators}})/, locator);
complexTemplate = complexTemplate.replace(/({{name}})/, varName(name));

return complexTemplate + "\n";
}

export function simpleCode(locatorType, locator, elType, name, mainModel) {
export function simpleCode(locatorType, locator, elType, name, mainModel, isList) {
const template = mainModel.settingsModel.template;
let templatePath = "";

Expand All @@ -67,7 +68,7 @@ export function simpleCode(locatorType, locator, elType, name, mainModel) {
? template.pageElementCss
: template.pageElementXPath;
templatePath = templatePath.replace(/({{locator}})/, locator);
templatePath = templatePath.replace(/({{type}})/, elType);
templatePath = templatePath.replace(/({{type}})/, isList ? `List<${elType}>` : elType);
templatePath = templatePath.replace(/({{name}})/, varName(name));
}

Expand Down Expand Up @@ -189,39 +190,51 @@ function genCodeOfElements(parentId, arrOfElements, mainModel, isAutoFind) {

if (el.parentId === parentId && (el.Locator || el.Root)) {
if (composites[el.Type] && !isAutoFind) {
result += simpleCode(
const codeRow = simpleCode(
locatorType(el.Locator),
el.Locator,
getClassName(el.Name),
el.Name,
mainModel
mainModel,
el.isList
);
if (!result.includes(codeRow)) {
result += codeRow;
}
}
if (complex[el.Type] && !isAutoFind) {
let fields = getFields(ruleBlockModel.elementFields[el.Type]);
result += isSimple(el, fields)
const codeRow = isSimple(el, fields)
? simpleCode(
locatorType(el.Root),
el.Root,
el.Type,
el.Name,
mainModel
mainModel,
el.isList
)
: complexCode(
el.Type,
complexLocators(el, fields, mainModel),
el.Name,
mainModel
);
if (!result.includes(codeRow)) {
result += codeRow;
}
}
if (simple[el.Type]) {
result += simpleCode(
const codeRow = simpleCode(
locatorType(el.Locator),
el.Locator,
el.Type,
el.Name,
mainModel
mainModel,
el.isList
);
if (!result.includes(codeRow)) {
result += codeRow;
}
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/js/models/GenerateBlockModel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ const applyFoundResult = ({ mainModel }, e, parent, ruleId) => {
parent: e.parent || null,
parentId: e.parentId,
elId: e.elId,
isList: e.isList
};
if (simple.indexOf(e.Type) > -1) {
element.Locator = e.Locator;
Expand Down Expand Up @@ -278,11 +279,11 @@ const applyFoundResult = ({ mainModel }, e, parent, ruleId) => {
}
};

function fillEl({ results, mainModel }, element, type, parent, ruleId) {
function fillEl({ results, mainModel }, element, type, parent, ruleId, isList = false) {
const { ruleBlockModel, generateBlockModel } = mainModel;
const rulesObj = ruleBlockModel.rules;
const composites = Object.keys(rulesObj.CompositeRules);
let result = { ...element, Type: type };
let result = { ...element, Type: type, isList };
if (composites.includes(type)) {
result.parent = null;
result.parentId = null;
Expand Down Expand Up @@ -420,6 +421,18 @@ const defineElements = (
}
fillEl({ results, mainModel }, e, t, parent, ruleId);
} else {
let e = {
Locator: isSimpleRule(t, uniq, mainModel)
? `EMPTY_LOCATOR_${finalLocator}`
: finalLocator,
// Locator: finalLocator,
content: s2.elements[0],
Name: nameElement(finalLocator, uniq, val, s2.elements[0]).slice(
0,
20
),
};
fillEl({ results, mainModel }, e, t, parent, ruleId, true);
generateBlockModel.log.addToLog({
message: `Warning! Too much elements found by locator ${finalLocator}; ${s2.elements.length} elements`,
type: "warning",
Expand Down