lazyman 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,7 @@ A simple web automation test framework using [selenium-webdriver](http://docs.se
5
5
 
6
6
  The philosophy of lazyman is 'do less, gain more'.
7
7
 
8
- Now lazyman only tested in windows, other platformes are going to be tested soon.
8
+ Now lazyman only tested in windows with Ruby193, other platformes are going to be tested soon.
9
9
 
10
10
  Install lazyman
11
11
  ---------------
@@ -13,7 +13,7 @@ Install lazyman from rubygems
13
13
 
14
14
  gem install lazyman
15
15
 
16
- Or clone from github
16
+ Or clone from github, build the gem and install
17
17
 
18
18
  If you have any issue when install lazyman, install the gems below:
19
19
 
@@ -36,8 +36,12 @@ By default, lazyman runs examples using chrome browser, so make sure you install
36
36
  Using following command to make everything running.
37
37
 
38
38
  cd your_project_name
39
+ lazyman go -f doc
40
+ or
39
41
  rspec -f doc
40
42
 
43
+ lazyman go command supports all the rspec options and it is the recommend way.
44
+
41
45
  Understand lazyman project structure
42
46
  ------------------------------------
43
47
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lazyman"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["easonhan"]
12
- s.date = "2013-04-07"
12
+ s.date = "2013-04-10"
13
13
  s.description = "A test framework using watir-webdriver rspec and page-object"
14
14
  s.email = "nbkhic@qq.com"
15
15
  s.executables = ["lazyman"]
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "lib/lazyman/generators/lazyman/app/pages/baidu/search_result_page.rb.tt",
44
44
  "lib/lazyman/generators/lazyman/app/pages/components/.empty_directory",
45
45
  "lib/lazyman/generators/lazyman/app/reports/.empty_directory",
46
+ "lib/lazyman/generators/lazyman/app/test_data/baidu.yml",
46
47
  "lib/lazyman/generators/lazyman/config/config.yml",
47
48
  "lib/lazyman/lazy_config.rb",
48
49
  "lib/lazyman/lazy_initializer.rb",
@@ -59,6 +60,7 @@ Gem::Specification.new do |s|
59
60
  "spec/lazy_config_spec.rb",
60
61
  "spec/lazy_initializer_spec.rb",
61
62
  "spec/lazy_navigator_spec.rb",
63
+ "spec/lazy_page_spec.rb",
62
64
  "spec/pages/components/footer.rb",
63
65
  "spec/pages/test_page.rb",
64
66
  "spec/spec_helper.rb"
@@ -10,7 +10,7 @@ module Lazyman
10
10
  File.join File.dirname(__FILE__), 'generators'
11
11
  end
12
12
 
13
- desc 'create project', 'create a lazyman project'
13
+ desc 'new project', 'create a lazyman project'
14
14
 
15
15
  def new
16
16
  if app_name
@@ -19,6 +19,14 @@ module Lazyman
19
19
  say 'no app name'
20
20
  end
21
21
  end
22
+
23
+ desc 'go', 'run test case with rspec'
24
+
25
+ def go
26
+ ARGV.shift
27
+ puts "rspec #{ARGV.join('')}" if $debug
28
+ run "rspec #{ARGV.join('')}"
29
+ end
22
30
 
23
31
  end
24
32
  CLI.start
@@ -2,4 +2,5 @@ module Lazyman
2
2
  class LasymanError < StandardError; end
3
3
  class ConfigFileMissingError < LasymanError; end
4
4
  class IncorrectConfigFileError < LasymanError; end
5
+ class InvalidLazymanPageError < LasymanError; end
5
6
  end #Lazyman
@@ -8,7 +8,7 @@ describe 'An example show you how to use lazyman' do
8
8
  end
9
9
 
10
10
  it 'should search baidu using key word' do
11
- baidu_page = @navi.goto_baidu_page
11
+ baidu_page = $navi.goto_baidu_page
12
12
  baidu_page.keyword = @keyword
13
13
  baidu_page.search_element.click
14
14
  result_page = SearchResultPage.new baidu_page.browser
@@ -16,7 +16,7 @@ describe 'An example show you how to use lazyman' do
16
16
  end
17
17
 
18
18
  it 'should have correct search result' do
19
- baidu_page = @navi.goto_baidu_page
19
+ baidu_page = $navi.goto_baidu_page
20
20
  result_page = baidu_page.search_for @keyword
21
21
  result_page.first_result.should eq 'watir-webdriver_百度百科'
22
22
  end
@@ -1,4 +1,7 @@
1
1
  require 'rubygems' #for ruby187
2
+ require 'erb'
3
+ require 'psych'
4
+
2
5
  begin
3
6
  require 'lazyman'
4
7
  rescue LoadError
@@ -9,11 +12,22 @@ Lazyman::Initializer.new(File.expand_path(File.join('.')), '<%= app_name %>')
9
12
  $:.unshift(File.expand_path File.join('.'))
10
13
 
11
14
  RSpec.configure do |c|
15
+
16
+ def test_data file
17
+ content = ''
18
+ file_path = File.expand_path(File.join('.', 'app', 'test_data', "#{file}.yml"))
19
+ raise "Can not find #{file}.yml" unless File.exists?(file_path)
20
+ File.open(file_path, 'r') do |handle|
21
+ content = handle.read
22
+ end
23
+ Psych.load ERB.new(content).result(binding)
24
+ end
25
+
12
26
  c.before(:all) do
13
- @navi = <%= app_name.camelize %>Navigator.new $config
27
+ $navi = <%= app_name.camelize %>Navigator.new $config
14
28
  end
15
29
 
16
30
  c.after(:all) do
17
- @navi.close
31
+ $navi.close
18
32
  end
19
33
  end
@@ -7,18 +7,10 @@ class BaiduPage < <%= app_name.camelize%>Page
7
7
  text_field 'keyword', id: 'kw'
8
8
  button 'search', id: 'su'
9
9
 
10
- def keyword_text_field
11
- @browser.text_field(id: 'kw')
12
- end
13
-
14
- def search_button
15
- @browser.button(id: 'su')
16
- end
17
-
18
10
  def search_for kw
19
- keyword_text_field.set kw
20
- search_button.click
21
- SearchResultPage.new @browser
11
+ self.keyword = kw
12
+ search_element.click
13
+ turn_to SearchResultPage
22
14
  end
23
15
 
24
16
  end
@@ -0,0 +1,4 @@
1
+ ---
2
+ one:
3
+ keyword=: '<%= 1.day.ago %>'
4
+ search_element: 'click'
@@ -1,6 +1,35 @@
1
+ require 'lazyman/errors'
1
2
  module Lazyman
2
3
  class Page
3
4
  include PageObject
4
- end
5
+
6
+ def method_missing(m, *args, &blk)
7
+ if @browser.respond_to? m
8
+ @browser.send(m, *args, &blk)
9
+ else
10
+ super
11
+ end #if
12
+ end
13
+
14
+ def turn_to kls
15
+ raise InvalidLazymanPageError unless kls <= Lazyman::Page
16
+ kls.new(@browser)
17
+ end
18
+
19
+ def data_driven hash, &blk
20
+ raise ArgumentError unless hash.is_a?(Hash)
21
+ hash.each do |mtd, data|
22
+ m_with_eql = (mtd.to_s + '=').to_sym
23
+ if respond_to?(m_with_eql)
24
+ #self.send(m_with_eql, data)
25
+ eval "self.#{m_with_eql.to_s}(data)"
26
+ elsif respond_to?(mtd.to_sym)
27
+ self.send(mtd.to_sym).send(data.to_sym)
28
+ end #if
29
+ end #each
30
+ class_eval &blk if block_given?
31
+ end
32
+
33
+ end #Page
5
34
 
6
35
  end #Lazyman
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lazyman::Page do
4
+ before :all do
5
+ @app_name = 'test'
6
+ Lazyman::Initializer.new File.dirname(__FILE__), @app_name
7
+ end
8
+
9
+ before(:each) do
10
+ @browser = mock_watir_browser
11
+ end
12
+
13
+ def mock_watir_browser
14
+ watir_browser = double('watir')
15
+ watir_browser.stub!(:is_a?).with(anything()).and_return(false)
16
+ watir_browser.stub!(:is_a?).with(Watir::Browser).and_return(true)
17
+ watir_browser
18
+ end
19
+
20
+ it 'method missing' do
21
+ @browser.stub :close
22
+ @browser.should_receive :close
23
+ Lazyman::Page.new(@browser).close
24
+ end
25
+
26
+ it 'should turn to page' do
27
+ p = Lazyman::Page.new(@browser).turn_to TestPage
28
+ p.is_a?(TestPage).should be_true
29
+ end
30
+
31
+ it 'should data driven with hash' do
32
+ btn = double();
33
+ hash = {:one => 'click', :two => 'ok'}
34
+
35
+ p = TestPage.new(@browser)
36
+ p.stub(:one).and_return(btn)
37
+ p.stub(:two=)
38
+ btn.should_receive(:click)
39
+ p.should_receive(:one)
40
+ p.should_receive(:two=).with('ok')
41
+ p.data_driven(hash)
42
+ end
43
+
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazyman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-07 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &24142308 !ruby/object:Gem::Requirement
16
+ requirement: &23821080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.13.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24142308
24
+ version_requirements: *23821080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: page-object
27
- requirement: &24142008 !ruby/object:Gem::Requirement
27
+ requirement: &23820792 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.6.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24142008
35
+ version_requirements: *23820792
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &24141720 !ruby/object:Gem::Requirement
38
+ requirement: &23820504 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.14.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *24141720
46
+ version_requirements: *23820504
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: active_support
49
- requirement: &24141432 !ruby/object:Gem::Requirement
49
+ requirement: &23820216 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.0.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *24141432
57
+ version_requirements: *23820216
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &24141120 !ruby/object:Gem::Requirement
60
+ requirement: &23819928 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.12'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *24141120
68
+ version_requirements: *23819928
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &24140832 !ruby/object:Gem::Requirement
71
+ requirement: &23819640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *24140832
79
+ version_requirements: *23819640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &24140532 !ruby/object:Gem::Requirement
82
+ requirement: &23819352 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.8.4
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *24140532
90
+ version_requirements: *23819352
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &24140232 !ruby/object:Gem::Requirement
93
+ requirement: &23819064 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 2.13.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *24140232
101
+ version_requirements: *23819064
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: page-object
104
- requirement: &24139944 !ruby/object:Gem::Requirement
104
+ requirement: &23818776 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.8.6.1
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *24139944
112
+ version_requirements: *23818776
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: thor
115
- requirement: &24164232 !ruby/object:Gem::Requirement
115
+ requirement: &23834868 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.14.6
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *24164232
123
+ version_requirements: *23834868
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: active_support
126
- requirement: &24163944 !ruby/object:Gem::Requirement
126
+ requirement: &23834580 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: 3.0.0
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *24163944
134
+ version_requirements: *23834580
135
135
  description: A test framework using watir-webdriver rspec and page-object
136
136
  email: nbkhic@qq.com
137
137
  executables:
@@ -166,6 +166,7 @@ files:
166
166
  - lib/lazyman/generators/lazyman/app/pages/baidu/search_result_page.rb.tt
167
167
  - lib/lazyman/generators/lazyman/app/pages/components/.empty_directory
168
168
  - lib/lazyman/generators/lazyman/app/reports/.empty_directory
169
+ - lib/lazyman/generators/lazyman/app/test_data/baidu.yml
169
170
  - lib/lazyman/generators/lazyman/config/config.yml
170
171
  - lib/lazyman/lazy_config.rb
171
172
  - lib/lazyman/lazy_initializer.rb
@@ -182,6 +183,7 @@ files:
182
183
  - spec/lazy_config_spec.rb
183
184
  - spec/lazy_initializer_spec.rb
184
185
  - spec/lazy_navigator_spec.rb
186
+ - spec/lazy_page_spec.rb
185
187
  - spec/pages/components/footer.rb
186
188
  - spec/pages/test_page.rb
187
189
  - spec/spec_helper.rb
@@ -200,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
202
  version: '0'
201
203
  segments:
202
204
  - 0
203
- hash: -704091149
205
+ hash: 433021533
204
206
  required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  none: false
206
208
  requirements: