selenium-dsl 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/sd CHANGED
@@ -2,18 +2,29 @@ require 'selenium_dsl'
2
2
 
3
3
  if ARGV.length>0
4
4
  codes = IO.read(ARGV[0])
5
- SeleniumDsl.parser(codes,ARGV[1])
5
+ SeleniumDsl.parser(codes,ARGV[1,99])
6
6
  else
7
7
  puts <<END
8
8
  Selenium DSL
9
9
  ============
10
- > selenium-dsl <script-file> [-mqv] #OR
11
- > sd <script-file> [-mqv]
10
+ > selenium-dsl <script-file> [-mqrsv] #OR
11
+ > sd <script-file> [-mqrsv]
12
12
  --------------------------
13
13
  m: mono --> no color
14
- q: quit --> closing browser
14
+ q: quit --> close browser
15
+ r: resize --> resize browser
16
+ s: screenshot> error, screenshot!
15
17
  v: verbose --> parsing output
16
18
 
19
+ Ex:
20
+ > sd go-test -m -q -v -r:800x600 -s:error_image
21
+ > sd go-test -mqv -r:800x600 -s:error_image
22
+ > sd go-test -mqvr:800x600 -s:error_image
23
+ > sd go-test -mqvsr:800x600
24
+ > sd go-test -qr:800x600
25
+ > sd go-test -q
26
+ > sd go-test
27
+
17
28
  Script-Reference:
18
29
  -----------------
19
30
  eng: <string> [params] --> Commands
@@ -34,7 +45,7 @@ cmd: <css-cmd>[@<attr>][=~<text>] --> DQ and check node attr
34
45
  Script-BASH-for-cron-job
35
46
  ------------------------
36
47
  #!/bin/bash
37
- txt=`sd my-website -mq`
48
+ txt=`sd my-website -mqs`
38
49
  if [ $? -ne 0 ]
39
50
  then
40
51
  echo "Error!!!"
@@ -2,18 +2,29 @@ require 'selenium_dsl'
2
2
 
3
3
  if ARGV.length>0
4
4
  codes = IO.read(ARGV[0])
5
- SeleniumDsl.parser(codes,ARGV[1])
5
+ SeleniumDsl.parser(codes,ARGV[1,99])
6
6
  else
7
7
  puts <<END
8
8
  Selenium DSL
9
9
  ============
10
- > selenium-dsl <script-file> [-mqv] #OR
11
- > sd <script-file> [-mqv]
10
+ > selenium-dsl <script-file> [-mqrsv] #OR
11
+ > sd <script-file> [-mqrsv]
12
12
  --------------------------
13
13
  m: mono --> no color
14
- q: quit --> closing browser
14
+ q: quit --> close browser
15
+ r: resize --> resize browser
16
+ s: screenshot> error, screenshot!
15
17
  v: verbose --> parsing output
16
18
 
19
+ Ex:
20
+ > sd go-test -m -q -v -r:800x600 -s:error_image
21
+ > sd go-test -mqv -r:800x600 -s:error_image
22
+ > sd go-test -mqvr:800x600 -s:error_image
23
+ > sd go-test -mqvsr:800x600
24
+ > sd go-test -qr:800x600
25
+ > sd go-test -q
26
+ > sd go-test
27
+
17
28
  Script-Reference:
18
29
  -----------------
19
30
  eng: <string> [params] --> Commands
@@ -34,7 +45,7 @@ cmd: <css-cmd>[@<attr>][=~<text>] --> DQ and check node attr
34
45
  Script-BASH-for-cron-job
35
46
  ------------------------
36
47
  #!/bin/bash
37
- txt=`sd my-website -mq`
48
+ txt=`sd my-website -mqs`
38
49
  if [ $? -ne 0 ]
39
50
  then
40
51
  echo "Error!!!"
@@ -3,7 +3,7 @@ require 'selenium_dsl/commands'
3
3
  require 'selenium_dsl/engines'
4
4
  require 'selenium_dsl/modules'
5
5
  require 'selenium_dsl/macros'
6
- # require 'pry'
6
+ require 'pry' if ARGV[1]=~/\-.*[d]/
7
7
 
8
8
  require 'term/ansicolor'
9
9
  include Term::ANSIColor
@@ -23,8 +23,8 @@ class SeleniumDsl
23
23
  @mock = false
24
24
  @code = {}
25
25
  @path = '~'
26
- @opt = ''
27
- @r_eng = [/^(chrome|firefox|remote|phantomjs|visit|wait|quit|if)/] #mock|debug|
26
+ @opt = []
27
+ @r_eng = [/^(debug|chrome|firefox|phantomjs|remote|resize|visit|wait|quit|if|screenshot)/] #mock|debug|
28
28
  @r_mcr = [/^\$[\-\w]+ *\=/,/^\$[\-\w]+[^\=]/]
29
29
  @r_cmd = [nodes, action]
30
30
  @r_mod = [/^(def +|end)/]
@@ -70,16 +70,28 @@ class SeleniumDsl
70
70
 
71
71
  private
72
72
 
73
+ def opt_d
74
+ (opt=@opt.select{|x|x=~/\-\w*[d]/})==[] ? nil : opt[0]
75
+ end
76
+
73
77
  def opt_m
74
- @opt=~/\-.*[m]/
78
+ (opt=@opt.select{|x|x=~/\-\w*[m]/})==[] ? nil : opt[0]
75
79
  end
76
80
 
77
81
  def opt_q
78
- @opt=~/\-.*[q]/
82
+ (opt=@opt.select{|x|x=~/\-\w*[q]/})==[] ? nil : opt[0]
83
+ end
84
+
85
+ def opt_r
86
+ (opt=@opt.select{|x|x=~/\-\w*[r]/})==[] ? nil : opt[0]
87
+ end
88
+
89
+ def opt_s
90
+ (opt=@opt.select{|x|x=~/\-\w*[s]/})==[] ? nil : opt[0]
79
91
  end
80
92
 
81
93
  def opt_v
82
- @opt=~/\-.*[v]/
94
+ (opt=@opt.select{|x|x=~/\-\w*[v]/})==[] ? nil : opt[0]
83
95
  end
84
96
 
85
97
  def _code_
@@ -131,8 +143,15 @@ class SeleniumDsl
131
143
  puts "#{no+1}. #{tx}"
132
144
  end
133
145
  puts "#{l+1}. #{r[l]}" if r[l]
134
- # puts caller
146
+ if (opt=opt_s)
147
+ if (arr=opt.split(':',2)).length>1
148
+ @driver.save_screenshot("#{arr[1]}.png")
149
+ else
150
+ @driver.save_screenshot("#{ARGV[0]}-error_#{l}.png")
151
+ end
152
+ end
135
153
  @driver.quit if opt_q && @driver
154
+ # puts caller
136
155
  Kernel.exit(1)
137
156
  end
138
157
  end
@@ -24,13 +24,22 @@ class SeleniumDsl
24
24
 
25
25
  private
26
26
  def _chrome(prm)
27
- @driver = Selenium::WebDriver.for :chrome
27
+ profile = Selenium::WebDriver::Chrome::Profile.new
28
+ @driver = Selenium::WebDriver.for :chrome, :profile => profile
29
+ if (opr=opt_r) && opr=~/[:]/
30
+ res = opr.sub(/.*[:]/,'').split('x',2).collect{|x|x.to_i}
31
+ @driver.manage.window.size=Selenium::WebDriver::Dimension.new(*res)
32
+ end
28
33
  end
29
34
 
30
35
  def _firefox(prm)
31
36
  profile = Selenium::WebDriver::Firefox::Profile.new
32
- profile['browser.cache.disk.enable'] = false
37
+ profile['browser.cache.disk.enable'] = false
33
38
  @driver = Selenium::WebDriver.for :firefox, :profile => profile
39
+ if (opr=opt_r) && opr=~/[:]/
40
+ res = opr.sub(/.*[:]/,'').split('x',2).collect{|x|x.to_i}
41
+ @driver.manage.window.size=Selenium::WebDriver::Dimension.new(*res)
42
+ end
34
43
  end
35
44
 
36
45
  def _phantomjs(prm)
@@ -43,13 +52,24 @@ class SeleniumDsl
43
52
  @driver = Selenium::WebDriver.for(:remote, :url => prm)
44
53
  end
45
54
 
55
+ def _resize(prm)
56
+ res = prm.split('x',2).collect{|x|x.to_i}
57
+ @driver.manage.window.size=Selenium::WebDriver::Dimension.new(*res)
58
+ end
59
+
60
+ def _screenshot(prm)
61
+ @driver.save_screenshot(prm)
62
+ end
63
+
46
64
  def _mock(prm)
47
65
  @mock = true
48
66
  end
49
67
 
50
- # def _debug(prm)
51
- # binding.pry
52
- # end
68
+ if ARGV[1]=~/\-.*[d]/
69
+ def _debug(prm)
70
+ binding.pry
71
+ end
72
+ end
53
73
 
54
74
  def _visit(prm)
55
75
  _firefox('') if !@driver
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver