Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Remove and address sleep statement in wp-admin-jetpack-page.js #1739

Closed
wants to merge 2 commits into from

Conversation

juliaamosova
Copy link
Contributor

Removed and addressed sleep statement with a for loop that checks if the Connect Jetpack button ID matches with the currently active element ID (element in focus).

I used the JavaScriptExecutor to get the focus on the button - as far as I know, there is no other way to do it using webdriver. JavaScriptExecutor is not ideal because it doesn't return anything (or rather returns undefined) but it does the job when the action needs to be made.

I also looked at doing the following:

  1. Rewrite existing waitTillFocused function but I didn't want to use JavaScriptExecutor in it (for the reason described above) so I passed on that option;

  2. Make a separate function out of the loop I wrote but the JavaScriptExecutor stopped me again. It gets the element using getElementsByClassName which can not always be applied to all elements. I passed on this option as well.

After considering the 2 options above, I decided to leave the loop as one-time use.

To test:

The change affects the following specs:

  • wp-jetpack-onboarding-spec.js
  • wp-jetpack-connect-spec.js
  • connect-disconnect-spec.js
  • jetpack-connect-flow.js which is a part of gutenberg-markdown-block-spec.js

Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few minor nitpicks about the code, but in general, this approach might not be sustainable enough. The button itself will be replaced with the new button, which may or may not have the same problem as the old one.

@@ -4,6 +4,9 @@ import { By } from 'selenium-webdriver';

import * as driverHelper from '../../driver-helper';
import AsyncBaseContainer from '../../async-base-container';
import config from 'config';

const explicitWaitMS = config.get( 'explicitWaitMS' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitWaitMS is available inside any PageObject via this.explicitWaitMS: https://github.com/Automattic/wp-e2e-tests/blob/master/lib/async-base-container.js#L22

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks @brbrr 👍

@@ -13,8 +16,23 @@ export default class WPAdminJetpackPage extends AsyncBaseContainer {

async connectWordPressCom() {
const selector = By.css( 'a.jp-jetpack-connect__button' );
const pauseBetweenFocusAttemptsMS = 200;
const connectJetpackButtonFocus =
"document.getElementsByClassName( 'jp-jetpack-connect__button')[0].focus();";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I'm not quite sure what the problem you trying to fix here, but the connection button will be changed: Automattic/jetpack#8618.

Is the issue you trying to fix is somehow related to the fact that button not doing what it should right after page load? It might be a good idea to fix this on Jetpack side instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue you trying to fix is somehow related to the fact that button not doing what it should right after page load? It might be a good idea to fix this on Jetpack side instead.

I am trying to remove and address the sleep statement. It was originally added here with no explanation why:

https://github.com/Automattic/wp-e2e-tests/pull/584/files#diff-e88aeb376f9b63bf70f5877bdece3966R14

My guess is that the test runs too fast and clicks on the button when it is not ready to be clicked on yet. I was not able to reproduce it locally though.

Since you mentioned the button will be changed, it makes sense to see if the issue will be present after the change takes affect. What do you think?

.switchTo()
.activeElement()
.getId();
let connectJetpackButtonId = await ( await this.driver.findElement( selector ) ).getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these params around findElement is needed? I think chained call with single await should do the job

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, single await would do the job here. Thanks for catching it!

await driverHelper.waitTillPresentAndDisplayed( this.driver, selector );
await this.driver.sleep( 1000 );
for ( let i = 0; i < explicitWaitMS / pauseBetweenFocusAttemptsMS; i++ ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for loop might be replaced with driver.wait function? They seem like quite similar

@juliaamosova
Copy link
Contributor Author

Closing this PR since a.jp-jetpack-connect__button will be removed soon as per here (after Jetpack 6.9 release):

https://github.com/Automattic/wp-e2e-tests/blob/master/lib/pages/wp-admin/wp-admin-jetpack-page.js#L15

The situatuation around sleep statement will be changed as well. Correcting it as-is now seems reduntant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
[Status] Needs Jetpack e2e Testing Run full Jetpack e2e suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants