Skip to content

Commit

Permalink
page objects: store call to the locator in the previous commit into a…
Browse files Browse the repository at this point in the history
… variable
  • Loading branch information
ashwiniraokarai committed Apr 23, 2024
1 parent 2bec52f commit 574709a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/adding-items.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { test, expect, Locator } from "@playwright/test";
import { TodoForm } from "./page-classes/todo-form.ts";

let todoForm: TodoForm;
let newTodoField: Locator;
let displayedTodoItems: Locator;
let todoForm: TodoForm;
let countOfRemainingToDos: Locator;

test.beforeEach(
async({ page })=>{
Expand All @@ -12,6 +13,7 @@ test.beforeEach(
//Invoke the page object to grab locator(s)
todoForm = new TodoForm(page);
newTodoField = todoForm.newToDoField();
countOfRemainingToDos = todoForm.countOfRemainingToDos();

//Instead of the li, you could even target the label inside the li directly which embeds the text, like so:
//".todo-list label"
Expand Down Expand Up @@ -44,7 +46,7 @@ test.describe("when adding a single todo item",

test("be shown the count of remaining items",
async ( { page } ) => {
await expect(todoForm.countOfRemainingToDos())
await expect(countOfRemainingToDos)
.toHaveText("1 item left");
await page.close();
}
Expand All @@ -68,7 +70,7 @@ test.describe("when adding multiple todo items",

test("should be shown the count of remaining items",
async( {page} ) => {
await expect(todoForm.countOfRemainingToDos())
await expect(countOfRemainingToDos)
.toHaveText("2 items left");
}
);
Expand Down

0 comments on commit 574709a

Please sign in to comment.