Jump to content

Ruby on Rails with Watir - Webdriver without Browser

EroewinQ
Go to solution Solved by EroewinQ,

Hey @penguinsofevil, I finally found the alternative gems. Capybara and Poltergeist. They work together just need PhantomJS to run. I found it here: https://www.amberbit.com/blog/2014/2/12/automate-tasks-on-the-web-with-ruby-and-capybara/

 

Hi. I'm writing a feature where it needs to access this website. I have the following action to run on the website:

  1. Visit the web login page
  2. Enter username & password
  3. Visit a specific page
  4. Take a screenshot
  5. Save it as base64

I already make the code for it:

# Preparation
require 'watir'

browser_args = %w[headless disable-gpu disable-dev-shm-usage disable-software-rasterizer no-sandbox]
browser = Watir::Browser.new :chrome, args: browser_args

# Step 1: go to the site
browser.goto site

# Step 2: enter 'username' & 'password'
browser.text_field({ name: 'login_username' }).set username
browser.text_field({ name: 'login_password' }).set password

# Step 3: click the 'Login' button
browser.button({ value: 'Login' }).click

# Step 4: (visit a specific page)

# Step 5: screenshot
browser.screenshot.base64

 

The issue is, the server operator said that we're not allowed to install a browser on the server. Only webdriver like chromedriver and geckodriver allowed. The reason is that browser has GUI. As you can see, I use headless as an argument for the browser which makes it run without a UI or display server dependencies (https://peter.sh/experiments/chromium-command-line-switches). Already explain it, but still, the operator won't allow me to install any browser on the server.

 

Is there any alternative for that case without installing any browser? If not, how do I explain it (again) to the server operator? 

Link to comment
Share on other sites

Link to post
Share on other sites

i'm not completely fluent in ruby, but i was looking at the documentation, you could try something like:

# Preparation
require 'watir'

# browser_args = %w[headless disable-gpu disable-dev-shm-usage disable-software-rasterizer no-sandbox]
browser = Watir::Browser.new :chrome, headless: true

you can't install browsers but what about other gems? only works for posix tho

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×