Using Windows Subsystem WSL2. I am trying to open browser in Ubuntu 20.04.
Followed commands to install google chrome and chrome-driver
https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/
Facing issue while starting chrome via terminal. Unable to initialise browser as well.
Versions:
Windows 10
Ubuntu 20.04
Google Chrome 102.0.5005.61
ChromeDriver 102.0.5005.61
selenium-webdriver (4.1.0)
watir (7.1.0)
When I tried to open google-chrome via terminal.
$google-chrome
Error: [0530/135205.172753:ERROR:exception_handler_server.cc(361)] getsockopt: Invalid argument (22)
$sudo update-alternatives --config x-www-browser
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/google-chrome-stable 200 auto mode
1 /usr/bin/chromium-browser 40 manual mode
2 /usr/bin/google-chrome-stable 200 manual mode
3 /usr/bin/wslview 30 manual mode
I tried to initialise browser in IRB as well.
require 'watir'
browser = Watir::Browser.new(:chrome)
Error: Net::ReadTimeout
Tried reinstalling subsystem as well. Still facing same issue.
A few possible issues:
First, you mention that you are on WSL2, but the Chrome error you are receiving leads me to believe that you might be on WSL1. I see the same error if I run google-chrome on WSL1, but not on WSL2.
Double-check that with wsl.exe -l -v. You may need to convert the instance to WSL2 with wsl --set-version <distro> 2.
Second, running google-chrome like that, even on WSL2, will require an X server. WSL in Windows 10 does not support GUI applications, so you would need to install and configure an X server in Windows. You'll find other questions and answers on that topic, so I won't spend much time on it here, since your real question is about running Chrome headless.
As long as you are running WSL2 you should be able to run Chrome headless with Watir. It looks like the main thing you are missing is not calling Watir with the headless: true option for Chrome per this doc.
Here are the steps I took with Watir and Chromedriver. Note that the first line is a fixed version of the directions you linked to, since it requires sudo apt-key add rather than sudo curl:
curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add
sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list"
sudo apt update
sudo apt install -y google-chrome-stable
google-chrome --version # To check the Chromedriver version to download
cd ~
wget https://chromedriver.storage.googleapis.com/102.0.5005.61/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver ~/.local/bin # A directory on your path
gem install --user-install watir
irb
In irb:
require 'watir'
browser = Watir::Browser.new :chrome, headless: true
browser.goto 'https://stackoverflow.com/q/72432711/11810933'
puts browser.title
Which returns the title of your question here.
It's also possible to use the headless package, as noted on this page.
Add the following:
sudo apt install xvfb
gem install --user-install headless
Then in irb:
require 'watir'
require 'headless'
headless = Headless.new
headless.start
browser = Watir::Browser.new(:chrome)
browser.goto 'https://stackoverflow.com/q/72432711/11810933'
puts browser.title
headless.destroy
Related
When I run
$ php artisan dusk tests/Browser/ExampleTest.php
It prompt the error
Tests\Browser\ExampleTest::testExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error:
Chrome failed to start: exited abnormally (unknown error:
DevToolsActivePort file doesn't exist) (The process started from
chrome location /snap/bin/chromium is no longer running, so
ChromeDriver is assuming that Chrome has crashed.) (Driver info:
chromedriver=2.45.615279
(12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux
5.4.0-107-generic x86_64)
I check the chrome driver, it is install correctly.
$ php artisan dusk:chrome-driver
ChromeDriver binary successfully installed for version 100.0.4896.60.
Then I google the error. They said to check the chrome version
$ /usr/bin/chromium-browser --version
/usr/bin/chromium-browser: 12: xdg-settings: not found cannot create
user data directory: /home/shiro/snap/chromium/1952: Permission
denied
My goal is need to run Laravel Dusk in Ubuntu 20.04.
***Make sure your chromium-browser need to REMOVE and INSTALL snap stable version MATCH with your Laravel Dusk Chrome Driver
Below is the step, I run:-
Next fix the Chromium issue by install via snap, then next error
$ sudo snap refresh --edge chromium
error: cannot communicate with server: Post
http://localhost/v2/snaps/chromium: dial unix /run/snapd.socket:
connect: no such file or directory
to solve the error, need to update the packages.
$ sudo add-apt-repository ppa:saiarcot895/chromium-beta
$ sudo apt-get update
$ sudo apt-get install chromium-browser
Finally, it show the version. However, does not match my Laravel Chrome driver. Didn't solve my first issue. Still can't run dusk
$ /usr/bin/chromium-browser --version
Chromium 97.0.4692.20 Ubuntu 20.04
Next install snap version of Chrome and remove the chromium-browser
$ systemctl start snapd.service
$ sudo snap install chromium
$ sudo apt remove chromium-browser
IMPORTANT NOTE
$ /usr/bin/chromium-browser --version
-bash: /usr/bin/chrome: No such file or directory
Boom~ It works~
I have ROR projects that need different versions of ruby and one of them need ruby 2.4.0. with Postgresql. I’m using a PC with Windows 10.
How can I install more than one ruby version like in Linux with rvm? and where can I download the Ruby 2.4.0 for Windows? (I saw that rubyinstaller.org doesn’t have this version)
Windows 10 comes with a new feature called Windows Subsystem for Linux (WSL) that allows you to use Bash with the most common Linux tools included the ones you need to install a Ruby Manager Version.
For this tutorial we'll set up Ubuntu on Windows, Ruby 2.4.0, Rails 5.0.1 and PostgreSQL.
Installing Bash On Windows
First enable developer mode on your machine
https://www.youtube.com/watch?v=S6NvjvL3xaI
Next install Windows Subsystem for Linux
https://www.youtube.com/watch?v=g_5hxfFKDL8
And restart your computer.
After the computer reboot open a Command Prompt (CMD) and type
> bash
You will see the next message
This will install Ubuntu on Windows, distributed by Canonical
and licensed under its terms available here:
https://aka.ms/uowterms
Press "y" to continue: y
Press "Y" to continue
Downloading from the Windows Store... 100%
Extracting filesystem, this will take a few minutes….
Bash will ask you for a user, please remember this user because bash will ask you every time you need root permissions in Bash. Also when you time your password you won’t see the keystrokes, it’s normal, only keep typing and press ENTER when you finish.
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms.wslusers
Enter new UNIX username:
Enter new UNIX password:
And your Bash is ready when you see the CMD its in the
mnt/c/Users/your_username directory.
your_username#yourmachine:/mnt/c/Users/your_username$
Installing RVM and Ruby
In your bash copy this line:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Then install gnup2
$ sudo apt-get install gnupg2
Remember your UNIX password because every time you saw a sudo in the command you will be asked for your password.
Install RVM
$ \curl -sSL https://get.rvm.io -o rvm.sh
$ cat rvm.sh | bash -s stable
$ source ~/.rvm/scripts/rvm
Install Ruby
$ rvm install ruby-2.4.0
If you need to install other version of ruby run this same command like this
$ rvm install ruby-2.3.5
And select the ruby version you want to use
$ rvm --default use 2.3.5
To check if it works
$ ruby -v
Installing RubyOnRails
Install the Ruby’s package manager Bundler
$ gem install bundler
Add NodeJS
$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Install Rails
$ gem install rails
Installing PostgreSQL
Download PostgreSQL installer and follow the instructions of the installation
https://www.openscg.com/bigsql/postgresql/installers.jsp/
The installer will ask you for a user and a password, also keep them in a safe place because you will use it to access to PostgreSQL command line and in database.ymlin your ROR project.
When the installation finish, return to bash and type the next command
$psql -p 5432 -h localhost -U your_postgresql_username
Bash will ask you the PostgreSQL password and if everything works you will have access to the Postgres shell prompt
psql (9.5.6, server 9.6.2)
WARNING: psql major version 9.5, server major version 9.6.
Some psql features might not work.
Type "help" for help.
postgres=#
Type \q to exit the Postgres shell.
Running your Rails app
Open the project in your favorite editor and update the database.yml with the PostgreSQL username and password.
development:
database: your_app_name_development
username: your_postgres_user
password: your_postgres_password
host: localhost
port: 5432
test:
database: your_app_name_test
username: your_postgres_user
password: your_postgres_password
host: localhost
port: 5432
In Bash go to the directory where is your rails project, for example:
$ cd Projects/my_app
To learn more about Bash navigation visit
https://www.pluralsight.com/guides/beginner-linux-navigation-manual
Create your database
$ rake db:create
Run the rails server to make sure everything is working
$ rails s
And go to your browser and visit
$ localhost:3000
Every time you need a Bash, open a Command Prompt and type
>bash -l
For more detail of each of the commands in this tutorial, visit
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-and-set-up-a-local-programming-environment-on-windows-10
https://medium.com/#colinrubbert/installing-ruby-on-rails-in-windows-10-w-bash-postgresql-e48e55954fbf
I'm trying to install PhantomJS on my Mac (Yosemite).
I did the following:
npm install phantomjs
Then I did:
npm install phantomjs-prebuilt
Both of which appear in my node_modules. But when I try to run phantomjs --versionI get
-bash: phantomjs: command not found
Also tried installing the binary from the downloads website, but nothing. What am I missing? End goal is to use casperjs but currently casper is asking
Fatal: [Errno 2] No such file or directory; did you install phantomjs?
I thought I did....?
If you are using Homebrew, you can type:
brew tap homebrew/cask
brew cask install phantomjs
Download phantomjs latest version (ex: phantomjs-2.1.1-macosx.zip) from http://phantomjs.org/download.html
Extract it to some path(ex: ~/Desktop/phantomjs-2.1.1-macosx)
Run this command on terminal -
sudo ln -n ~/Desktop/phantomjs-2.1.1-macosx/bin/phantomjs /usr/local/bin/
Launch phantomjs from the terminal by command: phantomjs
Check phantomjs version by command: phantomjs -v
Check the phantomjs path by command: which phantomjs
The accepted answer is outdated. On Mac, using Homebrew, type:
brew tap homebrew/cask
brew cask install phantomjs
The first step may not be necessary for some MacOS versions.
For newer versions of cask (2021 and later), use
brew install --cask phantomjs
You need to add phantomjs binary to your PATH. You can do this either by modifying the environment variable or by symlinking the binary to for example /usr/local/bin
For example, if you want to symlink the binary:
cd $HOME
curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
ln -s $HOME/phantomjs-2.1.1-macosx/bin/phantomjs /usr/bin/phantomjs
or if you want to modify the PATH environment variable:
cd $HOME
curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
and add this line to this file: ~/.bash_profile:
export PATH=$HOME/phantomjs-2.1.1-macosx/bin:$PATH
and then run:
source ~/.bash_profile
Shouldn't you be installing phantomjs globally?
npm install -g phantomjs
Since you are installing it locally, the command -
phantomjs -v
would not work everywhere.
You can check the difference between local install and global install here: https://docs.npmjs.com/cli/install
After a lot of digging I found that on on High-Sierra old versions of phantomjs (<2.0) would not work.
Also, the zip file via the phantomjs download page is a faulty one.
If you need a new phantom, just go to this page and download phantomjs 2.1.1 (or later).
for Mac BigSur
brew tap homebrew/cask
brew install --cask phantomjs
I have a big problem with my Debian server configuration. Someone before me has made a big mess with ruby installation and now i can't manage to get it all working. What i'm trying to do now is to get back to environment, where ruby1.8 is installed and rails app is working correctly with apache+passenger. If it would be working on RVM it would be perfect. Here is the story:
There was ruby 1.8 installed on a server. The person has removed it with sudo apt-get remove ruby1.8 and then installed version 2.0.x manually using those commands:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make
sudo make install
Then, he has removed all the dirs listed by whereis ruby with rm command.
And here i came - i want to install RVM on this server. The problem is, no matter what i do, i get a lot of errors from all sides. Steps i've done:
# Install RVM
curl -L https://get.rvm.io | bash -s stable
# install 1.8.7 version
rvm install 1.8.7
# use 1.8.7
rvm use 1.8.7
# Install gems
bundle install
First thing (and that's just a tip of iceberg) is that i'm not able to start apache2 in cause of the following error:
apache2: Syntax error on line 203 of /etc/apache2/apache2.conf: Syntax
error on line 1 of /etc/apache2/mods-enabled/passenger.load: Cannot
load
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
into server:
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/libout/apache2/mod_passenger.so:
cannot open shared object file: No such file or directory Action
'configtest' failed.
Looks like there is even no /usr/lib/ruby/ dir on my system right now.
The question is: is there any way to reset all ruby-releated libraries on debian to the original state (debian without ruby installed) and install working RVM on top of that? Thanks in advance for any help.
Verify if, Is ruby installed correct by ruby -v
Install phusion passenger
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
and then follow onscreen instructions
I'm using mocha within yeoman as a build target: yeoman test.
But the only output I see is
Running "mocha:all" (mocha) task
Testing index.html
When I open that very same index.html in a browser, it works.
I'd expect the test results to show up in console.
My phantomjs was 1.4.1, and it's not working just like you. After I update phantomjs to 1.8, it's working.
I use MacOS, and the update commands are:
sudo brew update
sudo brew unlink phantomjs
sudo brew install phantomjs