Playwright Tutorial | Assertions | expect function

Описание к видео Playwright Tutorial | Assertions | expect function

Validate Playwright Tests, Assert Playwright Tests

#playwright #typescript #javascript #with #assertions #softassertion #expect #tutorial #automation #testing #coding #selenium #cypress
playwright, playwright tutorial, playwright testing, playwright assertions, playwright soft assertions

=================================================================================

Chapters
00:00 - Introduction of Assertions in Playwright
01:47 - Type of Assertions
02:49 - Auto-retrying assertions in Playwright
17:25 - Import expect from playwright/test
18:04 - Non-retrying assertions in Playwright
20:28 - Negatives Matchers (.not) in Playwright
23:18 - Custom assertions error message in Playwright
24:53 - Soft assertions (expect.soft()) in Playwright
28:24 - Recap

=================================================================================

Playwright with TypeScript Series -    • Playwright Tutorials with TypeScript ...  
Playwright Notes - https://docs.google.com/document/d/e/...
Nopcommerce Website link for Practice - https://demo.nopcommerce.com/login
Saucedemo Website link for Practice - https://www.saucedemo.com/
Playwright Assertions official documentation - https://playwright.dev/docs/test-asse...

=================================================================================

Video 9 - Playwright (TypeScript) - Assertions in Playwright

What are Assertions - We can call assertions as verifications or checks which can be done in our tests, Playwright includes test assertions in the form of expect function.

Type of Assertions -
Assertions are classified into 2 parts -
1 - Auto-retrying Assertions - These assertions will retry until the assertion passes, or the assertion timeout is reached. Note that retrying assertions are async, so you must await them.
2 - Non retrying Assertions - These assertions allow you to test any conditions, but do not auto-retry. Most of the time, web pages show information asynchronously, and using non-retrying assertions can lead to a flaky test.

Note - Prefer auto-retrying assertions whenever possible.

Commonly used Auto-retrying Assertions -

await expect(locator).toHaveCount() - To check Specific number of elements are present on the page or not.
await expect(locator).toBeEnabled() - To check if element is enabled or not.
await expect(locator).toBeDisabled() - To check if an element is disabled or not.
await expect(locator).toBeVisible() - To check if an element is visible or not.
await expect(locator).toBeHidden() - To check Element is hidden or not.
await expect(locator).toHaveText(‘text’) - To check Element have specified text or not.
await expect(locator).toHaveAttribute(‘attribute’, ‘AttributeValue’) - To check if the element have specified value of attribute
await expect(locator).toHaveId(‘IdValue’) - To check if the element have specified value of id
await expect(locator).toHaveClass(‘ClassValue’) - To check if the element have specified value of id
await expect(page).toHaveURL(‘URLValue’) - To check if the page has specified URL or not
await expect(page).toHaveTitle(‘TitleValue’) - To check if the page has specified Title or not


Some Non retrying Assertions -
expect(value).toBe() - Value is the same
expect(value).toBeLessThan() - Number is less than

Negative Matchers - we can expect the opposite to be true by adding a .not to the front of the matchers:
Examples -
expect(value).not.toEqual(0);
await expect(locator).not.toHaveText('some text');

Custom Expect Message -
You can specify a custom error message as a second argument to the expect function.

Example -
await expect(locator, ‘Custom Error Message’).not.toHaveText('some text');


Soft Assertion -
By default, failed assertion will terminate test execution. Playwright also supports soft assertions: failed soft assertions do not terminate test execution, but mark the test as failed.
Examples -
expect.soft(value).not.toEqual(0);
await expect.soft(locator).toHaveText('some text');

============================================================================================================

Комментарии

Информация по комментариям в разработке