
Grab the locators. This will be something similar to the Angular application but unique which I've mentioned in my earlier post.
Locators:

export const shareAnUpdateButton = 'button:has-text("Share an update...")'
export const textBox =
'text=Share an update... Bold Italic Underline Strikethrough Remove Formatting Bullete >> p'
export const shareButton = 'button:has-text("Share")'
export const justNow = "//a[normalize-space()='Just now']"
export const messageText =
"(//span[normalize-space()='These are my Blogposts --->'])[1]"
export const chatterFeedLink =
"(//a[@data-value='https://www.blogger.com/profile/06939442079028713822'])[1]"
export const attachmentIcon = 'button:has-text("Attach up to 10 files")'
export const uploadFilesButton = 'button:has-text("Upload Files")'
export const justNowForDownload =
'[aria-label="Test Test\\, Just now"] >> text=Upload a File!'
export const downloadFile =
'[aria-label="Test Test\\, Just now"] div[role="group"] div:has-text(" DownloadDownload")'
export const uploadAFileMessageInFeed =
"(//span[normalize-space()='Upload a File!'])[1]"
export const fileInFeed = "(//a[@title='View File'])[1]"
Pages:
import { BasePage } from './basePage'
import { expect } from '@playwright/test'
import { baseUrl } from '../config'
export class LandingPage extends BasePage {
constructor(page: Page) {
super(page)
}
async openApp(): Promise<void> {
await super.open(baseUrl)
await super.waitForPageLoad()
}
async type(selector: string, text: string): Promise<LandingPage> {
return await this.waitAndFill(selector, text)
}
async clickElement(selector: any): Promise<LandingPage> {
return await this.waitAndClick(selector)
}
async clickShareButton(selector): Promise<LandingPage> {
return await this.nthClick(selector)
}
async verifyIsVisible(selector: any): Promise<LandingPage> {
const isVisible = await this.isElementVisible(selector)
expect(isVisible).toBeTruthy()
return isVisible
}
}
Tests:
/*
Scenario: Create a new Chatter post message with test url and share it with followers
and click the test url link
Test Steps:
1. Create a new chatter post message
2. Add a test URL https://www.blogger.com/profile/06939442079028713822 to the message body
3. Share the new message with the followers.
4. Check whether the message with the test URL is visible in Chatter feed
5. Verify the target location when the test URL is clicked.
*/
import { expect } from '@playwright/test'
import { baseUrl, bloggerPageTitle, bloggerPageUrl } from '../../config'
import {
shareAnUpdateButton,
textBox,
justNow,
messageText,
chatterFeedLink,
shareButton
} from '../../pageObjects/landingPage'
import test from '../../fixtures/fixture'
import fs from 'fs'
const testData = JSON.parse(fs.readFileSync(`./data/data.json`, `utf-8`))
test.describe.serial(
'Create a new chatter post message with url and share it to followers',
() => {
test('User posts a new chatter message in the chatter feed to followers', async ({
landingPage
}) => {
await test.step(`user logged in to app successfully`, async () => {
await landingPage.openApp()
expect(await landingPage.getUrl()).toBe(baseUrl)
expect(await landingPage.getTitle()).toBe(testData.title)
})
await test.step(
'User types in message and url link in the text box and verifies the message with url is visible in the chatter feed',
async () => {
await landingPage.clickElement(shareAnUpdateButton)
await landingPage.type(textBox, testData.message)
await landingPage.clickShareButton(shareButton)
const isDisplayed = await landingPage.verifyIsVisible(justNow)
expect(isDisplayed).toBe(true)
var isVisible = await landingPage.verifyIsVisible(messageText)
expect(isVisible).toBe(true)
var isVisible = await landingPage.verifyIsVisible(chatterFeedLink)
expect(isVisible).toBe(true)
}
)
})
test('User clicks on the test url link and verifies the test url in a new tab', async ({
browser
}) => {
const context = await browser.newContext()
const page = await context.newPage()
await page.goto(baseUrl)
const link = page.locator(chatterFeedLink)
const [newPage] = await Promise.all([
context.waitForEvent('page'),
await link.click()
])
await newPage.waitForLoadState('networkidle')
expect(await newPage.title()).toContain(bloggerPageTitle)
expect(newPage.url()).toBe(bloggerPageUrl)
})
}
)
Here, I have taken two scenarios:
Scenario 1:
Scenario: Create a new Chatter post message with test url and share it with followers
and click the test url link
Test Steps:
1. Create a new chatter post message
2. Add a test URL https://www.blogger.com/profile/06939442079028713822 to the message body
3. Share the new message with the followers.
4. Check whether the message with the test URL is visible in Chatter feed
5. Verify the target location when the test URL is clicked.
Test Output:
Scenario 2:
Scenario: Create a new Chatter post message by attaching a test file and share it with
followers and download that same file
Test Steps:
1. Create a new Chatter post message
2. Attach a test file from your local disk or folder to the message
3. Share the new message with the followers.
4. Check whether the message with the test file are visible in the Chatter feed
5. Verify that the test file can be downloaded from the posted message
Test Output:
The two scenarios will cover opening a New tab, Upload document and Download document with Playwright.
Here is the GitHub Repo: Playwright-Salesforce
The main point, I have observed here is the locators for Angular and Salesforce applications are little different to that of our typical React.js, Vue.js applications.
Rest of the framework like the pages and tests remains same.
Happy Automation Testing Guys :) !
No comments:
Post a Comment