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

Make navigation for challenge slick carousel and corresponding test #1995

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions src/test/playwright/PO/ChallengeInfoPage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@

import BasePage from "./BasePage";
import { expect } from "@playwright/test";

class ChallengeInfoPage extends BasePage {
constructor(page) {
super(page);
this.viewChallengeButton = page.getByRole("button", { name: "Переглянути челендж" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const for "Переглянути челендж"

this.viewChallengeTitle = page.locator("span.title");
this.slickCard = page.locator("div.slick-slide");
this.slickCardsNames = page.locator("div.slick-slide div.name");
this.slickDots = page.locator("ul.slick-dots li");
this.slickRightArrow = page.locator("div.challenge-day-block span[aria-label='arrow-right']:nth-child(2) svg");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid locator nth-child(2)
DO not use hardcode.
Please update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$("span.arrows-next svg")

this.challengePageTitle = page.locator("h1.ant-typography");
this.challengeSortNumber = page.locator("input#sortNumber");
this.challengeStatus = page.locator("button#isActive");
Expand All @@ -15,6 +23,37 @@ class ChallengeInfoPage extends BasePage {
this.challengeTasksNames = page.locator("td:nth-child(2)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid locator nth-child(2)
Please update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$("td.ant-table-cell > a.table-name[href*='task']")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$x("//a[contains(text(),'Task_second')]")

}

async openViewChallenge() {
await this.viewChallengeButton.click();
await this.verifyElementVisibility(this.viewChallengeTitle);
}

async verifyTaskOnChallengeView(taskName) {
// Step 1: Verify the existence of the task in the slick carousel
await this.verifyElementExistance(this.slickCardsNames, taskName);

// Step 2: Find the target card based on the provided taskName
const targetCard = await this.slickCard.filter({ hasText: taskName });

// Step 3: Loop through challenge tasks until the target card is active
await this.navigateToTargetTask(targetCard);
}

async navigateToTargetTask(targetCard) {
const dotsCount = await this.slickDots.count();

let i = 0;
while (i < dotsCount && !(await this.isCardActive(targetCard))) {
await this.slickRightArrow.click();
i++;
}
expect(await this.isCardActive(targetCard)).toBeTruthy();
}

async isCardActive(card) {
const slickClass = await card.getAttribute("class");
return slickClass.includes("slick-active");
}
}

module.exports = ChallengeInfoPage;
16 changes: 7 additions & 9 deletions src/test/playwright/PO/basepage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect} from "@playwright/test";
import { expect } from "@playwright/test";

class BasePage {
constructor(page) {
Expand Down Expand Up @@ -51,16 +51,14 @@ class BasePage {

//use the method above to make assertion
async verifyElementExistance(allElements, name, doesExist = true) {
if ((await this.isItFirstPage())) {
if (await this.isItFirstPage()) {
await this.paginationFirstPage.click();
}
const isElementPresent = await this.isElementWithNamePresent(allElements, name)
doesExist
? expect(isElementPresent).toBe(true)
: expect(isElementPresent).toBe(false);
const isElementPresent = await this.isElementWithNamePresent(allElements, name);
doesExist ? expect(isElementPresent).toBe(true) : expect(isElementPresent).toBe(false);
}

async verifyUrl(expectedUrl){
async verifyUrl(expectedUrl) {
const currentUrl = await this.page.url();
expect(currentUrl).toBe(expectedUrl);
}
Expand All @@ -72,11 +70,11 @@ class BasePage {
);
}

async isItFirstPage(){
async isItFirstPage() {
return (
(await this.paginationFirstPage.isVisible()) &&
!(await this.paginationFirstPage.getAttribute("ant-pagination-item-active"))
)
);
}

async goToNextPage() {
Expand Down
29 changes: 22 additions & 7 deletions src/test/playwright/tests/challengesManipulation-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ let apiservice, challengespage, challengeinfopage,taskspage, addchallengepage, a
apiservice = new ApiService(page);
challengespage = new ChallengesPage(page);
await apiservice.apiLoginAs('admin');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Const for "admin"

// await apiservice.deleteChallengeBySequenceNumber(newChallengeCorrectDetails.SEQUENCE_NUMBER)
// await apiservice.deleteChallengeBySequenceNumber(editedChallengeCorrectDetails.SEQUENCE_NUMBER)
// await apiservice.deleteTaskByName(editedTaskCorrectDetails.NAME);
// await apiservice.deleteTaskByName(newTaskCorrectDetails.NAME);
})

test("Verify that a new challenge can be successfully created", async ({ page }) => {
Expand Down Expand Up @@ -171,9 +167,28 @@ let apiservice, challengespage, challengeinfopage,taskspage, addchallengepage, a
});


// test("Verify that the user can navigate through challenge's existing tasks", async({page})=>{
// await apiservice.createNewChallenge();
// })
test("Verify that the user can navigate through challenge's existing tasks", async({page})=>{
taskspage = new TasksPage(page);
challengeinfopage = new ChallengeInfoPage(page);
await apiservice.deleteTaskByName(createTaskRequest.body.name);
await apiservice.deleteTaskByName(createTaskRequest2.body.name);
await apiservice.deleteTaskByName(createTaskRequest3.body.name);
await apiservice.deleteTaskByName(createTaskRequest4.body.name);

await apiservice.createNewChallenge(createChallengeRequest);
await apiservice.createNewTask(createTaskRequest);
await apiservice.changeTaskDateToToday(createTaskRequest.body.name);
await apiservice.createNewTask(createTaskRequest2);
await apiservice.changeTaskDateToToday(createTaskRequest2.body.name);
await apiservice.createNewTask(createTaskRequest3);
await apiservice.changeTaskDateToToday(createTaskRequest3.body.name);
await apiservice.createNewTask(createTaskRequest4);
await apiservice.changeTaskDateToToday(createTaskRequest4.body.name);
await challengespage.gotoChallengesPage();
await challengespage.openChallengeInfoPage(createChallengeRequest.body.sortNumber);
await challengeinfopage.openViewChallenge();
await challengeinfopage.verifyTaskOnChallengeView(createTaskRequest4.body.name);
})


test.afterEach(async({page})=>{
Expand Down
Loading