Skip to content

Commit

Permalink
Merge pull request #1442 from jdi-testing/issue_1426
Browse files Browse the repository at this point in the history
issue 1426 import FindBy for pageObjectTemplate
  • Loading branch information
Iogsotot authored Aug 4, 2023
2 parents 5da217a + 83a1ecd commit 8596415
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "JDN",
"description": "JDN – helps Test Automation Engineer to create Page Objects in the test automation framework and speed up test development",
"devtools_page": "index.html",
"version": "3.13.548",
"version": "3.13.549",
"icons": {
"128": "icon128.png"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdn-ai-chrome-extension",
"version": "3.13.548",
"version": "3.13.549",
"description": "jdn-ai chrome extension",
"scripts": {
"start": "webpack --watch --env devenv",
Expand Down
153 changes: 149 additions & 4 deletions src/__tests__/__mocks__/pageObjectMocks/pageObject.mock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
import { AnnotationType } from "../../../common/types/common";

export const getLocatorsByAnnotationType = (value) => {
return [
{
attrId: "",
element_id: "0955274655778840492142094709",
height: 60,
locator: {
fullXpath: "/html/body/header/div/nav/ul[1]",
taskStatus: "SUCCESS",
robulaXpath: "//*[@class='uui-navigation nav navbar-nav m-l8']",
output: "//*[@class='uui-navigation nav navbar-nav m-l8']",
},
annotationType: value,
name: "listUl",
predictedAttrId: "",
predicted_label: "list",
predicted_probability: 1,
sort_key: 25223.1262207031,
tagName: "ul",
type: "list",
width: 420.3854370117,
x: 222.9375,
y: 0,
},
{
attrId: "",
element_id: "2022378243778840502461724770",
height: 15.3333339691,
locator: {
fullXpath: "/html/body/footer/div/div/ul",
taskStatus: "SUCCESS",
robulaXpath: "//*[@class='footer-menu']",
output: "//*[@class='footer-menu']",
},
annotationType: AnnotationType.UI,
name: "listUl7",
predictedAttrId: "",
predicted_label: "list",
predicted_probability: 1,
sort_key: 2181.326557325,
tagName: "ul",
type: "list",
width: 142.2604217529,
x: 1037.7396240234,
y: 1972.7917480469,
},
{
attrId: "",
element_id: "2713188863778840498565585241",
height: 38.6666679382,
locator: {
fullXpath: "/html/body/div/div[1]/div/div[1]/div/div[1]/ul/li[1]/a",
output: "/html/body/div/div[1]/div/div[1]/div/div[1]/ul/li[1]/a",
taskStatus: "REVOKED",
},
annotationType: AnnotationType.UI,
name: "badge",
predictedAttrId: "",
predicted_label: "badge",
predicted_probability: 0.74,
sort_key: 7733.3335876465,
tagName: "a",
type: "badge",
width: 200,
x: 0,
y: 60,
},
];
};

export const locators = [
{
attrId: "",
Expand Down Expand Up @@ -68,6 +138,74 @@ export const locators = [
},
];

export const locatorsWithFindBy = [
{
attrId: "",
element_id: "0955274655778840492142094709",
height: 60,
locator: {
fullXpath: "/html/body/header/div/nav/ul[1]",
taskStatus: "SUCCESS",
robulaXpath: "//*[@class='uui-navigation nav navbar-nav m-l8']",
output: "//*[@class='uui-navigation nav navbar-nav m-l8']",
},
annotationType: AnnotationType.FindBy,
name: "listUl",
predictedAttrId: "",
predicted_label: "list",
predicted_probability: 1,
sort_key: 25223.1262207031,
tagName: "ul",
type: "list",
width: 420.3854370117,
x: 222.9375,
y: 0,
},
{
attrId: "",
element_id: "2022378243778840502461724770",
height: 15.3333339691,
locator: {
fullXpath: "/html/body/footer/div/div/ul",
taskStatus: "SUCCESS",
robulaXpath: "//*[@class='footer-menu']",
output: "//*[@class='footer-menu']",
},
annotationType: AnnotationType.UI,
name: "listUl7",
predictedAttrId: "",
predicted_label: "list",
predicted_probability: 1,
sort_key: 2181.326557325,
tagName: "ul",
type: "list",
width: 142.2604217529,
x: 1037.7396240234,
y: 1972.7917480469,
},
{
attrId: "",
element_id: "2713188863778840498565585241",
height: 38.6666679382,
locator: {
fullXpath: "/html/body/div/div[1]/div/div[1]/div/div[1]/ul/li[1]/a",
output: "/html/body/div/div[1]/div/div[1]/div/div[1]/ul/li[1]/a",
taskStatus: "REVOKED",
},
annotationType: AnnotationType.UI,
name: "badge",
predictedAttrId: "",
predicted_label: "badge",
predicted_probability: 0.74,
sort_key: 7733.3335876465,
tagName: "a",
type: "badge",
width: 200,
x: 0,
y: 60,
},
];

export const pageObjectHTML = `package site.pages;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.*;
Expand Down Expand Up @@ -160,19 +298,26 @@ public class HomePage extends WebPage {
}
`;

export const pageObjectCiryllic = `package io.github.jditesting.pages;
export const pageObjectHTMLWithFindBy = `package site.pages;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.*;
import com.epam.jdi.light.elements.composite.*;
import com.epam.jdi.light.ui.html.elements.common.*;
import com.epam.jdi.light.elements.complex.*;
import com.epam.jdi.light.elements.common.*;
import com.epam.jdi.light.elements.complex.dropdown.*;
import com.epam.jdi.light.elements.complex.table.*;
import com.epam.jdi.light.ui.html.elements.complex.*;
import com.epam.jdi.light.ui.html.elements.common.*;
import io.github.jditesting.sections.*;
import com.epam.jdi.light.elements.pageobjects.annotations.FindBy;
public class DomashnyayaStranitsaPage extends WebPage {
public class HomePage extends WebPage {
${AnnotationType.FindBy}(xpath = "//*[@class='uui-navigation nav navbar-nav m-l8']")
public list listUl;
${AnnotationType.UI}("//*[@class='footer-menu']")
public list listUl7;
${AnnotationType.UI}("/html/body/div/div[1]/div/div[1]/div/div[1]/ul/li[1]/a")
public badge badge;
}
`;
21 changes: 19 additions & 2 deletions src/__tests__/pageObject/pageObject.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
locators,
pageObjectHTML,
pageObjectMUI,
pageObjectHTML,
pageObjectVuetify,
pageObjectHTMLWithFindBy,
getLocatorsByAnnotationType,
} from "../__mocks__/pageObjectMocks/pageObject.mock";
import { elementsWithoutNames } from "../__mocks__/pageObjectMocks/elementsWithoutNames";
import { elementsWithNames } from "../__mocks__/pageObjectMocks/elementsWithNames";
Expand All @@ -11,6 +12,7 @@ import { ElementLibrary } from "../../features/locators/types/generationClasses.
import { pageObjectTemplate } from "../../features/pageObjects/utils/pageObjectTemplate";
import { createLocatorNames } from "../../features/pageObjects/utils/pageObject";
import { getClassName } from "../../features/pageObjects/utils/pageObjectTemplate";
import { AnnotationType } from "../../common/types/common";

const templateTestData = [
{
Expand All @@ -27,7 +29,13 @@ const templateTestData = [
},
];

const templateTestDataWithFindBy = {
input: "HTML",
output: pageObjectHTMLWithFindBy,
};

describe("page object code generation", () => {
const locators = getLocatorsByAnnotationType(AnnotationType.UI);
templateTestData.forEach(({ input, output }) => {
test(`page object generated with ${input}`, () => {
const page = pageObjectTemplate(locators, "HomePage", input);
Expand All @@ -41,6 +49,15 @@ describe("page object code generation", () => {
expect(getClassName(poName.input)).toBe(poName.output);
});
});

describe("pageObjectTemplate should return pageObjectHTML with FindBy import", () => {
const locators = getLocatorsByAnnotationType(AnnotationType.FindBy);
test(`when page object generated with ${templateTestDataWithFindBy.input} and locators has Annotation Type === 'FindBy'`, () => {
const page = pageObjectTemplate(locators, "HomePage", templateTestDataWithFindBy.input);
expect(page.pageCode).toBe(templateTestDataWithFindBy.output);
expect(page.title).toBe("HomePage");
});
});
});

describe("create locators names", () => {
Expand Down
5 changes: 5 additions & 0 deletions src/features/pageObjects/utils/hasAnnotationType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Locator } from "../../locators/types/locator.types";

export const hasAnnotationType = (objects: Locator[], annotationType: string): boolean => {
return objects.some((obj) => obj.annotationType === annotationType);
};
7 changes: 5 additions & 2 deletions src/features/pageObjects/utils/pageObjectTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { camelCase, upperFirst } from "lodash";
import transliterate from "@sindresorhus/transliterate";
import { Locator } from "../../locators/types/locator.types";
import { getLocatorPrefix } from "../../locators/utils/locatorOutput";
import { AnnotationType } from "../../../common/types/common";
import { hasAnnotationType } from "./hasAnnotationType";

export const getClassName = (title: string) => {
let className = transliterate(title);
Expand All @@ -26,6 +28,8 @@ export const pageObjectTemplate = (locators: Locator[], title: string, library:
)}"${locatorEscaped}")\n public ${loc.type} ${loc.name};`;
});

const hasFindByAnnotationType: boolean = hasAnnotationType(locators, AnnotationType.FindBy);

const pageCode = `package site.pages;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.*;
Expand Down Expand Up @@ -67,11 +71,10 @@ import com.epam.jdi.light.vuetify.elements.complex.timelines.*;
import com.epam.jdi.light.vuetify.elements.composite.*;
`
: ""
}
}${hasFindByAnnotationType ? `import com.epam.jdi.light.elements.pageobjects.annotations.FindBy;\n` : ""}
public class ${className} extends WebPage {
${locatorsCode.join("\n\n")}
}
`;

return { pageCode, title: className };
};

0 comments on commit 8596415

Please sign in to comment.