Skip to content

Commit

Permalink
Testing: Assign E2E login credentials explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 5, 2019
1 parent 29b3dc5 commit a7c76e0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/e2e-test-utils/src/login-user.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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' ) ] );
}

0 comments on commit a7c76e0

Please sign in to comment.