capybara-bamboo-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Capybara::Bamboo::Client
2
+
3
+ This gem helps Bamboo users who have admin access to config/run/stop/enable/disable plans
4
+ but don't have privileges like bulk action perform actions on Bamboo.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'capybara-bamboo-client'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install capybara-bamboo-client
21
+
22
+ ## Usage
23
+
24
+ e.g. My project URL on Bamboo is https://bamboo.neilma.com.au/browse/neil
25
+
26
+ require 'capybara-bamboo-client'
27
+ include Capybara::Bamboo
28
+
29
+ bamboo_client = Client.configure do |config|
30
+ config.bamboo_url = 'https://bamboo.neilma.com.au/browse/neil'
31
+ config.username = 'username'
32
+ config.password = 'password'
33
+ end
34
+
35
+ bamboo_client.login
36
+
37
+ bamboo_client.construct_plans
38
+ bamboo_client.plans.each do |plan|
39
+ plan.disable # Disable all the plans, also can put if condition in to target only wanted plans
40
+ plan.enable # Enable all the plans
41
+ plan.stop
42
+ plan.start
43
+ end
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/[my-github-username]/capybara-bamboo-client/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
Binary file
@@ -0,0 +1,60 @@
1
+ require 'capybara'
2
+ require 'rspec'
3
+ require 'capybara/poltergeist'
4
+ require 'site_prism'
5
+
6
+ Dir[File.expand_path('../capybara-bamboo-client/**/*.rb', __FILE__)].each {|file| require file}
7
+
8
+ module Capybara
9
+ module Bamboo
10
+ module Client
11
+ class << self
12
+ include Capybara::DSL
13
+ include ::RSpec::Matchers
14
+ include BambooHelper
15
+ attr_accessor :bamboo_url, :capybara_timeout, :username, :password, :phantomjs_path, :plans, :app_host
16
+
17
+ def configure
18
+ yield self
19
+ @capybara_timeout ||= 60
20
+ @phantomjs_path ||= File.expand_path('../../drivers/phantomjs.exe', __FILE__)
21
+ @plans = []
22
+ @app_host ||= app_host_from_url(bamboo_url)
23
+ register_driver capybara_timeout, phantomjs_path, app_host
24
+ self
25
+ end
26
+
27
+ def login
28
+ visit bamboo_url
29
+ expect(page.all('createPlanLink').any?).to be false
30
+ click_link 'login'
31
+ fill_in 'loginForm_os_username', with: username || ENV[:BAMBOO_USERNAME]
32
+ fill_in 'loginForm_os_password', with: password || ENV[:BAMBOO_PASSWORD]
33
+ find('#loginForm_save').click
34
+ expect(page).to have_button('createPlanLink')
35
+ end
36
+
37
+ def logout
38
+ reset_session!
39
+ visit bamboo_url
40
+ expect(page).to have_link('login')
41
+ end
42
+
43
+ def construct_plans
44
+ find('table[id="dashboard"]').all('tbody tr').each do |tr|
45
+ tds = tr.all('td')
46
+ plan_name_link = tds.first.find('a')
47
+ plan_key = get_plan_key(plan_name_link[:id])
48
+ operation_links = tds.last.all('a')
49
+ @plans << Plan.new({app_host: app_host, name: plan_name_link.text, key: plan_key,
50
+ url: plan_name_link[:href],
51
+ build_action_url: operation_links.first[:href],
52
+ edit_plan_url: operation_links[1][:href],
53
+ favourite_plan_url: operation_links.last[:href]}).tap{|i| p i.inspect}
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,31 @@
1
+ module Capybara
2
+ module Bamboo
3
+ module Client
4
+ module BambooHelper
5
+
6
+ def self.included(base)
7
+ super
8
+ end
9
+
10
+ def register_driver(timeout, phantomjs_path, app_host)
11
+ Capybara.current_driver = :poltergeist
12
+ Capybara.register_driver :poltergeist do |app|
13
+ Capybara::Poltergeist::Driver.new(app, {js_errors: false, phantomjs: phantomjs_path})
14
+ end
15
+ Capybara.run_server = false
16
+ Capybara.app_host = app_host
17
+ Capybara.default_wait_time = timeout
18
+ end
19
+
20
+ def get_plan_key(link_id)
21
+ link_id.split(':').last
22
+ end
23
+
24
+ def app_host_from_url(bamboo_url)
25
+ /(.*)\/browse\/(.*)/.match(bamboo_url)[1]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ require 'capybara'
2
+
3
+ module Capybara
4
+ module Bamboo
5
+ module Client
6
+ class Plan
7
+ include Capybara::DSL
8
+
9
+ def initialize(opts)
10
+ opts.keys.each do |attr_key|
11
+ self.class.send(:attr_accessor, attr_key)
12
+ instance_variable_set("@#{attr_key}", opts[attr_key])
13
+ end
14
+ end
15
+
16
+ def disable
17
+ visit "/build/admin/suspendBuild.action?returnUrl=%2Fchain%2Fadmin%2Fconfig%2FdefaultStages.action%3FbuildKey%3D#{key}&buildKey=#{key}"
18
+ end
19
+
20
+ def enable
21
+ visit "/build/admin/resumeBuild.action?returnUrl=%2Fchain%2Fadmin%2Fconfig%2FdefaultStages.action%3FbuildKey%3D#{key}&buildKey=#{key}"
22
+ end
23
+
24
+ def start
25
+ visit "/build/admin/triggerManualBuild.action?buildKey=#{key}"
26
+ end
27
+
28
+ def stop
29
+ visit "/build/admin/ajax/stopPlan.action?planKey=#{key}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ module Capybara
2
+ module Bamboo
3
+ module Client
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Client do
4
+
5
+ let(:home_page) {Home.new}
6
+ let(:bamboo_client) do
7
+ Client.configure do |config|
8
+ config.bamboo_url = home_page.url
9
+ config.username = 'test_username'
10
+ config.password = 'test_password'
11
+ config.app_host = 'http://localhost:63342/capybara-bamboo-client/spec/fixtures'
12
+ end
13
+ end
14
+
15
+ context '#configure()' do
16
+ it 'sets bamboo url' do
17
+ expect(bamboo_client.bamboo_url).to eq home_page.url
18
+ end
19
+
20
+ it 'registers capybara driver with specific timeout' do
21
+ expect(bamboo_client.capybara_timeout).to eq 60
22
+ bamboo_client.capybara_timeout = 70
23
+ expect(bamboo_client.capybara_timeout).to eq 70
24
+ end
25
+ end
26
+
27
+ context '#login() and then #logout()' do
28
+ it 'logs in successfully when credentials have been configured' do
29
+ expect{bamboo_client.login}.not_to raise_error
30
+ expect{bamboo_client.logout}.not_to raise_error
31
+ end
32
+ end
33
+
34
+ context 'Logged in' do
35
+ before(:each) {bamboo_client.login}
36
+ context '#construct_plans()' do
37
+ it 'returns all the plans on the dashboard' do
38
+ bamboo_client.construct_plans
39
+ expect(bamboo_client.plans.length).to eq 2
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <a href="login.html" id="login">Log in</a>
8
+ </body>
9
+ </html>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <ul>
8
+ <li id="userInfo">
9
+ </li>
10
+ </ul>
11
+ <button id="createPlanLink">Create</button>
12
+ <a href="home.html" id="log-out">Logout</a>
13
+ <table id="dashboard">
14
+ <tbody>
15
+ <tr>
16
+ <td>
17
+ <a id="viewBuild:plan1" href="plan1.html">Plan1</a>
18
+ </td>
19
+ <td>
20
+ <a id="manualBuild_plan1", style="display:inline"><span>Run</span></a>
21
+ <a id="editBuild_plan1", style="display:inline"><span>Edit 'plan1'</span></a>
22
+ <a id="toggleFavourite_plan1", style="display:inline"><span>Favourite</span></a>
23
+ </td>
24
+ </tr>
25
+ <tr>
26
+ <td>
27
+ <a id="viewBuild:plan2" href="plan2.html">Plan2</a>
28
+ </td>
29
+ <td>
30
+ <a id="manualBuild_plan2", style="display:inline"><span>Run</span></a>
31
+ <a id="editBuild_plan2", style="display:inline"><span>Edit 'plan2'</span></a>
32
+ <a id="toggleFavourite_plan2", style="display:inline"><span>Favourite</span></a>
33
+ </td>
34
+ </tr>
35
+ </tbody>
36
+ </table>
37
+ </body>
38
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <form action="home_logged_in.html" method="post">
8
+ <input type="text" name="os_username" value="" id="loginForm_os_username" autofocus="">
9
+ <input type="password" name="os_password" value="" id="loginForm_os_password">
10
+ <input type="submit" name="save" value="Log in" id="loginForm_save" accesskey="S">
11
+ </form>
12
+ </body>
13
+ </html>
@@ -0,0 +1,5 @@
1
+ class Home < SitePrism::Page
2
+
3
+ set_url "http://localhost:63342/capybara-bamboo-client/spec/fixtures/home.html"
4
+
5
+ end
data/spec/plan_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ include Capybara::Bamboo::Client
4
+ describe Plan do
5
+
6
+ context '#initialize()' do
7
+ it 'dynamically sets up attr accessors' do
8
+ opts = {name: 'plan_name', plan_url: 'plan_url'}
9
+ plan = Plan.new(opts)
10
+ opts.keys.each {|key| expect(plan.send(key)).to eq opts[key] }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'capybara-bamboo-client'
3
+
4
+ describe 'IAG Bamboo Client' do
5
+
6
+ let(:bamboo_client) do
7
+ Client.configure do |config|
8
+ config.bamboo_url = 'https://bamboo.iag.com.au/browse/ITSM'
9
+ config.username = 'yuanming.ma'
10
+ config.password = 'cguweb1'
11
+ end
12
+ end
13
+
14
+ context '#login() and then #logout()' do
15
+ it 'logs in successfully when credentials have been configured' do
16
+ expect{bamboo_client.login}.not_to raise_error
17
+ expect{bamboo_client.logout}.not_to raise_error
18
+ end
19
+ end
20
+
21
+ context 'Logged in' do
22
+ before(:each) {bamboo_client.login}
23
+ context '#construct_plans()' do
24
+ it 'returns all the plans on the dashboard' do
25
+ bamboo_client.construct_plans
26
+ expect(bamboo_client.plans.length).to eq 2
27
+ bamboo_client.plans.each do |plan|
28
+ plan.disable if plan.name == 'UAT'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ Dir[File.expand_path('../../lib/**/*.rb', __FILE__)].each {|file| require file}
2
+ Dir[File.expand_path('../fixtures/*.rb', __FILE__)].each {|file| require file}
3
+ Dir[File.expand_path('../pages/*.rb', __FILE__)].each {|file| require file}
4
+ include Capybara::Bamboo
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-bamboo-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Neil Ma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.5
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: capybara
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: poltergeist
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Capybara-driven, Bamboo interactions with limited admin access
95
+ email:
96
+ - mayuanming@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - lib/capybara-bamboo-client/bamboo_helper.rb
102
+ - lib/capybara-bamboo-client/plan.rb
103
+ - lib/capybara-bamboo-client/version.rb
104
+ - lib/capybara-bamboo-client.rb
105
+ - spec/client_spec.rb
106
+ - spec/fixtures/home.html
107
+ - spec/fixtures/home_logged_in.html
108
+ - spec/fixtures/login.html
109
+ - spec/pages/home.rb
110
+ - spec/plan_spec.rb
111
+ - spec/real_client_spec.rb
112
+ - spec/spec_helper.rb
113
+ - drivers/phantomjs.exe
114
+ - README.md
115
+ homepage: https://github.com/neilma/capybara-bamboo-client
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.29
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Capybara-driven, Bamboo interactions with limited admin access
140
+ test_files:
141
+ - spec/client_spec.rb
142
+ - spec/fixtures/home.html
143
+ - spec/fixtures/home_logged_in.html
144
+ - spec/fixtures/login.html
145
+ - spec/pages/home.rb
146
+ - spec/plan_spec.rb
147
+ - spec/real_client_spec.rb
148
+ - spec/spec_helper.rb