Merge pull request #29309 from woocommerce/fix/e2e-product-search
Fix flaky issues with e2e product filter, search, sort test
This commit is contained in:
commit
9352dd1b81
|
@ -21,8 +21,8 @@ const {
|
|||
const config = require( 'config' );
|
||||
const simpleProductName = config.get( 'products.simple.name' );
|
||||
const singleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
||||
const singleProductPrice2 = config.has('products.simple.price') ? config.get('products.simple.price') : '19.99';
|
||||
const singleProductPrice3 = config.has('products.simple.price') ? config.get('products.simple.price') : '29.99';
|
||||
const singleProductPrice2 = config.has('products.simple.price') ? '1' + singleProductPrice : '19.99';
|
||||
const singleProductPrice3 = config.has('products.simple.price') ? '2' + singleProductPrice : '29.99';
|
||||
const clothing = 'Clothing';
|
||||
const audio = 'Audio';
|
||||
const hardware = 'Hardware';
|
||||
|
@ -31,34 +31,32 @@ const productTitle = 'li.first > a > h2.woocommerce-loop-product__title';
|
|||
const runProductBrowseSearchSortTest = () => {
|
||||
describe('Search, browse by categories and sort items in the shop', () => {
|
||||
beforeAll(async () => {
|
||||
await merchant.login();
|
||||
// Create 1st product with Clothing category
|
||||
// Create 1st product with Clothing category
|
||||
await createSimpleProductWithCategory(simpleProductName + ' 1', singleProductPrice, clothing);
|
||||
// Create 2nd product with Audio category
|
||||
// Create 2nd product with Audio category
|
||||
await createSimpleProductWithCategory(simpleProductName + ' 2', singleProductPrice2, audio);
|
||||
// Create 3rd product with Hardware category
|
||||
// Create 3rd product with Hardware category
|
||||
await createSimpleProductWithCategory(simpleProductName + ' 3', singleProductPrice3, hardware);
|
||||
await merchant.logout();
|
||||
});
|
||||
|
||||
it('should let user search the store', async () => {
|
||||
await shopper.goToShop();
|
||||
await shopper.searchForProduct(simpleProductName + ' 1');
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'});
|
||||
});
|
||||
|
||||
it('should let user browse products by categories', async () => {
|
||||
// Browse through Clothing category link
|
||||
await Promise.all([
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'}),
|
||||
page.click('span.posted_in > a', {text: clothing}),
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'}),
|
||||
]);
|
||||
await uiUnblocked();
|
||||
|
||||
// Verify Clothing category page
|
||||
await page.waitForSelector(productTitle);
|
||||
await expect(page).toMatchElement(productTitle, {text: simpleProductName + ' 1'});
|
||||
await expect(page).toClick(productTitle, {text: simpleProductName + ' 1'});
|
||||
await uiUnblocked();
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'});
|
||||
await page.waitForSelector('h1.entry-title');
|
||||
await expect(page).toMatchElement('h1.entry-title', simpleProductName + ' 1');
|
||||
});
|
||||
|
|
|
@ -192,34 +192,18 @@ const createSimpleProduct = async () => {
|
|||
* @param categoryName Product's category which can be changed when writing a test
|
||||
*/
|
||||
const createSimpleProductWithCategory = async ( productName, productPrice, categoryName ) => {
|
||||
// Go to "add product" page
|
||||
await merchant.openNewProduct();
|
||||
const product = await factories.products.simple.create( {
|
||||
name: productName,
|
||||
regularPrice: productPrice,
|
||||
categories: [
|
||||
{
|
||||
name: categoryName,
|
||||
}
|
||||
],
|
||||
isVirtual: true,
|
||||
} );
|
||||
|
||||
// Add title and regular price
|
||||
await expect(page).toFill('#title', productName);
|
||||
await expect(page).toClick('#_virtual');
|
||||
await clickTab('General');
|
||||
await expect(page).toFill('#_regular_price', productPrice);
|
||||
|
||||
// Try to select the existing category if present already, otherwise add a new and select it
|
||||
try {
|
||||
const [checkbox] = await page.$x('//label[contains(text(), "'+categoryName+'")]');
|
||||
await checkbox.click();
|
||||
} catch (error) {
|
||||
await expect(page).toClick('#product_cat-add-toggle');
|
||||
await expect(page).toFill('#newproduct_cat', categoryName);
|
||||
await expect(page).toClick('#product_cat-add-submit');
|
||||
}
|
||||
|
||||
// Publish the product
|
||||
await expect(page).toClick('#publish');
|
||||
await uiUnblocked();
|
||||
await page.waitForSelector('.updated.notice', {text:'Product published.'});
|
||||
|
||||
// Get the product ID
|
||||
const variablePostId = await page.$('#post_ID');
|
||||
let variablePostIdValue = (await(await variablePostId.getProperty('value')).jsonValue());
|
||||
return variablePostIdValue;
|
||||
return product.id;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue