Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPWebDriver: Wait for login form elements #65

Merged
merged 1 commit into from
Mar 9, 2017

Conversation

tangrufus
Copy link
Contributor

WPWebDriver::loginAs and WPWebDriver::loginAsAdmin should wait for form elements before submission. This explicit_wait prevents race conditions.

@calvinalkan
Copy link
Contributor

This costed me way too much time.

But I'm now 99% sure the issue happens because of this JS that WP runs on the login page.

function wp_attempt_focus() {setTimeout( function() {try {d = document.getElementById( "user_login" );d.focus(); d.select();} catch( er ) {}}, 200);}
wp_attempt_focus();
if ( typeof wpOnload === 'function' ) { wpOnload() }		

WP tries to auto-select the user login field which totally messes up how codeception fills out forms.

Current solution with the login cookies and retries is actually not the correct way to solve this.

@calvinalkan
Copy link
Contributor

This is what should be used:

$this->tester->waitForJS('return document.activeElement == document.getElementById("user_login")');

@calvinalkan
Copy link
Contributor

Also, include cases where PW is incorrect:

$this->tester->waitForJS("return (document.activeElement === document.getElementById('user_login')) || (document.activeElement === document.getElementById('user_pass'))");

@lucatume
Copy link
Owner

Thanks @calvinalkan for coming back to the issue and providing this.
I will review and include this new code in the next version of wp-browser (v4) based on Codeception v5.

This JS-based approach will work for the WPWebDriver module as the WPBrowser module does not have JS support hence not the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants