Skip to content
Snippets Groups Projects
Commit 05b3e41b authored by ilyaukin's avatar ilyaukin
Browse files

Issue #3389608: Add a test for advanced search

parent 8c8e11b9
Branches 1.0.x
No related tags found
1 merge request!12Resolve #3389608 "Search"
[
{
"keyword": "dammit",
"results": [
"Futurama"
]
}
]
\ No newline at end of file
{
"simple": [
{
"keyword": "dammit",
"results": [
"Futurama"
]
}
],
"advanced": [
{
"any": "cicero ceaser",
"phrase": "",
"none": "futurama",
"types": [
"article"
],
"languages": [],
"results": [
"Cicero"
]
}
]
}
\ No newline at end of file
......@@ -21,6 +21,11 @@ const baseUrl = playwrightConfig.use.baseURL;
// Import ATK Configuration.
import atkConfig from '../../playwright.atk.config';
// Standard accounts that use user accounts created
// by QA Accounts. QA Accounts are created when the QA
// Accounts module is enabled.
import qaUserAccounts from '../data/qaUsers.json';
// Search keywords and expected results.
// Adjust for your site.
import searchData from '../data/search.json';
......@@ -29,7 +34,7 @@ test.describe('Search tests.', () => {
test('(ATK-PW-1160) Search content by a keyword. @ATK-PW-1160 @search @content', async ({ page }) => {
await page.goto(baseUrl);
for (let item of searchData) {
for (let item of searchData.simple) {
await page.getByRole("button", { name: "Search Form" }).click();
const keyInput = page.locator('input:focus');
......@@ -40,12 +45,61 @@ test.describe('Search tests.', () => {
await expect(page.getByText('Search results')).toBeVisible();
// Check that expected items are shown.
for (let result of item.results) {
await expect(page.getByText(result)).toBeVisible();
}
await checkResult(page, item);
// Check that the search keyword is highlighted in the text.
await expect(page.locator(`xpath=//strong[.="${item.keyword}"]`).first()).toBeVisible();
}
});
test('(ATK-PW-1161) Advanced search. @ATK-PW-1161 @search @content', async ({ page, context }) => {
for (let item of searchData.advanced) {
// In the default installation, only admin can do advanced search.
// Change if it's configured different way on your site.
await atkCommands.logInViaForm(page, context, qaUserAccounts.admin);
await page.goto(baseUrl + 'search/node');
// Expand "Advanced search".
await page.getByRole("button", { name: "Advanced search" }).click();
// Fill all the configured data.
if (item.any) {
await page.getByLabel("Containing any of the words").fill(item.any);
}
if (item.phrase) {
await page.getByLabel("Containing the phrase").fill(item.phrase);
}
if (item.none) {
await page.getByLabel("Containing none of the words").fill(item.none);
}
// Select node type if specified.
for (let type of item.types) {
await page.getByRole("group", { name: "Types" })
.getByLabel(type).check();
}
// Select languages if specified.
for (let language of item.languages) {
await page.getByRole("group", { name: "Languages" })
.getByLabel(language).check();
}
await page.locator('input[value="Advanced search"]').click();
// Wait for search result to be shown.
await checkResult(page, item);
}
});
async function checkResult(page, item) {
const resultLocatorList = await page.locator('.search-result__title').all();
const resultList = [];
for (let resultLocator of resultLocatorList) {
resultList.push((await resultLocator.textContent()).trim());
}
for (let result of item.results) {
expect(resultList).toContain(result);
}
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment