All Projects → leonid-shevtsov → Headless

leonid-shevtsov / Headless

Licence: mit
Create a virtual X screen from Ruby, record videos and take screenshots.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Headless

Cbt Tunnel Nodejs
Node.js module for Local Connections to crossbrowsertesting.com
Stars: ✭ 39 (-95.9%)
Mutual labels:  screenshot, selenium
Ffmpegandroid
android端基于FFmpeg实现音频剪切、拼接、转码、编解码;视频剪切、水印、截图、转码、编解码、转Gif动图;音视频合成与分离,配音;音视频解码、同步与播放;FFmpeg本地推流、H264与RTMP实时推流直播;FFmpeg滤镜:素描、色彩平衡、hue、lut、模糊、九宫格等;歌词解析与显示
Stars: ✭ 2,858 (+200.53%)
Mutual labels:  ffmpeg, screenshot
Wdio Screenshot
A WebdriverIO plugin. Additional commands for taking screenshots with WebdriverIO.
Stars: ✭ 101 (-89.38%)
Mutual labels:  screenshot, selenium
Yaxg
capture and record your screen with callbacks
Stars: ✭ 47 (-95.06%)
Mutual labels:  ffmpeg, screenshot
scr
🎤 A Super CRappy SCReenshot & SCreen Recording SCRipt for Sound Cloud Rappers + audio recorder, yes (sponsored by https://git.io/kiwmi)
Stars: ✭ 16 (-98.32%)
Mutual labels:  screenshot, ffmpeg
Chromeless
🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
Stars: ✭ 13,254 (+1293.69%)
Mutual labels:  selenium, integration-testing
Screen Recorder
A Ruby gem to video record and take screenshots of your desktop or specific application window. Works on Windows, Linux, and macOS.
Stars: ✭ 135 (-85.8%)
Mutual labels:  ffmpeg, selenium
Hsac Fitnesse Fixtures
An environment to define and run integration tests. It contains Fitnesse fixture (base) classes and a baseline FitNesse installation.
Stars: ✭ 99 (-89.59%)
Mutual labels:  selenium, integration-testing
demo-webdriverio-cucumber
E2E Tests with WebdriverIO and Cucumber
Stars: ✭ 28 (-97.06%)
Mutual labels:  integration-testing, selenium
dusker
Stand alone Laravel Dusk test suit, which do not require Laravel framework itself
Stars: ✭ 28 (-97.06%)
Mutual labels:  integration-testing, selenium
Selenium-Foundation
Selenium Foundation is an automation framework designed to extend and enhance the capabilities provided by Selenium (WebDriver).
Stars: ✭ 51 (-94.64%)
Mutual labels:  screenshot, selenium
Singlefile
Web Extension for Firefox/Chrome/MS Edge and CLI tool to save a faithful copy of an entire web page in a single HTML file
Stars: ✭ 4,417 (+364.46%)
Mutual labels:  screenshot, selenium
w3c-webdriver
W3C WebDriver JavaScript Client
Stars: ✭ 28 (-97.06%)
Mutual labels:  integration-testing, selenium
Ffcast
Run command on rectangular screen regions
Stars: ✭ 478 (-49.74%)
Mutual labels:  ffmpeg, screenshot
Ffmpeg Cli Wrapper
Java wrapper around the FFmpeg command line tool
Stars: ✭ 940 (-1.16%)
Mutual labels:  ffmpeg
Tdarr
Tdarr - Distributed transcode automation using FFmpeg/HandBrake + Audio/Video library analytics + video health checking (Windows, macOS, Linux & Docker)
Stars: ✭ 911 (-4.21%)
Mutual labels:  ffmpeg
Danneskjold Theme
Beautiful high-contrast emacs theme
Stars: ✭ 26 (-97.27%)
Mutual labels:  screenshot
Instagramfirstcommenter
This bot will post a predefined comment as fast as possible to a new post on the target profile. I used this to successfully win tickets for a big music festival.
Stars: ✭ 26 (-97.27%)
Mutual labels:  selenium
Pybrowserstack Screenshots
api wrapper and python client for Browserstack Screenshots, including phantomCSS support
Stars: ✭ 27 (-97.16%)
Mutual labels:  screenshot
Wdio Workshop
WebdriverIO Workshop
Stars: ✭ 20 (-97.9%)
Mutual labels:  selenium

Headless Travis CI status

Buy Me a Coffee at ko-fi.com

Headless is the Ruby interface for Xvfb. It allows you to create a headless display straight from Ruby code, hiding the low-level action. It can also capture images and video from the virtual framebuffer. For example, you can record screenshots and screencasts of your failing integration specs.

I created it so I can run Selenium tests in Cucumber without any shell scripting. Even more, you can go headless only when you run tests against Selenium. Other possible uses include pdf generation with wkhtmltopdf, or screenshotting.

Documentation is available at rubydoc.info

Changelog

Note: Headless will NOT hide most applications on OS X. Here is a detailed explanation

Installation

On Debian/Ubuntu:

sudo apt-get install xvfb
gem install headless

Usage

Block mode:

require 'rubygems'
require 'headless'
require 'selenium-webdriver'

Headless.ly do
  driver = Selenium::WebDriver.for :firefox
  driver.navigate.to 'http://google.com'
  puts driver.title
end

Object mode:

require 'rubygems'
require 'headless'
require 'selenium-webdriver'

headless = Headless.new
headless.start

driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://google.com'
puts driver.title

headless.destroy

Cucumber

Running cucumber headless is now as simple as adding a before and after hook in features/support/env.rb:

# change the condition to fit your setup
if Capybara.current_driver == :selenium
  require 'headless'

  headless = Headless.new
  headless.start
end

Running tests in parallel

If you have multiple threads running acceptance tests in parallel, you want to spawn Headless before forking, and then reuse that instance with destroy_at_exit: false. You can even spawn a Headless instance in one ruby script, and then reuse the same instance in other scripts by specifying the same display number and reuse: true.

# spawn_headless.rb
Headless.new(display: 100, destroy_at_exit: false).start

# test_suite_that_could_be_ran_multiple_times.rb
Headless.new(display: 100, reuse: true, destroy_at_exit: false).start

# reap_headless.rb
headless = Headless.new(display: 100, reuse: true)
headless.destroy

# kill_headless_without_waiting.rb
headless = Headless.new
headless.destroy_without_sync

There's also a different approach that creates a new virtual display for every parallel test process - see this implementation by @rosskevin.

Cucumber with wkhtmltopdf

Note: this is true for other programs which may use headless at the same time as cucumber is running

When wkhtmltopdf is using Headless, and cucumber is invoking a block of code which uses a headless session, make sure to override the default display of cucumber to retain browser focus. Assuming wkhtmltopdf is using the default display of 99, make sure to set the display to a value != 99 in features/support/env.rb file. This may be the cause of Connection refused - connect(2) (Errno::ECONNREFUSED).

headless = Headless.new(:display => '100')
headless.start

Capturing video

Video is captured using ffmpeg. You can install it on Debian/Ubuntu via sudo apt-get install ffmpeg or on OS X via brew install ffmpeg. You can capture video continuously or capture scenarios separately. Here is typical use case:

require 'headless'

headless = Headless.new
headless.start

Before do
  headless.video.start_capture
end

After do |scenario|
  if scenario.failed?
    headless.video.stop_and_save("/tmp/#{BUILD_ID}/#{scenario.name.split.join("_")}.mov")
  else
    headless.video.stop_and_discard
  end
end

Video options

When initiating Headless you may pass a hash with video options.

headless = Headless.new(:video => { :frame_rate => 12, :codec => 'libx264' })

Available options:

  • :codec - codec to be used by ffmpeg
  • :frame_rate - frame rate of video capture
  • :provider - ffmpeg provider - either :libav (default) or :ffmpeg
  • :provider_binary_path - Explicit path to avconv or ffmpeg. Only required when the binary cannot be discovered on the system $PATH.
  • :pidfile_path - path to ffmpeg pid file, default: "/tmp/.headless_ffmpeg#{@display}.pid"
  • :tmpfile_path - path to tmp video file, default: "/tmp/.headless_ffmpeg#{@display}.mov"
  • :log_file_path - ffmpeg log file, default: "/dev/null"
  • :extra - array of extra ffmpeg options, default: []

Taking screenshots

Call headless.take_screenshot to take a screenshot. It needs two arguments:

  • file_path - path where the image should be stored
  • options - options, that can be: :using - :imagemagick or :xwd, :imagemagick is default, if :imagemagick is used, image format is determined by file_path extension

Screenshots can be taken by either using import (part of imagemagick library) or xwd utility.

import captures a screenshot and saves it in the format of the specified file. It is convenient but not too fast as it has to do the encoding synchronously.

xwd will capture a screenshot very fast and store it in its own format, which can then be converted to one of other picture formats using, for example, netpbm utilities - xwdtopnm <xwd_file> | pnmtopng > capture.png.

To install the necessary libraries on ubuntu:

import - run sudo apt-get install imagemagick xwd - run sudo apt-get install X11-apps and if you are going to use netpbm utilities for image conversion - sudo apt-get install netpbm

Troubleshooting

/tmp/.X11-unix is missing

Xvfb requires this directory to exist. It cannot be created automatically, because the directory must be owned by the root user. (You will never get this error if running as root - for example, in a Docker container.)

On macOS, the directory will be created when you run XQuartz.app. But since /tmp is cleared on reboot, you will need to open XQuartz.app after a reboot before running Xvfb. (You don't need to leave it running.)

To create this directory manually, on either macOS or Linux:

mkdir /tmp/.X11-unix
sudo chmod 1777 /tmp/.X11-unix
sudo chown root /tmp/.X11-unix/

Note that you may need to run these commands after every reboot, too.

Display socket is taken but lock file is missing

This means that there is an X server that is taking up the chosen display number, but its lock file is missing. This is an exceptional situation. Please stop the server process manually (pkill Xvfb) and open an issue.

Video not recording

If video is not recording, and there are no visible exceptions, try passing the following option to Headless to figure out the reason: Headless.new(video: {log_file_path: STDERR}). In particular, there are some issues with the version of avconv packaged with Ubuntu 12.04 - an outdated release, but still in use on Travis.

##Contributors


© 2011-2015 Leonid Shevtsov, released under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].