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

Challenge resuelto en los tests #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test'
import { devices } from '@playwright/test'

/**
* Read environment variables from file.
Expand All @@ -19,7 +19,7 @@ const config: PlaywrightTestConfig = {
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
Expand All @@ -36,7 +36,7 @@ const config: PlaywrightTestConfig = {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'https://playwright.deev/docs/intro',
baseURL: 'https://playwright.dev/docs/intro',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down Expand Up @@ -102,6 +102,6 @@ const config: PlaywrightTestConfig = {
// command: 'npm run start',
// port: 3000,
// },
};
}

export default config;
export default config
52 changes: 26 additions & 26 deletions tests/search.spec.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import { test, expect } from '@playwright/test';
import { test, expect } from '@playwright/test'

test.beforeEach(async ({ page }) => {
await page.goto('/');
});
await page.goto('/')
})

test('Realizar una busqueda que no tenga resultados', async ({ page }) => {
await page.getByRole('button').click();
await page.getByRole('button', { name: 'Search' }).click()

await page.getByPlaceholder('Search docs').click();
await page.getByPlaceholder('Search docs').click()

await page.getByPlaceholder('Search docs').fill('hascontent');
await page.getByPlaceholder('Search docs').fill('hascontent')

expect(page.locator('.DocSearch-NoResults p')).toBeVisible();
await page.pause()

expect(page.locator('.DocSearch-NoResults p')).toHaveText('No results for hascontent');
await expect(page.locator('p.DocSearch-Title')).toBeVisible()

await expect(page.locator('p.DocSearch-Title')).toContainText(/No results for "hascontent"/)
})

test('Limpiar el input de busqueda', async ({ page }) => {
await page.getByRole('button', { name: 'Search' }).click();
await page.getByRole('button', { name: 'Search' }).click()

const searchBox = page.getByPlaceholder('Search docs');
const searchBox = page.getByPlaceholder('Search docs')

await searchBox.click();
await searchBox.click()

await searchBox.fill('somerandomtext');
await searchBox.fill('somerandomtext')

await expect(searchBox).toHaveText('somerandomtext');
await expect(searchBox).toHaveAttribute('value', 'somerandomtext')

await page.getByRole('button', { name: 'Clear the query' }).click();
await page.getByRole('button', { name: 'Clear the query' }).click()

await expect(searchBox).toHaveAttribute('value', '');
});
await expect(searchBox).toHaveAttribute('value', '')
})

test('Realizar una busqueda que genere al menos tenga un resultado', async ({ page }) => {
await page.getByRole('button', { name: 'Search ' }).click();
await page.getByRole('button', { name: 'Search' }).click()

const searchBox = page.getByPlaceholder('Search docs');
const searchBox = page.getByPlaceholder('Search docs')

await searchBox.click();
await searchBox.click()

await page.getByPlaceholder('Search docs').fill('havetext');
await page.getByPlaceholder('Search docs').fill('havetext')

expect(searchBox).toHaveText('havetext');
await expect(searchBox).toHaveAttribute('value', 'havetext')

// Verity there are sections in the results
await page.locator('.DocSearch-Dropdown-Container section').nth(1).waitFor();
const numberOfResults = await page.locator('.DocSearch-Dropdown-Container section').count();
await expect(numberOfResults).toBeGreaterThan(0);

});
await page.locator('.DocSearch-Dropdown-Container section').nth(1).waitFor()
const numberOfResults = await page.locator('.DocSearch-Dropdown-Container section').count()
await expect(numberOfResults).toBeGreaterThan(0)
})