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

fix(tests): contextMenuSelect sometimes clicks the wrong block #7485

Merged
merged 7 commits into from
Sep 13, 2023

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

The details

Resolves

Fixes #7484

Proposed Changes

  • Add a helper function that tags the first label field on a block, then uses that to get that element as a Webdriverio Element.
  • Change context menu helper function to take in a block ID instead of a block element.
  • Use the helper function in all context menu tests and in block deletion tests.

Reason for Changes

Fix issues with clicking when the block's path is occluded or has a hole in it.

Test Coverage

Ran browser tests and watched for unexpected behaviour.

Documentation

I added JSDoc

Additional Information

  • You could run into issues if you used this function twice, on different blocks, within the same test context. In that case the solution is to add a helper that removes the ID from the SVG element. This seems not worth adding unless/until it becomes an issue.
  • There are other tests that click on blocks and have not previously had any issues. I left them in their current state (clicking on the block's SVG root). I don't see a benefit to updating them to use the more complicated helper function unless they break.
    • I could be convinced otherwise just for consistency.

* have text on it, because we use the text element as the click target.
* @param itemText The display text of the context menu item to click.
* @return A Promise that resolves when the actions are completed.
*/
async function contextMenuSelect(browser, block, itemText) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I think it's easiest if we pass the block element (which has an ID property) around to all of our helpers. This makes the code more consistent, and makes it easier for us to refactor the test helpers if we need to, because it's less likely we have to change test code as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is true for cases where we're creating the blocks by dragging from the flyout but false for cases where we create blocks by loading from JSON or XML. In the tests above, all of the basic playground tests and some of the delete tests create blocks from the flyout, but the other delete tests load from XML and just use a block ID to find the blocks. As I see it, every time we have a handle on a block we also have a handle on the block's ID, but the opposite is not guaranteed to be true.

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for those cases you can just get the block by ID using our helper for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 139 to 140
const clickEl = await getClickableBlockElementById(this.browser, firstBlockId);
await clickEl.click();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of calling this and then calling click could you create a clickBlock helper that does this and then removes the special ID? Then it cleans up after itself, and I think the code would be easier to read. If the clickBlock helper takes in the same options as click you could also use it from the context menu code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 159 to 163
* Get a clickable element on the block. We can't always use the block's SVG root
* because clicking will always happen in the middle of the block's bounds
* (including children) by default, which causes problems if it has holes
* (e.g. statement inputs). Instead, this tries to get the first text field on the
* block. It falls back on the block's SVG root.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Appreciate the detailed english description here!

* @return A Promise that resolves to the text element of the first label
* field on the block, or the block's SVG root if no label field was found.
*/
async function getClickableBlockElementById(browser, id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly would like to pass the block here instead of the ID.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@rachel-fenichel rachel-fenichel changed the title Clickable element fix(tests): contextMenuSelect sometimes clicks the wrong block Sep 12, 2023
@github-actions github-actions bot added the PR: fix Fixes a bug label Sep 12, 2023
@rachel-fenichel
Copy link
Collaborator Author

Updated per your suggestions. PTAL.

@rachel-fenichel rachel-fenichel merged commit 00d870e into google:develop Sep 13, 2023
7 checks passed
@rachel-fenichel rachel-fenichel deleted the clickableElement branch September 13, 2023 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contextMenuSelect clicks on the wrong block
2 participants