webkitdirectory upload in headless Capybara test - capybara

I have a file upload control in my UI marked with webkitdirectory. When I upload a folder in the following way, running in non-headless mode, it works:
find('.directory-upload', visible: false).set(Rails.root + "test/data/directory_to_upload")
However, when I run headless (with the :headless_chromium driver) it fails silently, i.e. the code runs but the directory isn't actually selected in the control (so the ensuing form validation fails).
Are there differences in supported HTML between headless and non-headless that could explain this?

You've run into a known bug in headless Chrome - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2521&q=directory%20upload&colspec=ID%20Status%20Pri%20Owner%20Summary - nothing your can really do about it.

Related

Why is my Dockerized Browserless-Chrome hanging when a Mediawiki Selenium test causes a new page to be loaded?

Background
I have a makefile which fetches and spins up a Dockerized Mediawiki instance on my local machine, from scratch, with a single make command:
https://gitlab.wikimedia.org/mhurd/mediawiki-docker-make
This works fairly well. Please try it!
Goal
I'd also like to be able to run Mediawiki's Selenium tests (as-is) in Docker containers and watch them execute "live", with the makefile, again, making it easy to kick this process off.
Approach
This work-in-progress branch adds a container for running Mediawiki Selenium tests, and a browserless-chrome container so you can watch and debug the tests "live", as they run:
https://gitlab.wikimedia.org/mhurd/mediawiki-docker-make/-/tree/selenium
As you can see from the top of this branch's readme, after running make to spin everything up, running make runseleniumtests kicks the tests off. When doing so a browser window is automatically opened which lets you see the Selenium tests which are running in the browserless-chrome container. This works... to a point.
Problem
Unfortunately, after a few tests are seen to be running, I'm seeing this error:
Protocol error (Input.dispatchMouseEvent): Target closed.

I suspect the way the browserless-chrome container manages its Chrome sessions may be to blame, as it appears the error is happening when a test causes a new page to be loaded, but I'm not sure.
Any ideas appreciated, and please try it yourself - the whole point of the makefile is to make spinning this up from scratch super simple. It only takes a couple commands and you should be able to see the tests running and the resulting error. Thanks!
Misc
Running curl -s http://127.0.0.1:3000/sessions | python3 -m json.tool on the host machine after attempting to run the tests shows there are multiple browserless-chrome sessions, but I'm unsure how to make it behave more like a non-dockerized setup - which has no problem with tests which cause page loads.
In email communication with Browserless support, they mention seeing similar issues but haven't been able to track down why:
It seems to be that the root cause may be due to "click" events aren't
working properly when your viewing the live debugger. Can you confirm
that if you don't open the live viewer, it allows the test to progress
and eventually throws new errors regarding selectors not being found? (Edit: I did)
I've also run into this live debugger behavior before and in my
experience I stopped watching the live debugger, and since I couldn't
see which selector it wasn't finding I exported a screenshot and in
that particular case, it ended up being an issue with my viewport,
since the viewport in the remote session was smaller, the styles
rendered differently then locally on my machine, when I set the
viewport size, the selectors were found - but then again, that was my
particular issue, might not be yours.
But yes, for some odd reason when you view live sessions, you can run
into this odd issue which we haven't been able to understand.

Cucumber testing on WSL2 not showing UI for Google Chrome

I'm testing my Rails project and there are some problems when the test is running.
cucumber features/test.feature
I have installed chromedriver for WSL2 and the test can run fine. However, the browser showing up is not rendered at all, it only has a border and transparent body like this.
I can still open google-chrome and it is displayed correctly. And the project used to work on WSL1. I can also take screenshots when testing, it's just that the browser's UI is not rendered.
I have installed the driver for GPU as stated in the WSL guide but the problem still persisted.
Has anyone encountered this problem and how can I fix it? Thank you very much.

Selenium jobs not running on jenkins CI server

We have automated 5 test cases and ran locally and seems to be worked fine. When the same code base is running on CI server(linux box against firefox browser), It failed to execute. However I used xming to see the GUI execution part and observed the browser is keep on loading and not displayed any web element to perform action. I just cross check with whether its proxy issue, and handled through code as below: (Due to security issue I can't able to share proxy details, but I pinged It returned proper response.)
Sample Code(created firefox profile):
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "someproxy.com");
profile.setPreference("network.proxy.http_port", 8090);
//Other dependencies like "No Proxy for" is added in firefox.
profile.setPreference("network.proxy.no_proxies_on","localhost, 127.1.1.1, prt-www.xxx.com, ti.xxx.com, s3, xxx.com" );
DesiredCapabilities desired = DesiredCapabilities.firefox();
desired.setCapability(FirefoxDriver.PROFILE, profile);
I really don't understand the root cause for this issue. Can somebody tell me what would be the root cause for this issue?
I check the firewall in that box , and It has been stopped.

Can I see what happens in PhantomJS?

Sometimes, when running automated tests in PhantomJS using Cucumber for Rails 4, it would be really, really useful to actually sit in front of my screen, look in a window, and see exactly what the browser is doing.
There are times when your code is right and your test is right, but testing fails intermittently nonetheless. It's often because of a script, or an animation, or some CSS that gets in the way. But seeing a screenshot, drilling into a DOM inspector, or using the debugger is not enough to catch those edge cases.
Is there any way to have a window looking at what PhantomJS is doing in the background? It could be something in X Window, or running in a VNC Server, etc. Anything visual would greatly help with debugging, especially in with those finicky details.
I found a little program called PhantomVNC, but it's not telling me much on how it works. It looks like something just feeding a series of screenshots through VNC.
I tried PhantomJS and Capybara-WebKit, but neither of those headless browsers other a "head" option. Selenium-WebDriver seems complicated to set up and only seems to work with a full browser like Firefox, and that may cause more problems than it solves.
If you have any ideas, please let me know. Thank you in advance.
Not sure specifically about Cuc/Rails - but I specifically have a second chrome/webdriver Virtual Machine for this. I use PhantomJS specifically for the headless automatic acceptance testing, but when there is an issue with the tests and I'm trying to diagnose it can be helpful to view the browser live.
In other words, spin up a Ubuntu desktop VM, install chrome, install selenium server and the chrome webdriver. Log in to the VM, open chrome, make sure selenium is running, then configure your test suite to connect to the selenium webdriver service (usually port :4444) of this instance. Run your tests and you should be able to watch the chrome instance on the VM.

How to prevent Firefox from starting in safe mode?

Running a Rails test suite with Selenium often opens Firefox with the "Start in Safe Mode?" dialog. Is there a way to either 1) disable this, or 2) add a script that will answer "No" if the dialog appears?
It appears to be related to some open Firefox issues. Please see here:
Disable/Change Firefox Safe Mode Hotkey (Shift)
If you're looking for an alternative to selenium and Firefox, I've had success with PhantomJS (a headless WebKit browser) and the poltergeist gem.
For 1)Disable this:
You can create your own custom profile.
For 2)Add a script to answer 'NO'
Use Autoit to write a script for answering NO and use that in your selenium program.

Resources