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

Use unique element locators for multiproxy selector on desktop and mobile #447

Closed
asnaith opened this issue Nov 30, 2023 · 2 comments · Fixed by #465
Closed

Use unique element locators for multiproxy selector on desktop and mobile #447

asnaith opened this issue Nov 30, 2023 · 2 comments · Fixed by #465
Assignees

Comments

@asnaith
Copy link
Member

asnaith commented Nov 30, 2023

At the moment we have to use .first when trying to interact with the multiproxySelector element eg:

topMenuItems.multiproxySelector().should('be.visible').first().click()

This is because two elements with that locator can be found in the DOM (the desktop and mobile one).

Let's give them unique names and update tests to get rid of the .first

@asnaith
Copy link
Member Author

asnaith commented Dec 12, 2023

After looking into this a little bit, I don't think this is because it's finding the selector from the desktop and mobile view.

I think it is more related to how it is rendered in the header (but can't work out exactly why).

I was able to set a unique locator for Desktop and Mobile eg

const theme = useTheme()
  const isDesktop = useMediaQuery(theme.breakpoints.up('md'))

  return (
    <Autocomplete
      className={className}
      isOptionEqualToValue={isOptionEqualToValue}
      disableClearable
      filterOptions={filterOptions}
      options={multiProxyList}
      renderOption={renderOptions}
      renderInput={renderInput}
      getOptionLabel={getOptionLabel}
      onChange={onChange}
      value={canFindMultiProxyFromUrl ? selectedMultiProxy || multiProxyList[0] : ''}
      data-cy={isDesktop ? 'select-multiproxy-desktop' : 'select-multiproxy-mobile'}
    />
  )

Which successfully set a unique one locator per layout (I set some custom viewports to check and saw the mobile one successfully applied).

However, when I removed the .first() from the element interactions in the test file I saw that Cypress would still find two of the select-multiproxy-desktop locators and I wasn't sure how to proceed.

@Tbaut
Copy link
Collaborator

Tbaut commented Dec 12, 2023

I checked and I'm certain that the issue was because of the dektop/mobile one. The mobile is hidden, but present in the DOM. I didn't use the exact same logic as you did, it's something a little simpler, since we have the info directly from the props depending on where this multiproxy selector is called.

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

Successfully merging a pull request may close this issue.

2 participants