Git Product home page Git Product logo

gnawrnip's Introduction

Gnawrnip

Gnawrnip is a TurnipFormatter Add-on that provides put a screenshot (like animation gif) to report use Capybara

Build Status Coverage Status Code Climate Dependency Status

IMPORTANT!

This project is currently in development (frequent releases). So it have potential for massive refactorings (that could be API breaking).

Requirements

  • Ruby
    • 2.2.0 or higher
  • RubyGems
    • capybara ~> 2.1.0
    • turnip_formatter

Installation

Add this line to your application's Gemfile:

gem 'gnawrnip'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gnawrnip

Setup

In your test setup file add:

require 'gnawrnip'
Gnawrnip.ready!

Customization

You can do to customize a screenshot.

Gnawrnip.configure do |c|
  c.make_animation = true
  c.max_frame_size = 1024 # pixel
end
  • make_animation (Boolean) Whether to make animation GIF. (Default: true)
  • max_frame_size (Integer) Maximum size that use to resize of image.
    • If given, it resize the image to fit to this value.

    • Ignored if this value is greater than original width and height.

    • Example:

         original: 640x480
       this value: 300
          result : 300x225
      
         original: 480x640
       this value: 400
          result : 300x400
      

As example, see example/spec/spec_helper.rb .

Example

see https://github.com/gongo/gnawrnip/tree/master/example

License

MIT License. see LICENSE.txt

gnawrnip's People

Contributors

gongo avatar marcoadkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gnawrnip's Issues

Capybara::Node::Element のActionMethodもanimation時のframeに入れていただけるとありがたいです。

Capybara::Node:Sessionの
click_button, click_link,click_onなどの時はanimation時のframeとなるのですが
find('#bar') .clickなど
Capybara::Node::ElenmentのActionMethodはframeになりません。

SessionクラスのActionMethodをhookしてscreenshotを撮られているとお見受けしますが、
ElementクラスのActionMethodもアニメーションの仲間に入れていただけるとありがたいです。

当方でモンキーパッチを作れればよいのでしょうが、Rubyはじめてまだ1ヶ月なので、ままならず。
ご検討宜しくお願いいたします。

フレームの切り換わる秒数を指定

Gnawrnip.frame_interval = 3 # 3sec

みたいな感じかな

今はデフォルトで一秒

  Template.add_js(<<-EOS)
    // Reference http://www.softel.co.jp/blogs/jquery/archives/1057
    $('.screenshot.animation').each(function() {
        var imgs = $(this).children('img');
        var frame = 0;

        imgs.hide();
        setInterval(function() {
            imgs.hide();
            imgs.eq(frame).show();
            frame = (++frame % imgs.length);
        }, 1000); // <= ここ
    });
  EOS

README 修正

Gnawrnip.configure とか増やしたのでその分

Problem of "Too many open files"

Problem

  • エラー出すぎて画像ファイル開きまくってる
  • 画像ファイル、Tempfile で開いてる
  • ファイルディスクリプタが爆発したはず

Solution

  • 一旦 .gnawnrip みたいなディレクトリ作って、そこに置いとく
    • base64 にしてメモリに全部持つのはつらそう

modal dialog が出ている場合、save_screenshot すると UnhandledAlertError

visit とか click_link など、save_screenshot のトリガとなるアクションが行われたとき、
confirm だったり alert だったり modal dialog が出てしまうと、
その状態で save_screenshot が起動して

Selenium::WebDriver::Error::UnhandledAlertErro

がraiseされる。

解決策(仮)

lib/gnawrnip/screenshot.rb にて

@@ -14,6 +14,8 @@ module Gnawrnip
       # @return  [Tempfile]  Image of screenshot
       #
       def take
+        return nil if alert_present?
+
         tempfile = Tempfile.new(['gnawrnip', '.png'])
         session.save_screenshot(tempfile.path)
         tempfile
@@ -24,6 +26,17 @@ module Gnawrnip
       def session
         Capybara.current_session
       end
+
+      def alert_present?
+        return false if session.driver.browser.respond_to?(:switch_to)
+
+        begin
+          session.driver.browser.switch_to.alert
+          true
+        rescue Selenium::WebDriver::Error::NoAlertPresentError
+          false
+        end
+      end
     end
   end
 end

とかすると、dialog でてる時は save_screenshot 取らない、みたいなことはできる。
しかし、 switch_to.alert で確かめる方法だと dialog が出ていない時は数秒 (Capybara.default_wait_time) まってしまうため、
時間がかかりすぎてしまう。ちょっと困る

Add timing of take a screenshot `each step`

Motivation

  • #19 (comment)

  • Turnip のテストレポートを見やすくしてみた - CrowdWorks Engineer Blog

    ステップ失敗時のSSを撮るために生まれたのが TurnipFormatter および Gnawrnip です。 大変便利なgemですが、TurnipFormatterとGnawrnipの組み合わせは、キャプチャのタイミングがページ遷移毎となっており、細かなタイミングでのキャプチャが得られません。 javascriptによる制御が組み込まれたWebアプリケーションでは、もう少し細かなタイミングでのキャプチャが欲しくなりますし、 受け入れテストのレポートにするならば、ステップごとのキャプチャが欲しくなります。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.