Skip to content

Commit

Permalink
Updating Marketo message tests (#435)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Li <[email protected]>
  • Loading branch information
Dli3 and Dennis Li committed Sep 13, 2024
1 parent 0f58606 commit 782bc48
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 31 deletions.
25 changes: 18 additions & 7 deletions configs/bacom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const envs = require('../envs/envs.js');
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
const config = {
testDir: '../tests/bacom',
testDir: '../tests/',
testMatch: ['bacom/**/*.test.js', 'milo/**/*.test.js'],
outputDir: '../test-results',
/* Maximum time one test can run for. */
timeout: 45 * 1000,
Expand All @@ -30,11 +31,18 @@ const config = {
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI
? [['github'], ['list'], ['../utils/reporters/base-reporter.js']]
: [['html', {
outputFolder: 'test-html-results',
open: 'never',
}], ['list'], ['../utils/reporters/base-reporter.js'],
['json', { outputFile: '../test-json-results/test-results.json' }]],
: [
[
'html',
{
outputFolder: 'test-html-results',
open: 'never',
},
],
['list'],
['../utils/reporters/base-reporter.js'],
['json', { outputFile: '../test-json-results/test-results.json' }],
],

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
Expand All @@ -45,7 +53,10 @@ const config = {

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
baseURL: process.env.BASE_URL || envs['@bacom_live'] || 'https://main--bacom--adobecom.hlx.live',
baseURL:
process.env.BASE_URL
|| envs['@bacom_live']
|| 'https://main--bacom--adobecom.hlx.live',
},

/* Configure projects for major browsers */
Expand Down
16 changes: 4 additions & 12 deletions features/milo/marketo.block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ module.exports = {
{
tcid: '0',
name: '@marketo full template',
path: [
'/drafts/nala/blocks/marketo/full',
],
path: ['/drafts/nala/blocks/marketo/full'],
tags: '@marketo @marketoFullRedirect @marketoRedirect @milo @smoke @regression',
},
{
tcid: '1',
name: '@marketo full template with company type',
path: [
'/drafts/nala/blocks/marketo/full-with-company-type',
],
path: ['/drafts/nala/blocks/marketo/full-with-company-type'],
tags: '@marketo @marketoFullRedirect @marketoRedirect @milo @smoke @regression',
},
{
Expand All @@ -38,17 +34,13 @@ module.exports = {
{
tcid: '4',
name: '@marketo full template message',
path: [
'/drafts/nala/blocks/marketo/full-message',
],
path: ['/drafts/nala/blocks/marketo/full-message'],
tags: '@marketo @marketoFullMessage @marketoMessage @milo @smoke @regression',
},
{
tcid: '5',
name: '@marketo full template with company type',
path: [
'/drafts/nala/blocks/marketo/full-message-with-company-type',
],
path: ['/drafts/nala/blocks/marketo/full-message-with-company-type'],
tags: '@marketo @marketoFullMessage @marketoMessage @milo @smoke @regression',
},
{
Expand Down
50 changes: 42 additions & 8 deletions selectors/milo/marketo.block.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class Marketo {
);
this.submitButton = this.marketo.locator('#mktoButton_new');
this.message = this.marketo.locator('.ty-message');
this.title = this.marketo.locator('.marketo-title');
this.description = this.marketo.locator('.marketo-description');
}

async submitFullTemplateForm(poi) {
Expand All @@ -45,7 +47,9 @@ export default class Marketo {
await this.postalCode.fill(POSTAL_CODE);

// Setting index 2 to test so that the 'Company Type' field doesn't display
await this.primaryProductInterest.selectOption(poi !== undefined ? poi : { index: 2 });
await this.primaryProductInterest.selectOption(
poi !== undefined ? poi : { index: 2 },
);

await this.state.selectOption({ index: 1 });
await this.selectCompanyType();
Expand Down Expand Up @@ -85,6 +89,11 @@ export default class Marketo {
const template = await this.page.evaluate(
'window.mcz_marketoForm_pref.form.template',
);

if (!template) {
throw new Error('Template not found');
}

return template;
}

Expand All @@ -102,13 +111,7 @@ export default class Marketo {
* and that the value isn't empty.
*/
async checkInputPlaceholders() {
const template = await this.page.evaluate(
'window.mcz_marketoForm_pref.form.template',
);

if (!template) {
throw new Error('Template not found');
}
const template = await this.getFormTemplate();

const inputFields = [
this.firstName,
Expand All @@ -127,4 +130,35 @@ export default class Marketo {
}).toPass();
});
}

async formElements() {
const template = await this.getFormTemplate();

const elements = [
this.firstName,
this.lastName,
this.email,
this.company,
this.country,
this.companyType,
this.submitButton,
this.title,
this.description,
];

if (template === 'flex_event') {
elements.push(this.jobTitle, this.functionalArea);
} else if (template === 'flex_contact') {
elements.push(
this.phone,
this.jobTitle,
this.functionalArea,
this.state,
this.postalCode,
this.primaryProductInterest,
);
}

return elements;
}
}
40 changes: 36 additions & 4 deletions tests/milo/marketo.block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,19 @@ test.describe('Marketo block test suite', () => {
await marketoBlock.submitFullTemplateForm();
});

await test.step('step-4: Verify the form submission redirect', async () => {
await test.step('step-4: Verify that the form message displays after form submission.', async () => {
await expect(async () => {
await expect(marketoBlock.message).toBeAttached();
await expect(page.url()).toBe(testPage);
}).toPass();

const elements = await marketoBlock.formElements();

elements.forEach(async (el) => {
await expect(async () => {
await expect(el).not.toBeVisible();
}).toPass();
});
});
});
});
Expand Down Expand Up @@ -203,11 +211,19 @@ test.describe('Marketo block test suite', () => {
await marketoBlock.submitFullTemplateForm('Digital commerce');
});

await test.step('step-4: Verify the form submission redirect', async () => {
await test.step('step-4: Verify that the form message displays after form submission.', async () => {
await expect(async () => {
await expect(marketoBlock.message).toBeAttached();
await expect(page.url()).toBe(testPage);
}).toPass();

const elements = await marketoBlock.formElements();

elements.forEach(async (el) => {
await expect(async () => {
await expect(el).not.toBeVisible();
}).toPass();
});
});
});
});
Expand Down Expand Up @@ -235,11 +251,19 @@ test.describe('Marketo block test suite', () => {
await marketoBlock.submitExpandedTemplateForm();
});

await test.step('step-4: Verify the form submission redirect', async () => {
await test.step('step-4: Verify that the form message displays after form submission.', async () => {
await expect(async () => {
await expect(marketoBlock.message).toBeAttached();
await expect(page.url()).toBe(testPage);
}).toPass();

const elements = await marketoBlock.formElements();

elements.forEach(async (el) => {
await expect(async () => {
await expect(el).not.toBeVisible();
}).toPass();
});
});
});
});
Expand Down Expand Up @@ -267,11 +291,19 @@ test.describe('Marketo block test suite', () => {
await marketoBlock.submitEssentialTemplateForm();
});

await test.step('step-4: Verify the form submission redirect', async () => {
await test.step('step-4: Verify that the form message displays after form submission.', async () => {
await expect(async () => {
await expect(marketoBlock.message).toBeAttached();
await expect(page.url()).toBe(testPage);
}).toPass();

const elements = await marketoBlock.formElements();

elements.forEach(async (el) => {
await expect(async () => {
await expect(el).not.toBeVisible();
}).toPass();
});
});
});
});
Expand Down

0 comments on commit 782bc48

Please sign in to comment.