How can I prevent slimerjs browser opens when I run a script? - casperjs

This is not about viewport. The viewport is ok. One thing is the viewport size of the screen, width and height, and another is the graphical interface browser (window), that is opened when you run casperjs test.js --engine=slimerjs.
It's ok that the browser opens when I run casperjs test.js --engine=slimerjs, very useful for testing purposes. But when I stopped testing and want to do something bigger I don't want that browser window open 10 times or 100 times.
I've been reading a while and couldn't find any in the documentation, google or here.
If this is possible, throw the command, I will be very grateful for that. Thank you very much.

Had the same requirement. xvfb (virtual frame buffer) does this work easily
Install xvfb with this command.
sudo apt-get install xvfb
Then run it using this prefix.
xvfb-run -a
So run the command like
xvfb-run -a casperjs tests.js --engine=slimerjs
This will run the application in the headless mode.

Yes, it`s possible, you can hidden window with xvfb util. How to do it. Docs

Related

Cypress --headless still opening browser window on mac os

npx npm run cypress --headless running this code in my project is still opening up a google chrome user, requiring UI to keep it going
no matter what I try, even uninstalling and reinstalling cypress doesn't fix the issue
The correct way is:
cypress run
Actually by default this command is executed in headless mode, that's why it's not necessary to write --headless. And if you want to run it in headed mode, then:
cypress run --headed

web-ext: How to run Firefox in dark mode?

I'm working on a new browser extension and I'm using Mozilla's web-ext tool to test it. I couldn't figure out how to run the test browser in dark mode.
So far I have tried this:
web-ext run --verbose --pref extensions.activeThemeID=firefox-compact-dark#mozilla.org
I figured out a way! Apparently, dark mode is an add-on; not a preference.
First step is to create an empty directory to store our Firefox profile.
mkdir ../dark-mode-profile
npx web-ext run -p ../dark-mode-profile --keep-profile-changes
Then enable dark mode and close Firefox (and hit Ctrl-C if necessary). Since we turned on the --keep-profile-changes flag, all the changes we made are now stored in our profile folder.
We can run Firefox with this profile:
npx web-ext run -p ../dark-mode-profile

How can I tell Cypress to hide Chrome when running from the command line?

Problem
I want to be able to run my tests in terminal, but all my tests fail due to Cypress using Electron as the default browser and I want it to utilize Chrome, but without having to specify it in the command line.
Current Outcome
I know I can use the command npx cypress run --browser chrome to tell Cypress to use Chrome instead. However, it opens the browser AND runs it in command line.
Expected Outcome
Ideally it would only require me to run npx cypress run and this would only run in the command line using Chrome.
Summary
Is there a way to set the default browser to Chrome instead of Electron so I wouldn't need to specify which browser to use?
Is there something to add to the package.json file to set the default browser to Chrome or a line to inject somewhere? I checked the docs and I couldn't really find anything other than the --browser command.
** Cypress Github Open Issue **
Here is the link to the open issue on their github regarding a headless chrome and also to change the default for cypress run
Support chrome headless and change defaults for cypress run
Photo for the debugger
Sorry for the terrible scribbles...I am under an NDA so had to go back and scratch out all the path names for my project as well as my last name.
Cypress 3.8.1+ allows you to pass --headless to cypress run to make Chrome invisible on any operating system by using Chrome headless:
cypress run --headless --browser chrome
Outdated answer below:
There is not currently a way to hide Chrome in run mode on macOS or
Windows.
We'd like to support it, but we'd have to find some kind of workaround
for xvfb not being available. We can't use google-chrome
--headless either because it won't allow us to install the Cypress extension.
The advice below will only work for Linux.
npx cypress run --browser chrome is the correct way to do what
you're trying to do.
If you are on Linux, you can make it run Chrome in a virtual
framebuffer (so it will be hidden from you) by blanking out the
DISPLAY env variable:
DISPLAY= npx cypress run --browser chrome
Technical explanation:
Cypress does not support running in "headless Chrome" - headless Chrome was not around when Cypress was first written
So, when Cypress is running in Chrome in CI, it uses xvfb to create an X virtual framebuffer, then it uses the DISPLAY variable
to tell Chrome to run in the xvfb
However, if you have DISPLAY set (by default, it is set on Linux if you have a display manager), it will use that DISPLAY instead -
this is why it appears even though you're doing cypress run.
Adding DISPLAY= before the command nulls out DISPLAY, which means that Cypress will spawn xvfb and run it inside of there
instead.

cannot start browser for selenium through ssh

I am trying to setup a linux box (no display connected) to run as a selenium server. If I connect a monitor and login on the box then I can run the selenium tests no problem. If I try to run the tests via ssh then the tests fail with
Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: Timed out waiting for profile to be created!
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:360)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:114)
I think it has something to do with the display's absence / presence. Any ideas?
PS the browser is firefox 5, the OS is Ubuntu 11.04
I got it to work by using xvfb. So first install xvfb:
sudo apt-get install xvfb
then run it
Xvfb :99 -ac
and then start the selenium server
DISPLAY=:99 java -jar selenium-server-standalone-2.4.0.jar
Here is my answer.
You get this error because there is no monitor to open firefox on, it is getting confused.
Install Xvfb, which pretends to be a monitor, but doesn't show up anywhere.
sudo apt-get install xvfb
If you want less errors add these fonts, but those warning aren't important.
sudo apt-get install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
Then start it running and set your display to something the system won't use. Here is what I do, remeber the & makes the terminal run something in the background.
Xvfb :99 -ac &
export DISPLAY=:99
firefox &
Also I was having problems with a ruby on rails server disconnecting when I quit the ssh terminal. To fix that problem use Screen. Screen runs another terminal without being affected by the ssh.
sudo apt-get install screen
Then just start screen before you you do the stuff above.
screen
To get out of the current screen window just click "Ctrl + A" and to get back in type screen -r.
There is a good way to test using imagemagick screen shoot
Install mozilla firefox headless(no GUI)
yum install xorg-x11-server-Xvfb.x86_64 xfonts-base xfonts-75dpi xfonts-100dpi firefox ImageMagick.x86_64
Starts firefox on virtual gui
DISPLAY=:1 firefox http://google.com &
– test and check
Xvfb :1 -screen 1 1024x768x24 &
ps -ef |grep firefox
Uses imagemagic to get a printscreen, to make sure its working.
DISPLAY=:1 import -window root google.com.png
(Optional) Set proxy in firefox profile
vi /root/.mozilla/firefox/ns11i9xo.default/prefs.js
user_pref(“network.proxy.http”, “proxyserver”);
user_pref(“network.proxy.http_port”, 8080);
user_pref(“network.proxy.no_proxies_on”, “localhost, 127.0.0.1, 172.17.0.0/16, 10.5.0.0/16″);
http://felipeferreira.net/?p=1220

xvfb on a machine with a display, can an application run 'in the background?'

I'm setting up to cron a web scraping job, using xvfb, firefox, and watir on my Mac OS X.
In testing the script so far, firefox pops up visibly on the local desktop, the watir script executes, and then firefox exits (I quit firefox in my script).
I'd like to set the xvfb DISPLAY such that firefox will run, but won't be seen on the local desktop, running 'in the background' so to speak.
Nothing I've been able to find online discusses such a possibility - nor explains that it's not possible.
Is it possible? If so, what do I need to do to make it work?
This is what we use to build packages whose testsuite require running Xserver in Linux:
#############################################
### Launch a virtual framebuffer X server ###
#############################################
export DISPLAY=":98"
Xvfb $DISPLAY >& Xvfb.log &
trap "kill $! || true" EXIT
sleep 10
...
# start your application/testsuite here
I tried it with firefox in a script. And does what you need (if your firefox in OSX also uses X11 of course).
there's a gem called Headless for this kind of stuff.
I've tried it with Selenium in my Ubuntu and works fine.

Resources