Created
October 23, 2013 19:30
-
-
Save ericboehs/7125105 to your computer and use it in GitHub Desktop.
Poltergeist hack to silence CoreText performance notes from phantomjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Capybara::Poltergeist | |
class Client | |
private | |
def redirect_stdout(to) | |
prev = STDOUT.dup | |
prev.autoclose = false | |
$stdout = to | |
STDOUT.reopen(to) | |
prev = STDERR.dup | |
prev.autoclose = false | |
$stderr = to | |
STDERR.reopen(to) | |
yield | |
ensure | |
STDOUT.reopen(prev) | |
$stdout = STDOUT | |
STDERR.reopen(prev) | |
$stderr = STDERR | |
end | |
end | |
end | |
class WarningSuppressor | |
class << self | |
def write(message) | |
if message =~ /QFont::setPixelSize: Pixel size <= 0/ || message =~/CoreText performance note:/ then 0 else puts(message);1;end | |
end | |
end | |
end | |
Capybara.register_driver :poltergeist do |app| | |
Capybara::Poltergeist::Driver.new(app, phantomjs_logger: WarningSuppressor) | |
end | |
Capybara.javascript_driver = :poltergeist |
Thanks @matheusbras.
Can anyone give little help on what I'd need to change to apply this to the :poltergeist_billy
driver? Not a ruby developer but using Cappy in our test suite.
Thanks for sharing this gist! Works for me.
Thanks!
@ericboehs Now a really dumb question: Isn't prev
overwriting each other?
Extending this pattern for other unwanted output:
class WarningSuppressor
IGNORES = [
/QFont::setPixelSize: Pixel size <= 0/,
/CoreText performance note:/,
/Heya! This page is using wysihtml5/
]
class << self
def write(message)
if suppress?(message) then 0 else puts(message);1;end
end
private
def suppress?(message)
IGNORES.any? { |re| message =~ re }
end
end
end
I had trouble making this cooperate with a phantomjs installed by phantomjs-gem. I straightened it out by changing the way the Driver's initialized:
require 'phantomjs'
#...everything as described above...
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, phantomjs_logger: WarningSuppressor, phantomjs: Phantomjs.path)
end
Just noting this for anyone who comes along with the same problem :~)
I created a gem: https://github.com/uiureo/poltergeist-suppressor
You can write like this:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app,
phantomjs_logger: Capybara::Poltergeist::Suppressor.new
)
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @matheusbras 👍