browser_shooter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp
6
+ .rvmrc
7
+ shoots/
data/.rvmrc.example ADDED
@@ -0,0 +1,2 @@
1
+ rvm use 1.9.2@browser_shooter
2
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # BrowserShooter
2
+
3
+ Combined with Selenium RC this gem allows to program Selenium scripts combined with ScreenShots.
4
+
5
+ ## Use it
6
+
7
+ ### Setup the servers
8
+
9
+ 1. Set up your VirtualMachines with your target SO and browsers installed. Java SE is also needed.
10
+ 2. Download the last version of [Selenium Server](http://seleniumhq.org/download/) (AKA Selenium Remote Control).
11
+ 3. Go to the console and start the Selenium Server:
12
+
13
+ java -jar <your selenium server file>.jar
14
+
15
+ Repeat this steps in every VM.
16
+
17
+ ### Config your BrowserShooter script
18
+
19
+ Create a YAML file like this:
20
+
21
+ shoots_path: "/tmp/shoots"
22
+
23
+ scripts:
24
+ google:
25
+ name: "google"
26
+ url: "http://www.google.de"
27
+ # commands are Selenium commands
28
+ # except 'shot' command wich receive an optional param with the 'sufix' of the screenshot png
29
+ # except 'pause' command wich use a Ruby 'sleep' command to pause
30
+ commands: |
31
+ open "/"
32
+ window_maximize
33
+ shot before
34
+ type "id=lst-ib", "fernando guillen"
35
+ click "name=btnG", wait_for :page
36
+ pause 3
37
+ shot after
38
+
39
+ browsers:
40
+ windows-firefox:
41
+ name: "windows-firefox"
42
+ host: 10.211.55.4
43
+ port: 4444
44
+ browser: "*firefox"
45
+
46
+ windows-iexplore:
47
+ name: "windows-iexploreproxy"
48
+ host: 10.211.55.4
49
+ port: 4444
50
+ browser: "*iexploreproxy"
51
+
52
+ Look in the `examples` folder for more complete examples.
53
+
54
+
55
+ ### Run the BrowserShooter script
56
+
57
+ $ browser_shooter ./my/config.yml
58
+
59
+ The screenshots will be stored in:
60
+
61
+ <shoots_path>/<time_stamp>/<script_name>_<browser_name>[_<sufix>].png
62
+
63
+ ## Status
64
+
65
+ Still in a _discovery_ state.. no tests.
66
+
67
+ But is functional a can be usefull in no-production environments.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'bundler'
6
+
7
+ include Rake::DSL
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ task :default => :test
12
+
13
+ Rake::TestTask.new do |t|
14
+ t.libs << '.'
15
+ t.test_files = FileList['test/*_test.rb']
16
+ t.verbose = true
17
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Use:
4
+ # browser_shooter /path/to/config.yml
5
+
6
+ begin
7
+ require 'browser_shooter'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'browser_shooter'
11
+ end
12
+
13
+ if ( ARGV.size != 1 )
14
+ BrowserShooter::Logger.log "use: $ browser_shooter <config_file_path>"
15
+ exit 1
16
+ end
17
+
18
+ BrowserShooter.new( ARGV[0] ).run
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "browser_shooter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "browser_shooter"
7
+ s.version = BrowserShooter::VERSION
8
+ s.authors = ["Fernando Guillen"]
9
+ s.email = ["fguillen.mail@gmail.com"]
10
+ s.homepage = "https://github.com/fguillen/BrowserShooter"
11
+ s.summary = "Selenium RC wraper to create browser screenshots"
12
+ s.description = "Selenium RC wraper to create browser screenshots"
13
+
14
+ s.rubyforge_project = "browser_shooter"
15
+
16
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
17
+ s.add_development_dependency "rake", "0.9.2.2"
18
+ s.add_dependency "selenium-webdriver"
19
+ s.add_dependency "selenium"
20
+ s.add_dependency "selenium-client"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,55 @@
1
+ shoots_path: "~/browser_shoots"
2
+
3
+ scripts:
4
+ google:
5
+ name: "google"
6
+ url: "http://www.google.de"
7
+ commands: |
8
+ open "/"
9
+ window_maximize
10
+ shot before
11
+ type "id=lst-ib", "fernando guillen"
12
+ click "name=btnG", wait_for :page
13
+ pause 3
14
+ shot after
15
+
16
+
17
+ miniclip:
18
+ name: "miniclip"
19
+ url: "http://www.miniclip.com/games/de/"
20
+ commands: |
21
+ open "/"
22
+ window_maximize
23
+ shot
24
+
25
+ brandengage:
26
+ name: "brandengage"
27
+ url: "http://staging.iframe.sponsorpay.com"
28
+ commands: |
29
+ open "/test/brandengage.html"
30
+ window_maximize
31
+ click "link=be_1372_dedicated"
32
+ pause 5
33
+ get_alert
34
+ click "link=sp.showVideo();"
35
+ pause 5
36
+ shot
37
+
38
+ browsers:
39
+ windows-firefox:
40
+ name: "windows-firefox"
41
+ host: 10.211.55.4
42
+ port: 4444
43
+ browser: "*firefox"
44
+
45
+ windows-iexplore:
46
+ name: "windows-iexploreproxy"
47
+ host: 10.211.55.4
48
+ port: 4444
49
+ browser: "*iexploreproxy"
50
+
51
+ linux-firefox:
52
+ name: "linux-firefox"
53
+ host: 10.211.55.5
54
+ port: 4444
55
+ browser: "*firefox"
@@ -0,0 +1,28 @@
1
+ shoots_path: "~/browser_shoots"
2
+
3
+ scripts:
4
+ brandengage:
5
+ name: "brandengage"
6
+ url: "http://staging.iframe.sponsorpay.com"
7
+ commands: |
8
+ open "/test/brandengage.html"
9
+ window_maximize
10
+ click "link=be_1372_dedicated"
11
+ pause 5
12
+ get_alert
13
+ click "link=sp.showVideo();"
14
+ pause 5
15
+ shot
16
+
17
+ browsers:
18
+ windows-firefox:
19
+ name: "windows-firefox"
20
+ host: 10.211.55.4
21
+ port: 4444
22
+ browser: "*firefox"
23
+
24
+ windows-iexplore:
25
+ name: "windows-iexploreproxy"
26
+ host: 10.211.55.4
27
+ port: 4444
28
+ browser: "*iexploreproxy"
@@ -0,0 +1,40 @@
1
+ class BrowserShooter
2
+ module Commander
3
+ def self.execute( command, client, shoot_path )
4
+ BrowserShooter::Logger.log "command: #{command}"
5
+
6
+ if( command.split[0].strip == "shot" )
7
+ sufix = command.split[1] ? command.split[1].strip : nil
8
+
9
+ BrowserShooter::Commander.shot(
10
+ client,
11
+ shoot_path,
12
+ sufix
13
+ )
14
+
15
+ elsif( command.split[0].strip == "pause" )
16
+ BrowserShooter::Commander.pause( command.split[1].strip.to_i )
17
+
18
+ else
19
+ eval "client.#{command}"
20
+
21
+ end
22
+ end
23
+
24
+ def self.shot( client, path, sufix = nil )
25
+ sufix = "_#{sufix}" unless sufix.nil?
26
+ path = "#{path}#{sufix}.png"
27
+
28
+ BrowserShooter::Logger.log "shooting in '#{path}'"
29
+
30
+ File.open( path, "wb" ) do |f|
31
+ f.write( Base64.decode64( client.capture_entire_page_screenshot_to_string( "" ) ) )
32
+ end
33
+ end
34
+
35
+ def self.pause( seconds )
36
+ BrowserShooter::Logger.log "pausing #{seconds} seconds"
37
+ sleep seconds
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ class BrowserShooter
2
+ module Driver
3
+ def self.run_script_on_browser(script, browser, shoots_path)
4
+ BrowserShooter::Logger.log "Runing script '#{script["name"]}' with url '#{script["url"]}' in browser '#{browser["name"]}'"
5
+
6
+ client = nil
7
+
8
+ begin
9
+ client =
10
+ Selenium::Client::Driver.new(
11
+ :host => browser["host"],
12
+ :port => browser["port"],
13
+ :browser => browser["browser"],
14
+ :url => script["url"],
15
+ :timeout_in_seconds => 20
16
+ )
17
+
18
+ client.start_new_browser_session
19
+
20
+ script["commands"].lines.each do |command|
21
+ BrowserShooter::Commander.execute(
22
+ command,
23
+ client,
24
+ "#{shoots_path}/#{script["name"]}_#{browser["name"]}"
25
+ )
26
+ end
27
+
28
+ rescue Exception => e
29
+ BrowserShooter::Logger.log "ERROR: #{e.message}"
30
+ # puts e.backtrace
31
+
32
+ ensure
33
+ client.close_current_browser_session if client
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ class BrowserShooter
2
+ module Logger
3
+ def self.log( message )
4
+ puts "[BrowserShooter #{Time.now.strftime( "%F %T" )}] #{message}"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class BrowserShooter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "./browser_shooter/version"
2
+ require_relative "./browser_shooter/logger"
3
+ require_relative "./browser_shooter/driver"
4
+ require_relative "./browser_shooter/commander"
5
+
6
+ require "selenium-webdriver"
7
+ require "selenium-client"
8
+ require "yaml"
9
+
10
+ class BrowserShooter
11
+ attr_reader :config
12
+
13
+ def initialize( config_file_path )
14
+ @config = load_config( config_file_path )
15
+ end
16
+
17
+ def load_config( config_file_path )
18
+ config = YAML.load_file( config_file_path )
19
+ config = set_up_shoots_path( config )
20
+
21
+ config
22
+ end
23
+
24
+ def run
25
+ config["scripts"].each_value do |script|
26
+ config["browsers"].each_value do |browser|
27
+ BrowserShooter::Driver.run_script_on_browser(script, browser, config["shoots_path"])
28
+ end
29
+ end
30
+ end
31
+
32
+ def set_up_shoots_path( config )
33
+ config["shoots_path"] = File.expand_path( "#{config["shoots_path"]}/#{Time.now.strftime("%Y%m%d%H%M%S")}" )
34
+ BrowserShooter::Logger.log( "shoots_path: #{config["shoots_path"]}" )
35
+
36
+ FileUtils.mkdir_p( config["shoots_path"] )
37
+
38
+ config
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,7 @@
1
+ require_relative "test_helper"
2
+
3
+ class BrowserScreenshotTest < Test::Unit::TestCase
4
+ def test_run
5
+ BrowserShooter.new( "#{FIXTURES}/config.yml" ).run
6
+ end
7
+ end
@@ -0,0 +1,55 @@
1
+ shoots_path: "/tmp/shoots"
2
+
3
+ scripts:
4
+ google:
5
+ name: "google"
6
+ url: "http://www.google.de"
7
+ commands: |
8
+ open "/"
9
+ window_maximize
10
+ shot before
11
+ type "id=lst-ib", "fernando guillen"
12
+ click "name=btnG", wait_for :page
13
+ pause 3
14
+ shot after
15
+
16
+
17
+ miniclip:
18
+ name: "miniclip"
19
+ url: "http://www.miniclip.com/games/de/"
20
+ commands: |
21
+ open "/"
22
+ window_maximize
23
+ shot
24
+
25
+ brandengage:
26
+ name: "brandengage"
27
+ url: "http://staging.iframe.sponsorpay.com"
28
+ commands: |
29
+ open "/test/brandengage.html"
30
+ window_maximize
31
+ click "link=be_1372_dedicated"
32
+ pause 5
33
+ get_alert
34
+ click "link=sp.showVideo();"
35
+ pause 5
36
+ shot
37
+
38
+ browsers:
39
+ windows-firefox:
40
+ name: "windows-firefox"
41
+ host: 10.211.55.4
42
+ port: 4444
43
+ browser: "*firefox"
44
+
45
+ windows-iexplore:
46
+ name: "windows-iexploreproxy"
47
+ host: 10.211.55.4
48
+ port: 4444
49
+ browser: "*iexploreproxy"
50
+
51
+ linux-firefox:
52
+ name: "linux-firefox"
53
+ host: 10.211.55.5
54
+ port: 4444
55
+ browser: "*firefox"
@@ -0,0 +1,4 @@
1
+ require "test/unit"
2
+ require_relative "../lib/browser_shooter"
3
+
4
+ FIXTURES = File.expand_path( "#{File.dirname(__FILE__)}/fixtures" )
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: browser_shooter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Fernando Guillen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-06 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ - rc
33
+ - 6
34
+ version: 1.0.0.rc.6
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ - 9
48
+ - 2
49
+ - 2
50
+ version: 0.9.2.2
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: selenium-webdriver
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: selenium
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: selenium-client
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :runtime
91
+ version_requirements: *id005
92
+ description: Selenium RC wraper to create browser screenshots
93
+ email:
94
+ - fguillen.mail@gmail.com
95
+ executables:
96
+ - browser_shooter
97
+ extensions: []
98
+
99
+ extra_rdoc_files: []
100
+
101
+ files:
102
+ - .gitignore
103
+ - .rvmrc.example
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - bin/browser_shooter
108
+ - browser_shoter.gemspec
109
+ - examples/config1.yml
110
+ - examples/config2.yml
111
+ - lib/browser_shooter.rb
112
+ - lib/browser_shooter/commander.rb
113
+ - lib/browser_shooter/driver.rb
114
+ - lib/browser_shooter/logger.rb
115
+ - lib/browser_shooter/version.rb
116
+ - test/browser_shooter_test.rb
117
+ - test/fixtures/config.yml
118
+ - test/test_helper.rb
119
+ has_rdoc: true
120
+ homepage: https://github.com/fguillen/BrowserShooter
121
+ licenses: []
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ requirements: []
145
+
146
+ rubyforge_project: browser_shooter
147
+ rubygems_version: 1.3.7
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Selenium RC wraper to create browser screenshots
151
+ test_files:
152
+ - test/browser_shooter_test.rb
153
+ - test/fixtures/config.yml
154
+ - test/test_helper.rb