Refactor code to k6
[MAILPOET-4957]
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { sleep, check, group } from 'k6';
|
import { sleep, check } from 'k6';
|
||||||
import { chromium } from 'k6/experimental/browser';
|
import { chromium } from 'k6/experimental/browser';
|
||||||
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
|
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
|
||||||
|
|
||||||
@@ -21,64 +21,57 @@ import {
|
|||||||
import { authenticate } from '../utils/helpers.js';
|
import { authenticate } from '../utils/helpers.js';
|
||||||
/* global Promise */
|
/* global Promise */
|
||||||
|
|
||||||
export function listsViewSubscribers() {
|
export async function listsViewSubscribers() {
|
||||||
const browser = chromium.launch({
|
const browser = chromium.launch({
|
||||||
headless: headlessSet,
|
headless: headlessSet,
|
||||||
timeout: timeoutSet,
|
timeout: timeoutSet,
|
||||||
});
|
});
|
||||||
const page = browser.newPage();
|
const page = browser.newPage();
|
||||||
|
|
||||||
group('Lists - View subscribers of a list', () => {
|
try {
|
||||||
page
|
// Go to the page
|
||||||
.goto(`${baseURL}/wp-admin/admin.php?page=mailpoet-segments#/lists`, {
|
await page.goto(
|
||||||
|
`${baseURL}/wp-admin/admin.php?page=mailpoet-segments#/lists`,
|
||||||
|
{
|
||||||
waitUntil: 'networkidle',
|
waitUntil: 'networkidle',
|
||||||
})
|
},
|
||||||
|
);
|
||||||
|
|
||||||
.then(() => {
|
// Log in to WP Admin
|
||||||
authenticate(page);
|
authenticate(page);
|
||||||
})
|
|
||||||
|
|
||||||
.then(() => {
|
// Wait for async actions
|
||||||
return Promise.all([
|
await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle' })]);
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle' }),
|
|
||||||
]);
|
|
||||||
})
|
|
||||||
|
|
||||||
.then(() => {
|
// Click to view subscribers of the default list "Newsletter mailing list"
|
||||||
page.waitForSelector('[data-automation-id="dynamic-segments-tab"]');
|
page.waitForSelector('[data-automation-id="dynamic-segments-tab"]');
|
||||||
check(page, {
|
check(page, {
|
||||||
'segments tab is visible': page
|
'segments tab is visible': page
|
||||||
.locator('[data-automation-id="dynamic-segments-tab"]')
|
.locator('[data-automation-id="dynamic-segments-tab"]')
|
||||||
.isVisible(),
|
.isVisible(),
|
||||||
});
|
});
|
||||||
})
|
page
|
||||||
|
.locator('[data-automation-id="segment_name_' + defaultListName + '"]')
|
||||||
|
.hover();
|
||||||
|
page
|
||||||
|
.locator(
|
||||||
|
'[data-automation-id="view_subscribers_' + defaultListName + '"]',
|
||||||
|
)
|
||||||
|
.click();
|
||||||
|
|
||||||
.then(() => {
|
// Wait for the page to load
|
||||||
page
|
page.waitForSelector('.mailpoet-listing-no-items');
|
||||||
.locator(
|
page.waitForSelector('[data-automation-id="filters_subscribed"]');
|
||||||
'[data-automation-id="segment_name_' + defaultListName + '"]',
|
check(page, {
|
||||||
)
|
'subscribers filter is visible': page
|
||||||
.hover();
|
.locator('[data-automation-id="listing_filter_segment"]')
|
||||||
page
|
.isVisible(),
|
||||||
.locator(
|
});
|
||||||
'[data-automation-id="view_subscribers_' + defaultListName + '"]',
|
page.waitForLoadState('networkidle');
|
||||||
)
|
} finally {
|
||||||
.click();
|
page.close();
|
||||||
page.waitForSelector('.mailpoet-listing-no-items');
|
browser.close();
|
||||||
page.waitForSelector('[data-automation-id="filters_subscribed"]');
|
}
|
||||||
check(page, {
|
|
||||||
'subscribers filter is visible': page
|
|
||||||
.locator('[data-automation-id="listing_filter_segment"]')
|
|
||||||
.isVisible(),
|
|
||||||
});
|
|
||||||
page.waitForLoadState('networkidle');
|
|
||||||
})
|
|
||||||
|
|
||||||
.finally(() => {
|
|
||||||
page.close();
|
|
||||||
browser.close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
sleep(randomIntBetween(thinkTimeMin, thinkTimeMax));
|
sleep(randomIntBetween(thinkTimeMin, thinkTimeMax));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user