Skip to content

Commit e86e43e

Browse files
4manasamanasa
andauthored
updated the playwright tests (#581)
Co-authored-by: manasa <[email protected]>
1 parent 94798ac commit e86e43e

File tree

10 files changed

+278
-64
lines changed

10 files changed

+278
-64
lines changed

tests/e2e/Digv2/ComplexFields/CaseReference.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test.describe('E2E test', () => {
125125
await page.locator('button:has-text("Next")').click();
126126

127127
const assignment = page.locator('div[id="Assignment"]');
128-
await expect(assignment.locator(`div >> span >> text="${caseID[0]}"`)).toBeVisible();
128+
await expect(assignment.locator(`button:has-text("${caseID[0]}")`)).toBeVisible();
129129

130130
await page.locator('button:has-text("Previous")').click();
131131

tests/e2e/Digv2/ComplexFields/DataReference.spec.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,49 @@ test.describe('E2E test', () => {
2828

2929
await page.locator('button:has-text("submit")').click();
3030

31+
/** Testing Advanced Search */
32+
let selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
33+
await selectedSubCategory.click();
34+
await page.locator('li:has-text("DataPatterns")').click();
35+
36+
let selectedTestName = page.locator('div[data-test-id="6f64b45d01d11d8efd1693dfcb63b735"]');
37+
await selectedTestName.click();
38+
await page.locator('li:has-text("Advanced search")').click();
39+
40+
await page.locator('button:has-text("Search")').click();
41+
42+
const productName = page.locator('input[data-test-id="85c72bcef3da32c2abc605764537c6a1"]');
43+
await productName.fill('item');
44+
45+
await page.locator('button:has-text("Search")').click();
46+
47+
let table = page.locator('div[id="list-view"] >> nth = 0');
48+
let tableCell = table.locator('tbody >> tr >> td >> nth=1');
49+
50+
const selectedRow = await table.locator('tbody >> tr >> td >> span >> input[type="radio"] >> nth=0');
51+
await selectedRow.click();
52+
53+
await expect(await tableCell.textContent()).toContain('Item');
54+
55+
const radiobutton = await page.locator('div[role="radiogroup"]');
56+
const requiredDateInput = await radiobutton.locator('label >> span >> input >> nth=1');
57+
await requiredDateInput.click();
58+
59+
await page.locator('button:has-text("Discard")').click();
60+
61+
const price = await page.locator('input[data-test-id="3601146c4e948c32b6424d2c0a7f0118"]');
62+
await price.fill('12');
63+
64+
await page.locator('button:has-text("Search")').click();
65+
3166
/** Display subcategory tests */
3267

3368
/** Autocomplete display type test */
34-
let selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
69+
selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
3570
await selectedSubCategory.click();
3671
await page.locator('li:has-text("Display")').click();
3772

38-
let selectedTestName = page.locator('div[data-test-id="6f64b45d01d11d8efd1693dfcb63b735"]');
73+
selectedTestName = page.locator('div[data-test-id="6f64b45d01d11d8efd1693dfcb63b735"]');
3974
await selectedTestName.click();
4075
await page.locator('li:has-text("Autocomplete")').click();
4176

@@ -88,7 +123,8 @@ test.describe('E2E test', () => {
88123

89124
selectedTestName = page.locator('div[data-test-id="6f64b45d01d11d8efd1693dfcb63b735"]');
90125
await selectedTestName.click();
91-
await page.locator('li:has-text("Table")').click();
126+
127+
await page.getByRole('option', { name: 'Table', exact: true }).click();
92128

93129
selectedProduct = page.locator('tr:has-text("Basic Product")');
94130
const selectedProductRow = selectedProduct.locator('input[type="radio"]');
@@ -213,7 +249,7 @@ test.describe('E2E test', () => {
213249
await displayAs.click();
214250
await page.locator('li:has-text("Combo-Box")').click();
215251

216-
const selectProducts = page.locator('input[role="combobox"]');
252+
let selectProducts = page.locator('input[role="combobox"]');
217253
await selectProducts.click();
218254
await page.locator('li:has-text("Mobile")').click();
219255
await page.locator('li:has-text("Television")').click();
@@ -267,7 +303,7 @@ test.describe('E2E test', () => {
267303
await selectedTestName.click();
268304
await page.locator('li:has-text("Readonly")').click();
269305

270-
selectedProduct = page.locator('div[id="semantic-link-grid"] >> span >> text="Basic Product"');
306+
selectedProduct = page.locator('button:has-text("Basic Product")');
271307
await expect(selectedProduct).toBeVisible();
272308

273309
await page.locator('button:has-text("Next")').click();
@@ -292,26 +328,29 @@ test.describe('E2E test', () => {
292328

293329
await page.locator('span:has-text("Product Name")').click();
294330

295-
const table = page.locator('div[id="list-view"]');
296-
let tableCell = table.locator('tbody >> tr >> td >> nth=1');
331+
table = page.locator('div[id="list-view"]');
332+
tableCell = table.locator('tbody >> tr >> td >> nth=1');
297333
// "---" should come at the top in the ascending order, since it's a Falsy value
298334
await expect(await tableCell.textContent()).toBe('---');
299335

300336
await page.locator('span:has-text("Product Name")').click();
301337

302338
tableCell = table.locator('tbody >> tr >> td >> nth=1');
339+
303340
// "Luxury Product" should be at the top in the descending order
304-
await expect(await tableCell.textContent()).toBe('Luxury Product');
341+
await expect(await tableCell.textContent()).toBe('Red Item');
305342

306-
const lastRow = table.locator('tbody >> tr >> nth=3');
343+
const lastRow = table.locator('tbody >> tr >> nth=6');
307344
tableCell = lastRow.locator('td >> nth=1');
308345
// "---" should be at the bottom in the descending order
309346
await expect(await tableCell.textContent()).toBe('---');
310347

311348
await page.locator('button:has-text("Next")').click();
312349

350+
await page.locator('button:has-text("Previous")').click();
351+
313352
/** Submitting the case */
314-
await page.locator('button:has-text("submit")').click();
353+
await page.locator('button:has-text("Next")').click();
315354
}, 10000);
316355
});
317356

tests/e2e/Digv2/ComplexFields/EmbeddedData.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ test.describe('E2E test', () => {
216216

217217
await page.locator('button[id="delete-button"] >> nth=0').click();
218218

219+
await page.locator('button:has-text("Next")').click();
220+
await page.locator('button:has-text("Previous")').click();
221+
219222
/** Table Edit Modal tests */
220223
selectEditMode = page.locator('div[data-test-id="80c1db3a7b228760228004b1a532c71e"]');
221224
await selectEditMode.click();

tests/e2e/Digv2/FormFields/Boolean.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ test.describe('E2E test', () => {
4242
await expect(page.locator('div >> p:has-text("Required field")')).toBeVisible();
4343
const requiredBooleanLabel = page.locator('label[data-test-id="325f4eb20dc7c90a4fb697cd6c6bf0ea"]');
4444
await expect(await requiredBooleanLabel.locator('span').getByText('BooleanRequired')).toBeVisible();
45-
requiredBooleanLabel.click(); // check required field
46-
requiredBooleanLabel.click(); // uncheck required field
45+
await requiredBooleanLabel.click(); // check required field
46+
await requiredBooleanLabel.click(); // uncheck required field
4747
await expect(page.locator('p.Mui-error.Mui-required')).toBeVisible();
48-
requiredBooleanLabel.click();
48+
await requiredBooleanLabel.click();
4949
await expect(page.locator('p.Mui-error.Mui-required')).toBeHidden();
5050

5151
// Checking not required boolean field
5252
const notRequiredBooleanLabel = page.locator('label[data-test-id="da0d9f2c08a5bebe777c814af80a2351"]');
53-
notRequiredBooleanLabel.click(); // check required field
54-
notRequiredBooleanLabel.click(); // uncheck required field
53+
await notRequiredBooleanLabel.click(); // check required field
54+
await notRequiredBooleanLabel.click(); // uncheck required field
5555
await expect(page.locator('p.Mui-error.Mui-required')).toBeHidden();
5656

5757
/** Selecting Disable from the Sub Category dropdown */

tests/e2e/Digv2/FormFields/Email.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ test.describe('E2E test', () => {
9898
const editableEmail = page.locator('input[data-test-id="c75f8a926bb5e08fd8342f7fe45dc344"]');
9999
await editableEmail.fill('Johndoe.com');
100100
await editableEmail.blur();
101-
await expect(page.locator('p:has-text("Invalid")')).toBeVisible();
101+
await expect(page.locator('p:has-text("Enter a valid email address")')).toBeVisible();
102102
editableEmail.fill('[email protected]');
103103
await editableEmail.blur();
104-
await expect(page.locator('p:has-text("Invalid")')).toBeHidden();
104+
await expect(page.locator('p:has-text("Enter a valid email address")')).toBeHidden();
105105

106106
attributes = await common.getAttributes(editableEmail);
107107
await expect(attributes.includes('readonly')).toBeFalsy();
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
const { test, expect } = require('@playwright/test');
2+
const config = require('../../../config');
3+
const common = require('../../../common');
4+
5+
const isDisabled = true;
6+
const isVisible = true;
7+
8+
test.beforeEach(common.launchPortal);
9+
10+
test.describe('E2E test for Location component', () => {
11+
let attributes;
12+
13+
test('should login, create case and run Location tests', async ({ page }) => {
14+
await common.login(config.config.apps.digv2.user.username, config.config.apps.digv2.user.password, page);
15+
16+
/** Verify homepage */
17+
const announcementBanner = page.locator('h6:has-text("Announcements")');
18+
await expect(announcementBanner).toBeVisible();
19+
20+
const worklist = page.locator('h6:has-text("My Worklist")');
21+
await expect(worklist).toBeVisible();
22+
23+
/** Create case */
24+
const complexFieldsCase = page.locator('div[role="button"]:has-text("Form Field")');
25+
await complexFieldsCase.click();
26+
27+
/** Select Location category */
28+
const selectedCategory = page.locator('div[data-test-id="76729937a5eb6b0fd88c42581161facd"]');
29+
await selectedCategory.click();
30+
await page.locator('li >> text="Location"').click();
31+
32+
/** Select Required subcategory */
33+
const selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
34+
await selectedSubCategory.click();
35+
await page.getByRole('option', { name: 'Required' }).click();
36+
37+
await page.locator('button:has-text("submit")').click();
38+
39+
await expect(page.locator('div[role="alert"] >> text="Cannot be blank"')).toBeVisible();
40+
/** Required field test */
41+
const requiredLocationField = page.locator('input[data-test-id="5d234240d150ee2ad896ca0be0e01fd3"]');
42+
await requiredLocationField.type('Hitech City, Hyderabad');
43+
await page.waitForSelector('.pac-container .pac-item', { timeout: 50000 });
44+
await page.locator('.pac-container .pac-item').nth(1).click();
45+
46+
await expect(requiredLocationField).not.toHaveValue('');
47+
await expect(page.locator('p.Mui-error.Mui-required')).toBeHidden();
48+
49+
attributes = await common.getAttributes(requiredLocationField);
50+
expect(attributes.includes('required')).toBeTruthy();
51+
52+
/** Non-required field */
53+
const nonRequiredLocationField = page.locator('input[data-test-id="e4c3274b192b2696223fe7c86c635b75"]');
54+
attributes = await common.getAttributes(nonRequiredLocationField);
55+
expect(attributes.includes('required')).toBeFalsy();
56+
57+
/** Disable tests */
58+
await selectedSubCategory.click();
59+
await page.getByRole('option', { name: 'Disable' }).click();
60+
61+
const alwaysDisabledLocation = page.locator('input[data-test-id="43067a18c1d1c66f64f01e7e274c6396"]');
62+
attributes = await common.getAttributes(alwaysDisabledLocation);
63+
expect(attributes.includes('disabled')).toBeTruthy();
64+
65+
const conditionallyDisabledLocation = page.locator('input[data-test-id="878f51dda2d3d8279c962e2f65172ac3"]');
66+
attributes = await common.getAttributes(conditionallyDisabledLocation);
67+
if (isDisabled) {
68+
expect(attributes.includes('disabled')).toBeTruthy();
69+
} else {
70+
expect(attributes.includes('disabled')).toBeFalsy();
71+
}
72+
73+
const neverDisabledLocation = page.locator('input[data-test-id="a98054547fce446cbe5d4f9fb06c922c"]');
74+
attributes = await common.getAttributes(neverDisabledLocation);
75+
expect(attributes.includes('disabled')).toBeFalsy();
76+
77+
/** Update tests */
78+
await selectedSubCategory.click();
79+
await page.getByRole('option', { name: 'Update' }).click();
80+
81+
const editableLocation = page.locator('input[data-test-id="666e146bbb2d7e31be1a66c4ea52f453"]');
82+
await editableLocation.fill('Hitech City, Hyderabad');
83+
84+
await page.waitForSelector('.pac-container .pac-item', { timeout: 5000 });
85+
86+
await page.locator('.pac-container .pac-item').nth(1).click();
87+
88+
attributes = await common.getAttributes(editableLocation);
89+
expect(attributes.includes('readonly')).toBeFalsy();
90+
91+
/** Visibility tests */
92+
await selectedSubCategory.click();
93+
94+
await page.locator('[data-value="Visibility"]').click();
95+
96+
await expect(page.locator('input[data-test-id="4d056e06ff67ee10b252d5d96d373c91"]')).toBeVisible();
97+
98+
const neverVisibleLocation = page.locator('input[data-test-id="804db68b1b68c6e908079a1cab23fcdc"]');
99+
await expect(neverVisibleLocation).not.toBeVisible();
100+
101+
const conditionallyVisibleLocation = page.locator('input[data-test-id="4b7ffe4018eb786ba3d11aa195f7d98d"]');
102+
if (isVisible) {
103+
await expect(conditionallyVisibleLocation).toBeVisible();
104+
} else {
105+
await expect(conditionallyVisibleLocation).not.toBeVisible();
106+
}
107+
108+
/** Label and Placeholder tests */
109+
await selectedSubCategory.click();
110+
await page.getByRole('option', { name: 'Label' }).click();
111+
112+
const defaultLabelLocationField = page.locator('input[data-test-id="1d1f18e5499018ff649dd30066ba2270"]');
113+
const defaultLabel = await defaultLabelLocationField.locator('xpath=ancestor::div[contains(@class, "MuiFormControl")]//label').textContent();
114+
expect(defaultLabel).toBe('LocationDefaultLabel');
115+
116+
const customLabelLocationField = page.locator('input[data-test-id="88de9f842705651ff0dae0556755a43e"]');
117+
const customLabel = await customLabelLocationField.locator('xpath=ancestor::div[contains(@class, "MuiFormControl")]//label').textContent();
118+
expect(customLabel).toBe('Enter location (custom label)');
119+
120+
const customPlaceholderHelperField = page.locator('input[data-test-id="df7f2d2aa61b4ebfddb604ae39cb7374"]');
121+
const placeholder = await customPlaceholderHelperField.getAttribute('placeholder');
122+
expect(placeholder).toBe('Enter location');
123+
const helper = await customPlaceholderHelperField
124+
.locator('xpath=ancestor::div[contains(@class, "MuiFormControl")]//p[contains(@class, "MuiFormHelperText")]')
125+
.textContent();
126+
expect(helper).toBe('You can either enter place name or coordinates ');
127+
128+
/** Map visibility tests */
129+
130+
await selectedSubCategory.click();
131+
await page.getByRole('option', { name: 'Map Visibility' }).click();
132+
133+
const mapVisibleField = page.locator('input[data-test-id="ce5f551ab012660f2358544a1ce8dede"]');
134+
await expect(mapVisibleField).toBeVisible();
135+
const mapContainer = page.locator('input[data-test-id="ce5f551ab012660f2358544a1ce8dede"] >> xpath=..');
136+
await expect(mapContainer.locator('div')).toHaveCount(1); // Google Map
137+
const hiddenMapContainer = page.locator('input[data-test-id="ad80fd801feb0799ca829d6eedb8902a"] >> xpath=..');
138+
await expect(hiddenMapContainer.locator('iframe')).toHaveCount(0);
139+
140+
/** Coordinates format test */
141+
const onlyCoordsField = page.locator('input[data-test-id="41b59bdbb86495ae2db766c2944d4d7b"]');
142+
await onlyCoordsField.fill('Hitech City, Hyderabad');
143+
await page.waitForSelector('.pac-container .pac-item', { timeout: 5000 });
144+
await page.locator('.pac-container .pac-item').nth(1).click();
145+
146+
const coordinates = await onlyCoordsField.inputValue();
147+
const regex = /^-?\d+(\.\d+)?\s*,\s*-?\d+(\.\d+)?$/;
148+
expect(regex.test(coordinates.trim())).toBe(true);
149+
}, 10000);
150+
});
151+
152+
test.afterEach(async ({ page }) => {
153+
await page.close();
154+
});

tests/e2e/Digv2/FormFields/Phone.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test.describe('E2E test', () => {
8484
await page.getByRole('option', { name: 'Update' }).click();
8585

8686
/** Update tests */
87-
const readonlyPhone = page.locator('input[data-test-id="2c511e68e41cb70907b27a00de6b18b9"]');
87+
const readonlyPhone = page.locator('div[data-test-id="2c511e68e41cb70907b27a00de6b18b9"] >> input');
8888
attributes = await common.getAttributes(readonlyPhone);
8989
await expect(attributes.includes('readonly')).toBeTruthy();
9090

tests/e2e/Digv2/FormFields/URL.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test.describe('E2E test', () => {
8383
await expect(attributes.includes('readonly')).toBeFalsy();
8484

8585
/** Validation tests */
86-
const validationMsg = 'Please enter a valid URL including the protocol (http://, https://, ftp://, etc.)';
86+
const validationMsg = 'Enter a valid url';
8787
await editableURL.fill('InvalidUrl');
8888
await editableURL.blur();
8989
await expect(page.locator(`p:has-text("${validationMsg}")`)).toBeVisible();

0 commit comments

Comments
 (0)