|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test.describe("OB-04. Assertions", { tag: ["@onboarding"] }, () => { |
| 4 | + // TODO: |
| 5 | + // - [ ] Read the documentation on https://playwright.dev/docs/test-assertions |
| 6 | + // |
| 7 | + // - [ ] Goto the URL https://github.com |
| 8 | + // Write tests for AT LEAST 10 of the assertions listed below |
| 9 | + // Use different values from the documentation to test the assertions |
| 10 | + // |
| 11 | + // AUTO RETRYING ASSERTIONS |
| 12 | + // await expect(locator).toBeAttached() Element is attached |
| 13 | + |
| 14 | + const url = "https://github.com"; |
| 15 | + |
| 16 | + test.beforeEach(async ({ page }) => { |
| 17 | + await page.goto(url); |
| 18 | + }); |
| 19 | + |
| 20 | + test("TC-01: should be attached", async ({ page }) => { |
| 21 | + const logo = page.locator('a[href="/"]').first(); |
| 22 | + await expect(logo).toBeAttached(); |
| 23 | + }); |
| 24 | + |
| 25 | + test("TC-02: should be visible", async ({ page }) => { |
| 26 | + const signInButton = page.getByRole("link", { name: "Sign in" }); |
| 27 | + await expect(signInButton).toBeVisible(); |
| 28 | + }); |
| 29 | + |
| 30 | + test("TC-03: should have correct title", async ({ page }) => { |
| 31 | + await expect(page).toHaveTitle(/GitHub/); |
| 32 | + }); |
| 33 | + |
| 34 | + test("TC-04: should have correct URL", async ({ page }) => { |
| 35 | + await expect(page).toHaveURL(url); |
| 36 | + }); |
| 37 | + |
| 38 | + test("TC-05: should contain text", async ({ page }) => { |
| 39 | + const heroText = page.getByRole("heading", { |
| 40 | + name: /Build and ship software on a single/i, |
| 41 | + }); |
| 42 | + await expect(heroText).toContainText("Build and ship software on a single"); |
| 43 | + }); |
| 44 | + |
| 45 | + test("TC-06: should have attribute", async ({ page }) => { |
| 46 | + const signUpButton = page.getByRole("link", { name: "Sign up" }); |
| 47 | + await expect(signUpButton).toHaveAttribute("href", /\/signup/); |
| 48 | + }); |
| 49 | + |
| 50 | + test("TC-07: should have class", async ({ page }) => { |
| 51 | + const header = page.locator("header").first(); |
| 52 | + await expect(header).toHaveClass(/header-logged-out/); |
| 53 | + }); |
| 54 | + |
| 55 | + test("TC-08: should have sign-in button enabled", async ({ page }) => { |
| 56 | + const signInButton = page.getByRole("link", { name: "Sign in" }); |
| 57 | + await expect(signInButton).toBeEnabled(); |
| 58 | + }); |
| 59 | + |
| 60 | + test("TC-09: should have an empty search input in explore page", async ({ |
| 61 | + page, |
| 62 | + }) => { |
| 63 | + await page.goto("https://github.com/search"); |
| 64 | + const searchBox = page.getByRole("textbox", { name: "Search GitHub" }); |
| 65 | + const isSearchBoxVisible = await searchBox.isVisible(); |
| 66 | + await expect(searchBox).toBeEmpty(); |
| 67 | + }); |
| 68 | + |
| 69 | + test("TC-10: should have accessible name", async ({ page }) => { |
| 70 | + const signInButton = page.getByRole("link", { name: "Sign in" }); |
| 71 | + await expect(signInButton).toHaveAccessibleName("Sign in"); |
| 72 | + }); |
| 73 | + |
| 74 | + test("TC-11: should hide the mobile menu by default", async ({ page }) => { |
| 75 | + const mobileMenu = page.locator(".mobile-menu"); |
| 76 | + await expect(mobileMenu).toBeHidden(); |
| 77 | + }); |
| 78 | + |
| 79 | + test("TC-12: should verify if Sign in link is truthy", async ({ page }) => { |
| 80 | + const signInButton = await page |
| 81 | + .getByRole("link", { name: "Sign in" }) |
| 82 | + .getAttribute("href"); |
| 83 | + expect(signInButton).toBeTruthy(); |
| 84 | + }); |
| 85 | + |
| 86 | + test("TC-13: should match Sign up link with regex", async ({ page }) => { |
| 87 | + const signUpButton = await page |
| 88 | + .getByRole("link", { name: "Sign up" }) |
| 89 | + .getAttribute("href"); |
| 90 | + expect(signUpButton).toMatch(/^\/signup/); |
| 91 | + }); |
| 92 | + |
| 93 | + // await expect(locator).toBeChecked() Checkbox is checked |
| 94 | + // await expect(locator).toBeDisabled() Element is disabled |
| 95 | + // await expect(locator).toBeEditable() Element is editable |
| 96 | + // await expect(locator).toBeEmpty() Container is empty |
| 97 | + // await expect(locator).toBeEnabled() Element is enabled |
| 98 | + // await expect(locator).toBeFocused() Element is focused |
| 99 | + // await expect(locator).toBeHidden() Element is not visible |
| 100 | + // await expect(locator).toBeInViewport() Element intersects viewport |
| 101 | + // await expect(locator).toBeVisible() Element is visible |
| 102 | + // await expect(locator).toContainText() Element contains text |
| 103 | + // await expect(locator).toHaveAccessibleDescription() Element has a matching accessible description |
| 104 | + // await expect(locator).toHaveAccessibleName() Element has a matching accessible name |
| 105 | + // await expect(locator).toHaveAttribute() Element has a DOM attribute |
| 106 | + // await expect(locator).toHaveClass() Element has a class property |
| 107 | + // await expect(locator).toHaveCount() List has exact number of children |
| 108 | + // await expect(locator).toHaveCSS() Element has CSS property |
| 109 | + // await expect(locator).toHaveId() Element has an ID |
| 110 | + // await expect(locator).toHaveJSProperty() Element has a JavaScript property |
| 111 | + // await expect(locator).toHaveRole() Element has a specific ARIA role |
| 112 | + // await expect(locator).toHaveScreenshot() Element has a screenshot |
| 113 | + // await expect(locator).toHaveText() Element matches text |
| 114 | + // await expect(locator).toHaveValue() Input has a value |
| 115 | + // await expect(locator).toHaveValues() Select has options selected |
| 116 | + // await expect(page).toHaveScreenshot() Page has a screenshot |
| 117 | + // await expect(page).toHaveTitle() Page has a title |
| 118 | + // await expect(page).toHaveURL() Page has a URL |
| 119 | + // await expect(response).toBeOK() Response has an OK status |
| 120 | + // |
| 121 | + // NON-RETRYING ASSERTIONS |
| 122 | + // expect(value).toBe() Value is the same |
| 123 | + // expect(value).toBeCloseTo() Number is approximately equal |
| 124 | + // expect(value).toBeDefined() Value is not undefined |
| 125 | + // expect(value).toBeFalsy() Value is falsy, e.g. false, 0, null, etc. |
| 126 | + // expect(value).toBeGreaterThan() Number is more than |
| 127 | + // expect(value).toBeGreaterThanOrEqual() Number is more than or equal |
| 128 | + // expect(value).toBeInstanceOf() Object is an instance of a class |
| 129 | + // expect(value).toBeLessThan() Number is less than |
| 130 | + // expect(value).toBeLessThanOrEqual() Number is less than or equal |
| 131 | + // expect(value).toBeNaN() Value is NaN |
| 132 | + // expect(value).toBeNull() Value is null |
| 133 | + // expect(value).toBeTruthy() Value is truthy, i.e. not false, 0, null, etc. |
| 134 | + // expect(value).toBeUndefined() Value is undefined |
| 135 | + // expect(value).toContain() String contains a substring |
| 136 | + // expect(value).toContain() Array or set contains an element |
| 137 | + // expect(value).toContainEqual() Array or set contains a similar element |
| 138 | + // expect(value).toEqual() Value is similar - deep equality and pattern matching |
| 139 | + // expect(value).toHaveLength() Array or string has length |
| 140 | + // expect(value).toHaveProperty() Object has a property |
| 141 | + // expect(value).toMatch() String matches a regular expression |
| 142 | + // expect(value).toMatchObject() Object contains specified properties |
| 143 | + // expect(value).toStrictEqual() Value is similar, including property types |
| 144 | + // expect(value).toThrow() Function throws an error |
| 145 | + // expect(value).any() Matches any instance of a class/primitive |
| 146 | + // expect(value).anything() Matches anything |
| 147 | + // expect(value).arrayContaining() Array contains specific elements |
| 148 | + // expect(value).closeTo() Number is approximately equal |
| 149 | + // expect(value).objectContaining() Object contains specific properties |
| 150 | + // expect(value).stringContaining() String contains a substring |
| 151 | + // expect(value).stringMatching() String matches a regular expression |
| 152 | +}); |
0 commit comments