Mink and Behat: Is there a way to launch selenium (Chrome) in background? - behat

When running tests, I would like not to be bothered by Chrome popping-up every time Behat launches a scenario needing Chrome.
I know there is a maximizeWindow() method for session objects, but nothing like "minimize".

Nowadays, you can set Chrome to run in headless mode like so (behat.yml):
default:
extensions:
Behat\MinkExtension:
javascript_session: browser
sessions:
browser:
selenium2:
browser: chrome
capabilities:
chrome:
switches:
- "--headless"

You could run Chrome with a virtual framebuffer, so that the window appears on a virtual screen instead of your real screen.
This also allows to easily run your tests on a headless machine, such as a build server.
On Linux, we're using xvfb for this particular purpose. More info: How To Run Your Tests Headlessly with Xvfb
For Windows, see Is there anything like xvfb or xnest for Windows?

Seems there is no method for launching in background. maximizeWindow is for setting the resolution.
You should try to run in a virtual machine or on another PC in order to avoid this kind of issues, popups and interacting by mistake with the window that runs automation.
Running on the same machine should be done when writing new tests and when debugging.

I found an acceptable solution for this that didn't require me to run Chrome headless or in a virtual machine.
Simply log in with a secondary user account on your local machine, and run selenium on that account. Then, switch back to your main user account and run your tests. The chrome browser will be created under the user running selenium and you will never see the chrome windows pop up.

Related

Selenium works when started locally, but not remotely

I'm hoping this is a simple issue to solve:
I have a dedicated machine that runs selenium with chromedriver. I can physically walk to the machine and type the following in a local terminal:
java -Dwebdriver.chrome.driver=chromedriver238 -jar selenium-server-3.11.jar
I can then go to any other machine on the network and kick off testing (in my case, codeception on jenkins) and it will sucessfully run my tests in chrome without a hitch.
However, if I try to run the above command without physically being at the selenium machine (ex, trying to ssh into the machine to run the command or making this command run as part of a supervisor process) then selenium has trouble starting the instance of chrome.
Has anyone run into this scenario before? Is there a way I can give 'interactive' access to the background script to allow it to open stuff on my screen?
Because when you physically walk to the machine and run the command. the selenium can get the desktop/window interface.
When use SSH, selenium lost the desktop/window interface, selenium have to start chrome under headless model, but your code not config to run as headless model. So the conflict come out.
you need to config your code to run with headless model.
I'm to getting the same scenario, when i try to start the selenium code on the machine A it works yet when i try to start selenium and run the scripts from machine B
(remotely connecting to machine A using ssh [ssh test#machine-a]) chrome instance doesn't start/launch and driver is getting null.
logs :
2020-02-27 12:04:27,319 INFO [LogWritter] Exception in beforeclass chrome driver instantiation , driver is null
2020-02-27 12:04:27,493 INFO [LogWritter] Exception in getting screenshot---java.awt.AWTException: headless environment
Any help/suggestion would be great !

WebDriverException: Element is not clickable at point

Complete error
org.openqa.selenium.WebDriverException: Element is not clickable at
point (931, 23). Other element would receive the click:
Running selenium tests using Jenkins in headless browser
In following environment
OS- CentOS 6 and Xvfb installed in same machine
Xvfb screen resolution - Xvfb :1 -screen 0 1280x1024x16 &
Driver - Firefox driver
Selenium webdriver version - 2.52.0
The same test case working fine in windows os with firefox
Try this. Install Xvfb plugin on Jenkins.
After that install Xvfb in "Global Tool Configuration"
Then under your project configuration, setup xvfb
Try Using resolution given in image
Now run your build :)
This is the reason it is important to test on different browsers and on different platforms. Sometimes what works on one browser/os does not work on the same browser but a different platform.
I would update your setup so that you make a screenshot when you run into this type (and most other types) of error. In my experience this is the single best thing you can do to reduce the time spent to debug these issues.
In my setup I do the following:
Create a screenshot
Capture the coordinates from the Selenium error message
Use an image manipulation program to automatically create a red dot where the click happened
Usually I just have to take one look at such an image to see exactly what is happening.

How can I run Chrome headless from protractor WITHOUT using a Selenium server

I have Chrome working headless via a Selenium server by running xvfb bound to DISPLAY:10 and then running Selenium with a DISPLAY=:10 webdriver-manager start. So that's all fine.
I also have Chromedriver running directly from protractor by specifying directConnect: true in my protractor.conf.
What I'd like to do is a combination of the two, ie. run chromedriver directly (NO SELENIUM!), but somehow instruct it to run headless on DISPLAY :10.
In terms of topology, everything is run on the developer's PC. There are no servers involved. In a comment below, I mention a node server: this is being used to launch protractor instead of the more usual launching from the command line. I want protractor to be running on DISPLAY:0 so I can see its output, test failures etc. When it spawns chrome using chromedriver, I want chrome to be running on DISPLAY:10. My reason for doing this is that I want the chrome window to be bigger than my physical screen. See How can I screenshot the full height of a mobile form factor? for background.
I'm guessing the topology is like this:
Box A: xvfb, DISPLAY=:10, Selenium Server, chromedriver
Box B: DISPLAY=:0, node, protractor (directConnect: true), chromedriver
Box C: test runner.
I don't know how else it could be laid out, given that DISPLAY is an environment variable, not a parameter to be passed.
In which case, assuming you don't want a separate xvfb installed on Box B, and A is reachable (plus a decent connection) from B, the solution is simply to set:
DISPLAY=boxAHost:10
on Box B.
If A isn't reachable from B, it might be simplest to just duplicate the xvfb setup on both A and B, and have DISPLAY=:10 on both.
I had a "Doh!!!" moment of zen and the whole thing is much easier that I thought it would be.
I had conflated the stdout of node/protractor (which I want on my screen) with the X display of chrome (which I want headless on DISPLAY:10). Of course they are totally different!!!!
Simply prefixing protractor with DISPLAY=:10 eg.
DISPLAY=:10 protractor /installation_test/conf-c-direct-noserver.js
or, in my case since I'm running a node server which in turn spawns protractor, ...
DISPLAY=:10 npm start
So protractor runs in my terminal and I can watch stdout, whereas the DISPLAY=:10 is inherited down through the call layers and is eventually seen and understood by Chrome.

How to run the selenium code on linux using firefox without GUI?

I had redhat Linux server command line but there is no GUI for that and I need to run selenium code on this server with firefox. As I am new to selenium so I am not sure whether it will work or not.
For achieving this I had install Firefox on my Redhat linux machine successfully but not able to trigger that as it is showing no display found.
Is there any other way to achieve this for headless browsing, where virtually a firefox will be opened and selenium code can be executed without GUI. Is it possible to do??
You can use HtmlUnitDriver of selenium to use headless browsing but it will not open firefox and may be not loading all content to it's cache as same as firefox
Refer Below:-
https://code.google.com/p/selenium/wiki/HtmlUnitDriver
Another thing you can use is Phantomjs with selenium Webdriver. This is most using pattern by industries for headless browsing
Refer below:-
http://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html
Yes you can trigger selenium file using command line
http://www.tutorialspoint.com/testng/testng_executing_tests.htm
Bash file is running fine in windows for testng but it is not working in linux/mac
Now if still your firefox is not opening then it is basically issue of some setting with your OS with firefox
Refer that too :-
https://serverfault.com/questions/279036/open-terminal-via-ssh-run-firefox-display-not-found
May be you have problem with some permission in red hat
Hope it will help you :)

Jenkins with Xvfb and Selenium - Firefox started but nothing executed

I have a problem with Selenium under Jenkins 1.446 together with Xvfb: It looks like firefox is started correctly because I let my failing tests record screenshots. These screenshots all show the same failing page, which in my case is the starting page where the tests should begin. So I gues the selenium WebDriver commands do not arrive. What could be the reason? By the way, the tests are running perfectly on my local machine.
I'm using Firefox 9.0.1 with no specific test profile and no AddOns, Ubuntu 10.04, Senlenium 2.16.1
Log entry: com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
Thanks!
EDIT: Issue seems to be fixed by a system reboot ...
I experienced a very similar issue with FF9.0.1 and Selenium 2.16.1 running through JUnit launched by Maven SureFire plugin run by Jenkins on a WinXP node.
2.17.0 fixed the issue for me. Try updating to the latest Selenium.
Through RDP, I was able to watch the tests running. The tests appeared to be partially blocked by a prompt from Firefox asking about collecting anonymous usage statistics. Manually answering the prompt would allow the test to continue but because Selenium creates a new profile each time by default, the prompt would return on the next browser launch. Running the tests locally with a pre-configured FF profile allowed me to persist that the prompt had been answered. This isn't possible on my XP node because the tests are running as 'System'.
Selenium/WebDriver would normally take care of this for you by marking the prompt as already answered in a temporary FF profile configuration but a bug was causing the value to be set to the wrong value. You can inject a profile configuration to the Selenium FirefoxDriver driver to pragmatically configure stuff like this prompt but the bug appeared to prevent this as well. This has been resolved in Selenium 2.17.0 (http://selenium.googlecode.com/svn/trunk/java/CHANGELOG see 2.17.0 WebDriver bug fixes).