Skip to content

Commit

Permalink
included new files for blog page
Browse files Browse the repository at this point in the history
  • Loading branch information
Zahid-Automate committed Jan 11, 2024
1 parent 81af671 commit 38bf08a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pages/blog.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Page , Locator} from '@playwright/test';

class BlogPage{
page: Page;
blogHeading: Locator;
blogLinksList: Locator;
constructor(page: Page){
this.page=page;
this.blogHeading = page.locator('//h2[normalize-space()="Recent Posts"]');
this.blogLinksList = page.locator('//section[@id="recent-posts-3"]//ul//li');

}

}

export default BlogPage;
41 changes: 41 additions & 0 deletions tests/blog.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test, expect } from '@playwright/test';
import HomePage from '../pages/home.page';
import BlogPage from '../pages/blog.page';

test.describe('Blog page', () => {
let homePage:HomePage;
let blogPage:BlogPage;

test('Verify the number of links present in the blogs page', async ({ page }) => {
homePage = new HomePage(page);
blogPage = new BlogPage(page);

//Open Url
await homePage.navigate();
page.pause();
//Click on Blog
await homePage.blogMenu.click();

//Verify url has blog
await expect(page).toHaveURL(/.*blog/);


await blogPage.blogHeading.hover();
const relatedLinks = blogPage.blogLinksList;
const len = await relatedLinks.count();
console.log ("Total number of links present in Recent Posts is "+ len);

// Verify the number of related links present in blogs is 5
expect(len).toEqual(5);

const mylist = blogPage.blogLinksList.allTextContents();
const myList = await mylist; // Assuming mylist is an asynchronous operation that returns a list

for (let i = 0; i < myList.length; i++) {
console.log("Length of " + myList[i].trim() + " is " + myList[i].trim().length);
}

})
}

);

0 comments on commit 38bf08a

Please sign in to comment.