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

[🐛 Bug]: selenium seems to override _, breaking another package #12659

Closed
stefanoborini opened this issue Sep 1, 2023 · 15 comments · Fixed by #12704
Closed

[🐛 Bug]: selenium seems to override _, breaking another package #12659

stefanoborini opened this issue Sep 1, 2023 · 15 comments · Fixed by #12704
Labels
I-defect Something is not working as intended
Milestone

Comments

@stefanoborini
Copy link

stefanoborini commented Sep 1, 2023

What happened?

I am facing a very difficult debugging situation, and I'll gather as many information as I can.

We are using a package called shinyMatrix, together with an R shiny application. Everything is quite dynamic, with matrices widgets generated on the fly. We know that shinyMatrix uses, under the hood, Vue.

What I see is that if I run the test under selenium, and only under selenium, I get the following error in Chrome console

image

After some debugging and watch of the _ variable, I found that the following snippet of code seem to remap _ to a different function

image

It's quite hard to say what's going on, because it's all minified. I was able to trace down that file to verbatim code part of the ruby bindings (I am using the python bindings):

grep -r "allowfullscreen allowpaymentrequest" *
rb/lib/selenium/webdriver/atoms/getAttribute.js:<SNIP> {"class":"className",readonly:"readOnly"},dd="allowfullscreen allowpaymentrequest allowusermedia async autofocus autoplay checked compact complete controls declare default defaultchecked defaultselected defer disabled ended formnovalidate hidden indeterminate iscontenteditable ismap itemscope loop multiple muted nohref nomodule noresize noshade novalidate nowrap open paused playsinline pubdate readonly required reversed scoped seamless seeking selected truespeed typemustmatch willvalidate".split(" ");ba("_",function(a,b){var<SNIP>

The resulting effect of the overwrite is that this function in shinymatrix is no longer able to find the lodash utility function cloneDeep:

image

I don't know if this is a selenium problem, a Vue problem, a shiny problem, or a shinyMatrix problem. For now the most likely culprit seems to be selenium, but I might have to investigate further if you have more information about what's going on.

How can we reproduce the issue?

Hard to reproduce without my full code, but I am using a very simple script:

import time
from selenium import webdriver
from uidriver.widgets.shiny import Selector, Tabset

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(2)
driver.get("http://localhost:8888")
time.sleep(10)
Selector(driver).id("redacted").select("2")
Selector(driver).id("redacted2").select("redacted")
Tabset(driver).index(1).click_tab("redacted")
time.sleep(1000)

The Selector and Tabset are basically classes I developed to simplify the access. In the end, they are fancy wrappers for a find_element with a By.XPATH and click(). The Tabset change should make the shinyMatrix appear, but the error actually occurs already at the point of the second selector.

Relevant log output

See above.

Operating System

macOS 13.5.1

Selenium version

selenium==4.11.2 on python 3.11

What are the browser(s) and version(s) where you see this issue?

Chrome 116.0.5845.110

What are the browser driver(s) and version(s) where you see this issue?

Downloaded by selenium

Are you using Selenium Grid?

No response

@stefanoborini stefanoborini added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Sep 1, 2023
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

@stefanoborini, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

Sounds like you are wrapping the Select class, which currently injects the atom you referenced instead of using an endpoint. I made a PR to address it. Not sure what your actual issue is, but maybe that will fix it.

The alternative is to implement your own Select wrapping.

@mantas
Copy link

mantas commented Sep 1, 2023

I run into the same issue today. My tests fail after Selenium update with error saying that _.functionName is not a function. Everything works fine with Selenium 4.11.0 ruby gem. But updating to 4.12.0 seems to break it.

Looks like _ sign is overwritten by Selenium?

@mdmintz
Copy link
Contributor

mdmintz commented Sep 2, 2023

I discovered that the seleniumbase Vue tests failed due to selenium 4.12.0, with _ being overwritten by Selenium.

Screenshot 2023-09-02 at 8 53 39 AM

@titusfortner
Copy link
Member

Ok, sounds like it isn't just getAttribute, but also getDisplayed, so my PR is not an actual solution to this problem.

To get an attribute or to check if an element is displayed, Selenium executes large chunks of JS called "atoms" using the execute/sync endpoint to run inside the browser. These are generated at build time using the Google Closure Compiler. That part of the codebase is not my area of expertise, so I'll track down people who might know how to address the issue.

@diemol diemol removed the A-needs-triaging A Selenium member will evaluate this soon! label Sep 4, 2023
@DomZZ
Copy link

DomZZ commented Sep 6, 2023

I run into the same issue today. My tests fail after Selenium update with error saying that _.functionName is not a function. Everything works fine with Selenium 4.11.0 ruby gem. But updating to 4.12.0 seems to break it.

Looks like _ sign is overwritten by Selenium?

Same for me into dotnet project and nuget Selenium.Support 4.12.4.
image

@shs96c
Copy link
Member

shs96c commented Sep 6, 2023

Is there a public site that demonstrates this problem? Would be helpful to allow us to investigate further, though I guess we can just check what happens if we have a _ variable in a page (though it'd be helpful to know if that was a global or local variable)

@mantas
Copy link

mantas commented Sep 6, 2023

Loading UnderscoreJS via a simple script tag seems to be enough to replicate this.

@baflQA
Copy link
Contributor

baflQA commented Sep 7, 2023

I've spent last 8h and lost 1532 hairs before I got to know about this issue.
It's a serious one, I must say.

@baflQA
Copy link
Contributor

baflQA commented Sep 7, 2023

@jlipps could it be something related to your recent changes to atoms code, e.g. eea09a6 ?

@jlipps
Copy link
Contributor

jlipps commented Sep 7, 2023

that change wouldn't have any impact that i can see. #12557 would potentially be more likely given that it references this._, and this might be window. still seems a stretch, but it would be easy enough to roll back that commit and see if it solves the problem.

@nvborisenko
Copy link
Member

We have easy steps to reproduce it:

// open browser via selenium
// navigate to google.com
// find any element
// check whether the element is displayed (actually inject atoms)

After these steps _ object is overridden.

@nvborisenko
Copy link
Member

I reverted that change #12557, built locally, tested, and the issue disappeared.

@mdmintz
Copy link
Contributor

mdmintz commented Sep 7, 2023

PR ready to revert the change that caused the issue: #12704

Copy link

github-actions bot commented Dec 5, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I-defect Something is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants