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

Test Pages, Contact & Donation #1662

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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 packages/playwright/src/tests/07-pages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test'

import { getUrl } from '../utils'
test.beforeEach(async ({ page }) => {
await page.goto(getUrl('kunsthalte'))
await page.waitForTimeout(1000)
await page.click('button:has-text("EN")')
})
test.describe('07. Pages', () => {
test('TC-01: should Arts ', async ({ page }) => {
7alip marked this conversation as resolved.
Show resolved Hide resolved
await page.getByTestId('link-d/club/arts').click()
const pageTitle = await page.title()
expect(pageTitle).toContain('Art Station') // 01. On the Arts page, does the title match the page name?
})
test('TC-02: should Collections', async ({ page }) => {
7alip marked this conversation as resolved.
Show resolved Hide resolved
await page.getByTestId('link-d/club/collections').click()
await page.waitForTimeout(1000)
const titleEN = await page.textContent('h2.chakra-heading')
expect(titleEN).toContain('Collections') // 01. Does the Collections page open?
const pageTitleEN = await page.title()
expect(pageTitleEN).toContain('Collections') // 02. On the Collections page, Does the title match the page name?
})
test('TC-03: should Activities ', async ({ page }) => {
7alip marked this conversation as resolved.
Show resolved Hide resolved
await page.getByTestId('link-d/activities').click()
await page.waitForTimeout(1000)
const titleEN = await page.textContent('h2.chakra-heading')
expect(titleEN).toBe('Activities') // 01. Does the Activities page open?
const pageTitleEN = await page.title()
expect(pageTitleEN).toContain('Activities') // 02. On the Activities page, Does the title match the page name?
})
test('TC-01: should About Us', async ({ page }) => {
7alip marked this conversation as resolved.
Show resolved Hide resolved
await page.getByRole('link', { name: 'About Us' }).first().click()
await page.waitForTimeout(1000)
const titleEN = await page.textContent('h2.chakra-heading')
expect(titleEN).toContain('About Us') // 01. Does the About Us page open?
const pageTitleEN = await page.title()
expect(pageTitleEN).toContain('About Us') // 02. On the About Us page, Does the title match the page name?
})
})
89 changes: 89 additions & 0 deletions packages/playwright/src/tests/08-contact.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { test, expect } from '@playwright/test'

import { getUrl } from '../utils'
test.beforeEach(async ({ page }) => {
await page.goto(getUrl('kunsthalte'))
await page.waitForTimeout(1000)
await page.click('button:has-text("EN")')
})

test.describe('08. Contact', () => {
test('TC-01: should Contact', async ({ page }) => {
await page.getByRole('link', { name: 'Contact' }).first().click()
await page.waitForLoadState('networkidle')
await expect(page.locator('[id="__next"]')).toContainText('Contact') // 01. Does the Contact page open?

const pageTitle = await page.title()
await page.waitForTimeout(100)
expect(pageTitle).toContain('Contact') // 02. Does the title match the page name? //yapılamadı
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Lets move this title check to 07-pages.spec.ts as we will test all the pages in there.


await page.getByPlaceholder('Your Full Name').click()
await page.getByPlaceholder('E-mail').click()
await page.getByPlaceholder('Message').click()
await page.getByPlaceholder('Your Full Name').click()

const fullNameErrorMessage = await page.locator(
'[data-testid="error-text-fullname"]',
)
const isDivVisible = await fullNameErrorMessage.isVisible()
await expect(isDivVisible).toBe(true) // 03. Is Your Full Name a required field? // bakılacak

const requiredTextEmail = page.getByTestId('error-text-email')
await expect(requiredTextEmail).toBeVisible() // 04. Is email a required field?

const emailInput = await page.locator('[data-testid="input-email"]')
const testEmailError = 'test_example.com'
await emailInput.fill(testEmailError)
const requiredTextEmailError = await page.locator(
'[data-testid="error-text-email"]',
)

const isTextVisibleEmailError = await requiredTextEmailError.isVisible()
await expect(isTextVisibleEmailError).toBe(true)
const testEmail = '[email protected]'
await emailInput.fill(testEmail)
const emailValue = await emailInput.inputValue()
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

const isValidEmail = emailRegex.test(emailValue)
expect(isValidEmail).toBe(true) // 05. Assert that the email is valid
const requiredTextMessage = await page.locator(
'[data-testid="error-text-message"]',
)
const isTextVisibleMessage = await requiredTextMessage.isVisible()
await expect(isTextVisibleMessage).toBe(true) // 06. Is Message a required field?
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

This part could be separate test case:

test('TC-02: should display required fields errors', ({ page }) => {})


await page.getByPlaceholder('Your Full Name').fill('Test Mustafa BUDAK')
await page.getByPlaceholder('Message').fill('Bu bir Deneme Mesajıdır.')
await page.getByRole('button', { name: 'Send message' }).click()
await page.waitForTimeout(1000)
await page.waitForLoadState('networkidle')
const successDiv = await page.textContent('div[data-status="success"]')
expect(successDiv).toBe('Thank you. Your message has been delivered.') // 07. Can the user send the message successfully ?
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

This part could be separate test case:

test('TC-02: should send message via contact form', ({ page }) => {})


const emaillink = page.locator('a[href^="mailto:"]')
await expect(emaillink).toHaveCount(1) // 08. When clicking on the email address icon, the user should be directed to the Outlook application.
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

toHaveCount is intended to be used for list I think. toBeVisible would be better.


const xElement = page.getByLabel('X').first().getAttribute('href')
expect(xElement).not.toBeNull() // 09. When clicking on the xcom icon, the user should be directed to another page.
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

We have a util function to check external links. You can use this for all social buttons

const xElement = page.getByLabel('X').first()
await checkExternalLink(xElement, 'https://x.com/kunsthalte')


const WhatsAppElement = page
.getByLabel('WhatsApp')
.first()
.getAttribute('href')
expect(WhatsAppElement).not.toBeNull() // 10. When clicking on the WhatsApp icon, the user should be directed to another page.

const InstagramElement = page
.getByLabel('Instagram')
.first()
.getAttribute('href')
expect(InstagramElement).not.toBeNull() // 11. When clicking on the Instagram icon, the user should be directed to another page.

const YoutubeElement = page
.getByLabel('Youtube')
.first()
.getAttribute('href')
expect(YoutubeElement).not.toBeNull() // 12. When clicking on the Youtube icon, the user should be directed to another page.
await page.click('button:has-text("EN")')
})
})
78 changes: 78 additions & 0 deletions packages/playwright/src/tests/09-donate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { test, expect } from '@playwright/test'

import { getUrl } from '../utils'
test.beforeEach(async ({ page }) => {
await page.goto(getUrl('kunsthalte'))
await page.waitForTimeout(1000)
await page.click('button:has-text("EN")')
await page.waitForTimeout(1000)
})

test.describe('01. Donate', () => {
test('TC-01: should Donate', async ({ page }) => {
await page.getByRole('link', { name: 'Donate' }).click()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

It has testid

    await page.getByTestId('link-d-donation').click()
    await page.waitForLoadState('documentloaded')


await expect(page.getByRole('heading')).toContainText('Donate') // 01. Does the Donate page open?
const pageTitle = await page.title()
expect(pageTitle).toContain('Donate') // 02. Does the title match the page name?
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Let's move this to 07-pages.spec.ts

await page.getByRole('button', { name: '€10', exact: true }).click()
const inputElement = page.locator('.chakra-numberinput input')
const value = await inputElement.inputValue()
expect(value).toContain('10')
await page.getByRole('button', { name: '€5', exact: true }).click()
await page.getByRole('button', { name: '€20' }).click()
await page.getByRole('button', { name: '€50' }).click()
await page.getByRole('button', { name: '€100' }).click()
await page.getByRole('button', { name: '€10', exact: true }).click()
await page.locator('.css-8pgw4r').first().click()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Request testid or add TODO comment:

Suggested change
await page.locator('.css-8pgw4r').first().click()
// TODO: Add data-testid
await page.locator('.css-8pgw4r').first().click()

await page.waitForLoadState('networkidle')

const chakraNumberInputDivvalue = await page
.locator('.chakra-numberinput input')
.inputValue()
expect(chakraNumberInputDivvalue).toContain('11')
await page.locator('.css-1jj9yua > div:nth-child(2)').click()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Same comment, testid


const inputLocator = page.locator('.chakra-numberinput input')
const valuee = await inputLocator.inputValue()
expect(valuee).toContain('10')
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Up to here, it could be separate test case:

test('TC-02: should display correct amount in input', ({ page }) => {})

await page.getByPlaceholder('Name').click()
await page.getByPlaceholder('E-mail').click()
await page.getByPlaceholder('Name').click()

const requiredTextName = await page.locator('text=name is a required field')
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

It has error-text-name testid


const isTextVisibleName = await requiredTextName.isVisible()
await expect(isTextVisibleName).toBe(true) // 05. Is Name a required field?
await page.getByPlaceholder('Name').fill('Mustafa Budak')
const requiredTextEmail = await page.locator(
'text=email is a required field',
)
const isTextVisibleEmail = await requiredTextEmail.isVisible()
await expect(isTextVisibleEmail).toBe(true)

// 06. Is E-mail a required field?
const emailInput = await page.locator('input[name="email"]')

const testEmailError = 'test_example.com'
await emailInput.fill(testEmailError)
const requiredTextEmailError = await page.locator(
'text=email must be a valid email',
)

const isTextVisibleEmailError = await requiredTextEmailError.isVisible()
await expect(isTextVisibleEmailError).toBe(true)
const testEmail = '[email protected]'
await emailInput.fill(testEmail)
const emailValue = await emailInput.inputValue()
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

const isValidEmail = emailRegex.test(emailValue)
expect(isValidEmail).toBe(true) // 07. Assert that the email is valid
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

You don't need to validate emails like developers. You should just check if UI shows error message for invalid emails. I would remove this regex validation

await Promise.all([page.getByRole('button', { name: 'Donate €' }).click()])
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Promise.all shouldn't be needed here.

Suggested change
await Promise.all([page.getByRole('button', { name: 'Donate €' }).click()])
await page.getByRole('button', { name: 'Donate €' }).click()
await page.waitForLoadState('documentloaded')

const newUrl = page.url()
expect(isValidEmail).toBe(newUrl.length > 0) // 08. When the donate button is clicked, the user should be directed to the payment page.
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

What about this?

 expect(newUrl).toContain('checkout.stripe.com')


// Test code here
})
})
Loading