From 1e31940ef35612c7687aa960ab6fe755a59f358a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 5 Mar 2019 14:13:09 -0500 Subject: [PATCH] Testing: Assign E2E login credentials explicitly --- packages/e2e-test-utils/src/login-user.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/e2e-test-utils/src/login-user.js b/packages/e2e-test-utils/src/login-user.js index 8c7063ee940cb..8ec49b80bc0c7 100644 --- a/packages/e2e-test-utils/src/login-user.js +++ b/packages/e2e-test-utils/src/login-user.js @@ -1,11 +1,9 @@ - /** * Internal dependencies */ import { WP_USERNAME, WP_PASSWORD } from './shared/config'; import { createURL } from './create-url'; import { isCurrentURL } from './is-current-url'; -import { pressKeyWithModifier } from './press-key-with-modifier'; /** * Performs log in with specified username and password. @@ -20,12 +18,16 @@ export async function loginUser( username = WP_USERNAME, password = WP_PASSWORD ); } - await page.focus( '#user_login' ); - await pressKeyWithModifier( 'primary', 'a' ); - await page.type( '#user_login', username ); - await page.focus( '#user_pass' ); - await pressKeyWithModifier( 'primary', 'a' ); - await page.type( '#user_pass', password ); + // Explicitly assign values of form, since the username is prefilled if + // already logged in. This could be done by keyboard interactions as well, + // but as of Puppeteer 1.6.1, Cmd+A does not work as expected in Mac, + // making it difficult to erase the contents of the field. + // + // See: https://github.com/GoogleChrome/puppeteer/issues/1313 + await page.evaluate( ( _username, _password ) => { + document.getElementById( 'user_login' ).value = _username; + document.getElementById( 'user_pass' ).value = _password; + }, username, password ); await Promise.all( [ page.waitForNavigation(), page.click( '#wp-submit' ) ] ); }