Merge pull request #29939 from woocommerce/e2e/remove-merchant-ui-login

Remove merchant login/logout calls
This commit is contained in:
Greg 2021-05-22 10:06:33 -06:00 committed by GitHub
commit 7c5fd005fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 60 additions and 50 deletions

View File

@ -1,50 +1,52 @@
import { SimpleProduct, Coupon } from '@woocommerce/api';
import {
visitAdminPage,
switchUserToTest,
clearLocalStorage,
setBrowserViewport,
withRestApi,
WP_ADMIN_LOGIN
} from '@woocommerce/e2e-utils';
const { merchant } = require( '@woocommerce/e2e-utils' );
const config = require('config');
const { HTTPClientFactory } = require('@woocommerce/api');
/**
* Navigates to the post listing screen and bulk-trashes any posts which exist.
*
* @return {Promise} Promise resolving once posts have been trashed.
* Uses the WordPress API to delete all existing posts
*/
async function trashExistingPosts() {
await merchant.login();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
await visitAdminPage( 'edit.php' );
const apiUrl = config.get('url');
const wpPostsEndpoint = '/wp/v2/posts';
const adminUsername = config.get('users.admin.username');
const adminPassword = config.get('users.admin.password');
const client = HTTPClientFactory.build(apiUrl)
.withBasicAuth(adminUsername, adminPassword)
.create();
// If this selector doesn't exist there are no posts for us to delete.
const bulkSelector = await page.$( '#bulk-action-selector-top' );
if ( ! bulkSelector ) {
return;
// List all existing posts
const response = await client.get(wpPostsEndpoint);
const posts = response.data;
// Delete each post
for (const post of posts) {
await client.delete(`${wpPostsEndpoint}/${post.id}`);
}
// Select all posts.
await page.waitForSelector( '#cb-select-all-1' );
await page.click( '#cb-select-all-1' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
await page.click( '#doaction' );
await page.waitForXPath(
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
);
await switchUserToTest();
}
// Before every test suite run, delete all content created by the test. This ensures
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
// each other's side-effects.
beforeAll( async () => {
beforeAll(async () => {
await trashExistingPosts();
await withRestApi.deleteAllProducts();
await withRestApi.deleteAllCoupons();
await page.goto(WP_ADMIN_LOGIN);
await clearLocalStorage();
await setBrowserViewport( 'large' );
} );
await setBrowserViewport('large');
});
// Clear browser cookies and cache using DevTools.
// This is to ensure that each test ends with no user logged in.
afterAll(async () => {
const client = await page.target().createCDPSession();
await client.send('Network.clearBrowserCookies');
await client.send('Network.clearBrowserCache');
});

View File

@ -24,6 +24,10 @@ const shippingZoneNameUS = config.get( 'addresses.customer.shipping.country' );
const runOnboardingFlowTest = () => {
describe('Store owner can go through store Onboarding', () => {
beforeAll(async () => {
await merchant.login();
});
if ( IS_RETEST_MODE ) {
it('can reset onboarding to default settings', async () => {
await withRestApi.resetOnboarding();
@ -48,6 +52,10 @@ const runOnboardingFlowTest = () => {
const runTaskListTest = () => {
describe('Store owner can go through setup Task List', () => {
beforeAll(async () => {
await merchant.login();
});
it('can setup shipping', async () => {
await page.evaluate(() => {
document.querySelector('.woocommerce-list__item-title').scrollIntoView();

View File

@ -27,6 +27,9 @@ const {
const runInitialStoreSettingsTest = () => {
describe('Store owner can finish initial store setup', () => {
beforeAll(async () => {
await merchant.login();
});
it('can enable tax rates and calculations', async () => {
// Go to general settings page

View File

@ -4,13 +4,13 @@
* Internal dependencies
*/
const {
merchant,
createSimpleProduct,
createSimpleOrder,
createCoupon,
uiUnblocked,
addProductToOrder,
evalAndClick,
merchant
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
@ -26,10 +26,12 @@ let orderId;
const runOrderApplyCouponTest = () => {
describe('WooCommerce Orders > Apply coupon', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
couponCode = await createCoupon();
await merchant.login();
orderId = await createSimpleOrder('Pending payment', simpleProductName);
await Promise.all([
addProductToOrder(orderId, simpleProductName),

View File

@ -20,8 +20,9 @@ let orderId;
const runMerchantOrdersCustomerPaymentPage = () => {
describe('WooCommerce Merchant Flow: Orders > Customer Payment Page', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
await merchant.login();
orderId = await createSimpleOrder();
await addProductToOrder( orderId, simpleProductName );

View File

@ -45,8 +45,9 @@ const clickAndWaitForSelector = async ( buttonSelector, resultSelector ) => {
const runRefundOrderTest = () => {
describe('WooCommerce Orders > Refund an order', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
await merchant.login();
orderId = await createSimpleOrder();
await addProductToOrder(orderId, simpleProductName);

View File

@ -15,8 +15,8 @@ let productId;
const runProductEditDetailsTest = () => {
describe('Products > Edit Product', () => {
beforeAll(async () => {
await merchant.login();
productId = await createSimpleProduct();
await merchant.login();
});
it('can edit a product and save the changes', async () => {

View File

@ -15,11 +15,12 @@ const simpleProductPrice = config.has('products.simple.price') ? config.get('pro
const runProductSearchTest = () => {
describe('Products > Search and View a product', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
// Make sure the simple product name is greater than 1 to do a search
await expect(simpleProductName.length).toBeGreaterThan(1);
await merchant.login();
});
beforeEach(async () => {

View File

@ -34,8 +34,8 @@ const shippingZoneNameSF = 'SF with Local pickup';
const runAddNewShippingZoneTest = () => {
describe('WooCommerce Shipping Settings - Add new shipping zone', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
await merchant.login();
await deleteAllShippingZones();
});

View File

@ -40,9 +40,10 @@ const shippingCountryFR = 'country:FR';
const runCartCalculateShippingTest = () => {
describe('Cart Calculate Shipping', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct(firstProductName);
await createSimpleProduct(secondProductName, secondProductPrice);
await merchant.login();
await merchant.openNewShipping();
// Add a new shipping zone Germany with Free shipping

View File

@ -4,7 +4,6 @@
*/
const {
shopper,
merchant,
createCoupon,
createSimpleProduct,
uiUnblocked,

View File

@ -28,10 +28,10 @@ const runCartRedirectionTest = () => {
describe('Cart > Redirect to cart from shop', () => {
let simplePostIdValue;
beforeAll(async () => {
await merchant.login();
simplePostIdValue = await createSimpleProduct();
// Set checkbox in settings to enable cart redirection
await merchant.login();
await merchant.openSettings('products');
await setCheckbox('#woocommerce_cart_redirect_after_add');
await settingsPageSaveChanges();

View File

@ -4,7 +4,6 @@
*/
const {
shopper,
merchant,
createSimpleProduct,
uiUnblocked
} = require( '@woocommerce/e2e-utils' );
@ -26,9 +25,7 @@ const twoProductPrice = singleProductPrice * 2;
const runCartPageTest = () => {
describe('Cart page', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
await merchant.logout();
});
it('should display no item in the cart', async () => {

View File

@ -4,7 +4,6 @@
*/
const {
shopper,
merchant,
createCoupon,
createSimpleProduct,
uiUnblocked,

View File

@ -26,10 +26,10 @@ const simpleProductName = config.get('products.simple.name');
const runCheckoutLoginAccountTest = () => {
describe('Shopper Checkout Login Account', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
// Set checkbox for logging to account during checkout
await merchant.login();
await merchant.openSettings('account');
await setCheckbox('#woocommerce_enable_checkout_login_reminder');
await settingsPageSaveChanges();

View File

@ -27,10 +27,10 @@ let customerOrderId;
const runCheckoutPageTest = () => {
describe('Checkout page', () => {
beforeAll(async () => {
await merchant.login();
await createSimpleProduct();
// Set free shipping within California
await merchant.login();
await addShippingZoneAndMethod('Free Shipping CA', 'state:US:CA', ' ', 'free_shipping');
// Go to general settings page
await merchant.openSettings('general');

View File

@ -17,9 +17,7 @@ const simpleProductName = config.get( 'products.simple.name' );
const runMyAccountPayOrderTest = () => {
describe('Customer can pay for their order through My Account', () => {
beforeAll(async () => {
await merchant.login();
simplePostIdValue = await createSimpleProduct();
await merchant.logout();
await shopper.login();
await shopper.goToProduct(simplePostIdValue);
await shopper.addToCart(simpleProductName);

View File

@ -10,7 +10,6 @@ const {
const runMyAccountPageTest = () => {
describe('My account page', () => {
it('allows customer to login', async () => {
await merchant.logout();
await shopper.login();
await expect(page).toMatch('Hello');
await expect(page).toMatchElement('.woocommerce-MyAccount-navigation-link', {text: 'Dashboard'});

View File

@ -29,9 +29,10 @@ const {
const runOrderEmailReceivingTest = () => {
describe('Shopper Order Email Receiving', () => {
beforeAll(async () => {
simplePostIdValue = await createSimpleProduct();
await merchant.login();
await deleteAllEmailLogs();
simplePostIdValue = await createSimpleProduct();
await merchant.logout();
});

View File

@ -20,9 +20,7 @@ const simpleProductName = config.get( 'products.simple.name' );
const runSingleProductPageTest = () => {
describe('Single Product Page', () => {
beforeAll(async () => {
await merchant.login();
simplePostIdValue = await createSimpleProduct();
await merchant.logout();
});
it('should be able to add simple products to the cart', async () => {