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

Code generator #38

Open
wants to merge 5 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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
node_modules/
.tmp/
.dist/
dist/
package.json.lock
.vscode/
.vscode/
*hot-update.js
136 changes: 53 additions & 83 deletions app/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,33 @@ let commonFields = {

let ElementFields = {
"Button": { ...commonFields, "Locator": "TextField" },
"CheckBox": { ...commonFields, "Locator": "TextField" },
"Image": { ...commonFields, "Locator": "TextField" },
"Label": { ...commonFields, "Locator": "TextField" },
"Text": { ...commonFields, "Locator": "TextField" },
"Link": { ...commonFields, "Locator": "TextField" },
"TextField": { ...commonFields, "Locator": "TextField" },
"TextArea": { ...commonFields, "Locator": "TextField" },
"DataPicker": { ...commonFields, "Locator": "TextField" },
"FileInput": { ...commonFields, "Locator": "TextField" },
"Selector": { ...commonFields, "Locator": "TextField" },
"CheckList": { ...commonFields, "Locator": "TextField" },
"Menu": { ...commonFields, "Locator": "TextField" },
"RadioButtons": { ...commonFields, "Locator": "TextField" },
"Tabs": { ...commonFields, "Locator": "TextField" },
"Section": { ...commonFields, "Locator": "TextField", "isSection": "internal", "expanded": "internal", "children": "internal" },
"Form": { ...commonFields, "Locator": "TextField", "isSection": "internal", "Entity": "TextField", "expanded": "internal", "children": "internal" },
"ComboBox": {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField", "Enum": "TextField"
"List": "TextField", "Expand": "TextField"
},
"Dropdown": {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField"
},
"DropList": {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField"
},
"Table": {
...commonFields, "Root": "TextField", "Headers": "TextField", "RowHeaders": "TextField", "Header": "TextField",
Expand All @@ -39,86 +60,34 @@ let ElementFields = {
"HeaderTypes": "ComboBox", "HeaderTypesValues": ["All", "Headers", "No Headers", "Columns Headers", "Rows Headers"]
}
}
//let HeaderTypes = ["All", "Headers", "No Headers", "Columns Headers", "Rows Headers"];

/*let ElementFields = new Map();
ElementFields.set("Button", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Image", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Checkbox", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Label", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Link", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Text", { ...commonFields, "Locator": "TextField" });
ElementFields.set("TextField", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Input", { ...commonFields, "Locator": "TextField" });
ElementFields.set("TextArea", { ...commonFields, "Locator": "TextField" });
ElementFields.set("DataPicker", { ...commonFields, "Locator": "TextField" });
ElementFields.set("FileInput", { ...commonFields, "Locator": "TextField" });
ElementFields.set("Section", { ...commonFields, "Locator": "TextField", "isSection": "internal", "expanded": "internal", "children": "internal" });
ElementFields.set("Form", { ...commonFields, "Locator": "TextField", "isSection": "internal", "Entity": "TextField", "expanded": "internal", "children": "internal" });
ElementFields.set("Selector", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("CheckList", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("Menu", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("RadioButtons", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("Tabs", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("TextList", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("Chat", { ...commonFields, "Locator": "TextField", "Enum": "TextField" });
ElementFields.set("ComboBox", {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField", "Enum": "TextField"
});
ElementFields.set("Logout", {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField", "Enum": "TextField"
});
ElementFields.set("Dropdown", {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField", "Enum": "TextField"
});
ElementFields.set("DropList", {
...commonFields, "Root": "TextField", "Value": "TextField",
"List": "TextField", "Expand": "TextField", "Enum": "TextField"
});
ElementFields.set("Table", {
...commonFields, "Root": "TextField", "Headers": "TextField", "RowHeaders": "TextField", "Header": "TextField",
"RowHeader": "TextField", "Cell": "TextField", "Column": "TextField", "Row": "TextField",
"Footer": "TextField", "Height": "TextField", "Width": "TextField", "RowStartIndex": "TextField", "UseCache": "Checkbox",
"HeaderTypes": "ComboBox"
});
ElementFields.set("DynamicTable", {
...commonFields, "Root": "TextField", "Headers": "TextField", "RowHeaders": "TextField", "Header": "TextField",
"RowHeader": "TextField", "Cell": "TextField", "Column": "TextField", "Row": "TextField",
"Footer": "TextField", "Height": "TextField", "Width": "TextField", "RowStartIndex": "TextField", "UseCache": "Checkbox",
"HeaderTypes": "ComboBox"
});*/

let SimpleRules = {
"Button": [{ Locator: "input[type=submit]", uniqness: "value", id: 0 }, { Locator: "input[type=button]", uniqness: "value", id: 1 },
{ Locator: "button[type=button]", uniqness: "text", id: 2 }, { Locator: "button.btn", uniqness: "text", id: 3 }, { Locator: "a.btn", uniqness: "text", id: 4 },
{ Locator: 'button[type=submit]', uniqness: "text", id: 5 }],
// "Checkbox": [{ Locator: "", id: 0, uniqness: "" }],
// "Image": [{ Locator: "", id: 0, uniqness: "" }],
// "Label": [{ Locator: "", id: 0, uniqness: "" }],
"Link": [{ Locator: "a[href]", uniqness: "text", id: 0 }],
// "Text": [{ Locator: "", id: 0, uniqness: "" }],
// "TextField": [{ Locator: "", id: 0, uniqness: "" }],
// "Input": [{ Locator: "", id: 0, uniqness: "" }],
// "TextArea": [{ Locator: "", id: 0, uniqness: "" }],
// "DataPicker": [{ Locator: "", id: 0, uniqness: "" }],
// "FileInput": [{ Locator: "", id: 0, uniqness: "" }],
// "Selector": [{ Locator: "", id: 0, uniqness: "" }],
// "CheckList": [{ Locator: "", id: 0, uniqness: "" }],
// "Menu": [{ Locator: "", id: 0, uniqness: "" }],
// "RadioButtons": [{ Locator: "", id: 0, uniqness: "" }],
// "Tabs": [{ Locator: "", id: 0, uniqness: "" }],
// "TextList": [{ Locator: "", id: 0, uniqness: "" }],
// "Chat": [{ Locator: "", id: 0, uniqness: "" }]
"Button": [{ "Locator": "button[type=submit]", "uniqness": "text", "id": 0}],
"CheckBox": [{"Locator": "input[type=checkbox]", "id": 0, "uniqness": "id"}],
"Image": [{"Locator": "img", "id": 0, "uniqness": "id"}],
"Label": [{"Locator": "h1", "id": 0, "uniqness": "name"},
{"Locator": "h2", "id": 1, "uniqness": "name"},
{"Locator": "h3", "id": 2, "uniqness": "name"},
{"Locator": "[ui=label]", "id": 3, "uniqness": "text"}
],
"Link": [{"Locator": "", "uniqness": "", id: 0 }],
"Text": [{"Locator": ".main-txt", "id": 0, "uniqness": "name"}],
"TextField": [{"Locator": "input[type=text]", "id": 0, "uniqness": "id"},
{"Locator": "input[type=password]", "id": 1, "uniqness": "id"}
],
"TextArea": [{"Locator": "textarea", "id": 0, "uniqness": "id"}],
"DataPicker": [{"Locator": "", "id": 0, "uniqness": ""}],
"FileInput": [{"Locator": "", "id": 0, "uniqness": ""}],
"Selector": [{"Locator": "", "id": 0, "uniqness": ""}],
"CheckList": [{"Locator": "", "id": 0, "uniqness": ""}],
"Menu": [{"Locator": "", "id": 0, "uniqness": ""}],
"RadioButtons": [{"Locator": "", "id": 0, "uniqness": ""}],
"Tabs": [{"Locator": "", "id": 0, "uniqness": ""}]
};
let ComplexRules = {
"ComboBox": [{ Root: "[jtype=dropdown] button", uniqness: ".filter-option#text", Value: "", List: "li", Expand: ".caret", id: 0 }],
// "Dropdown": [{ Root: "[jtype=combobox] button", uniqness: ".filter-option#text", Value: "", List: "", Expand: "", id: 0 }],
// "DropList": [{ Root: "[jtype=droplist] button", uniqness: "text", Value: "", List: "", Expand: "", id: 0 }],
// "MenuDropdown": [{ Root: ".open [data-toggle]", uniqness: "text", Value: "", List: "", Expand: "", id: 0 }],
// "Logout": [{ Root: ".uui-profile-menu", uniqness: ".profile-photo span#text", Value: "", List: "", Expand: "", id: 0 }],
"Dropdown": [{ Root: "[ui=dropdown]", uniqness: "id", Value: "", List: "li", Expand: ".caret", id: 0 }],
"ComboBox": [{ Root: "[ui=combobox]", uniqness: "id", Value: "", List: "li", Expand: ".caret", id: 0 }],
"DropList": [{ Root: "[ui=droplist]", uniqness: "id", Value: "", List: "li", Expand: ".caret", id: 0 }],
"Table": [{
Root: "table", Header: "", RowHeader: "", Cell: "",
Column: "", Row: "", Footer: "", id: 0, uniqness: 'class'
Expand All @@ -129,12 +98,13 @@ let ComplexRules = {
}]
};
let CompositeRules = {
"Section": [{ Locator: ".section", id: 0, uniqness: 'class'},
{ Locator: "header", id: 1, uniqness: 'tag' },
{ Locator: "//footer", id: 2, uniqness: '[footer]' },
{ Locator: "#sidebar", id: 3, uniqness: 'id'},
{ Locator: "#content", id: 4, uniqness: 'id' }],
"Form": [{ Locator: "form", id: 0, uniqness: 'class' }]
"Section": [{ "Locator": ".section", "id": 0, "uniqness": "class" },
{"Locator": "header", "id": 1, "uniqness": "tag"},
{"Locator": "footer", "id": 2, "uniqness": "tag"},
{"Locator": ".uui-side-bar", "id": 3, "uniqness": "name"},
{"Locator": ".main-form", "id": 4, "uniqness": "tag"}
],
"Form": [{"Locator": "form", "id": 0, "uniqness": "id"}]
}

export { Elements, Locators, ElementFields, SimpleRules, ComplexRules, CompositeRules, commonFields };
25 changes: 20 additions & 5 deletions app/reducers/POgen/genPo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,37 @@ export let genEl = (obj) => {
chrome.devtools.inspectedWindow.eval('document.location', (r, err) => {
page.url = r.pathname;
objCopy.SiteInfo.hostName = r.hostname;
page.title = r.pathname.split("/").pop().replace(/\.html|\.htm/, '');
objCopy.SiteInfo.siteTitle = toName(r.hostname.substring(0,r.hostname.lastIndexOf(".")));
objCopy.SiteInfo.origin = r.origin;
});

chrome.devtools.inspectedWindow.eval('document.domain', (r, err) => {
if (r !== "") {
objCopy.SiteInfo.domainName = r;
objCopy.SiteInfo.domainName = r
objCopy.SiteInfo.pack = r.split('.').reverse().join('.');
}
});

chrome.devtools.inspectedWindow.eval('document.title', (r, err) => {
if (r !== "") {
page.name = r;
page.title = r;
page.name = toName(r);
}
});

function toName(n) {
let name = [];
if (n) {
//[^a-zA-Zа-яёА-ЯЁ0-9]
let arrayName = n.split(/[^a-zA-Zа-яёА-ЯЁ0-9]/);
for (let j = 0; j < arrayName.length; j++) {
if (arrayName[j]) {
name.push(arrayName[j][0].toUpperCase() + arrayName[j].slice(1));
}
}
}
return name.join(" ");
}
chrome.devtools.inspectedWindow.eval(
'document.body.outerHTML', (r, err) => {
if (err) {
Expand Down Expand Up @@ -187,9 +201,10 @@ export let genEl = (obj) => {
}
fillEl(e, t, parent, ruleId);
};
let tooMuchElements = `Too much elements found(${elements.length} for ${uniqness.value}. Locator (${firstSearch.locatorType.locator}))`;
if (elements.length > 1) {
if (uniqness.value === "tag" || uniqness.value === '[')
addToLog(`Too much elements found(${elements.length} for ${uniqness.value}. Locator (${firstSearch.locatorType.locator}))`);
addToLog(tooMuchElements);
for (let i = 0; i < elements.length; i++) {
let val = getValue(elements[i], uniqness, Locator);
let finalLocator = xpath
Expand All @@ -204,7 +219,7 @@ export let genEl = (obj) => {
}
fillEl(e, t, parent, ruleId);
} else {
addToLog(`Too much elements found(${s2.elements.length}. Locator (${finalLocator}))`);
addToLog(tooMuchElements);
}
}
}
Expand Down
Loading