selenium-dsl 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,7 @@
1
1
  source "https://rubygems.org"
2
-
3
- group :test do
4
- gem "minitest"
5
- end
6
-
7
2
  gem "selenium-webdriver"
8
- gem "pry"
9
- gem "term-ansicolor"
3
+ gem "term-ansicolor"
4
+ # gem "pry"
5
+ # group :test do
6
+ # gem "minitest"
7
+ # end
@@ -4,29 +4,21 @@ GEM
4
4
  addressable (2.3.2)
5
5
  childprocess (0.3.6)
6
6
  ffi (~> 1.0, >= 1.0.6)
7
- coderay (1.0.8)
8
7
  ffi (1.1.5)
9
8
  libwebsocket (0.1.5)
10
9
  addressable
11
- method_source (0.8.1)
12
- minitest (4.2.0)
13
- multi_json (1.3.7)
14
- pry (0.9.10)
15
- coderay (~> 1.0.5)
16
- method_source (~> 0.8)
17
- slop (~> 3.3.1)
10
+ multi_json (1.4.0)
18
11
  rubyzip (0.9.9)
19
12
  selenium-webdriver (2.26.0)
20
13
  childprocess (>= 0.2.5)
21
14
  libwebsocket (~> 0.1.3)
22
15
  multi_json (~> 1.0)
23
16
  rubyzip
24
- slop (3.3.3)
17
+ term-ansicolor (1.0.7)
25
18
 
26
19
  PLATFORMS
27
20
  ruby
28
21
 
29
22
  DEPENDENCIES
30
- minitest
31
- pry
32
23
  selenium-webdriver
24
+ term-ansicolor
data/bin/sd CHANGED
@@ -1,4 +1,49 @@
1
1
  require 'selenium_dsl'
2
2
 
3
- codes = IO.read(ARGV[0])
4
- SeleniumDsl.parser(codes,ARGV[1])
3
+ if ARGV.length>0
4
+ codes = IO.read(ARGV[0])
5
+ SeleniumDsl.parser(codes,ARGV[1])
6
+ else
7
+ puts <<END
8
+ Selenium DSL
9
+ ============
10
+ > selenium-dsl <script-file> [-mqv] #OR
11
+ > sd <script-file> [-mqv]
12
+ --------------------------
13
+ m: mono --> no color
14
+ q: quit --> closing browser
15
+ v: verbose --> parsing output
16
+
17
+ Script-Reference:
18
+ -----------------
19
+ eng: <string> [params] --> Commands
20
+ ex: firefox
21
+ visit http://google.com
22
+ *browser: (firefox | chrome | remote | phantomjs)*
23
+ cmd: <css-cmd> --> DOM Query (DQ)
24
+ ex: li.g[1]>a
25
+ cmd: <css-cmd>[=<value>] --> DQ and attr value=Id0123
26
+ ex: :input_id=Id0123 # <input name="input_id"/>
27
+ cmd: <css-cmd>[~<action>] --> DQ and action (DQA)
28
+ ex: li.g[1]>a~click
29
+ cmd: <css-cmd>[~<action>][=~<text>] --> DQA and check node text
30
+ ex: li.g[1]>a~text=~Home
31
+ cmd: <css-cmd>[@<attr>][=~<text>] --> DQ and check node attr
32
+ ex: :input_id@value=~ayam
33
+
34
+ Script-BASH-for-cron-job
35
+ ------------------------
36
+ #!/bin/bash
37
+ txt=`sd my-website -mq`
38
+ if [ $? -ne 0 ]
39
+ then
40
+ echo "Error!!!"
41
+ echo -e "\\r\\n $txt" > elog.txt
42
+ cat emsg.txt elog.txt > email.txt
43
+ ssmtp site.monitor@gmail.com < email.txt
44
+ else echo "OK"
45
+ fi
46
+
47
+ https://github.com/wharsojo/selenium-dsl - Enjoy!!!
48
+ END
49
+ end
@@ -1,4 +1,49 @@
1
1
  require 'selenium_dsl'
2
2
 
3
- codes = IO.read(ARGV[0])
4
- SeleniumDsl.parser(codes,ARGV[1])
3
+ if ARGV.length>0
4
+ codes = IO.read(ARGV[0])
5
+ SeleniumDsl.parser(codes,ARGV[1])
6
+ else
7
+ puts <<END
8
+ Selenium DSL
9
+ ============
10
+ > selenium-dsl <script-file> [-mqv] #OR
11
+ > sd <script-file> [-mqv]
12
+ --------------------------
13
+ m: mono --> no color
14
+ q: quit --> closing browser
15
+ v: verbose --> parsing output
16
+
17
+ Script-Reference:
18
+ -----------------
19
+ eng: <string> [params] --> Commands
20
+ ex: firefox
21
+ visit http://google.com
22
+ *browser: (firefox | chrome | remote | phantomjs)*
23
+ cmd: <css-cmd> --> DOM Query (DQ)
24
+ ex: li.g[1]>a
25
+ cmd: <css-cmd>[=<value>] --> DQ and attr value=Id0123
26
+ ex: :input_id=Id0123 # <input name="input_id"/>
27
+ cmd: <css-cmd>[~<action>] --> DQ and action (DQA)
28
+ ex: li.g[1]>a~click
29
+ cmd: <css-cmd>[~<action>][=~<text>] --> DQA and check node text
30
+ ex: li.g[1]>a~text=~Home
31
+ cmd: <css-cmd>[@<attr>][=~<text>] --> DQ and check node attr
32
+ ex: :input_id@value=~ayam
33
+
34
+ Script-BASH-for-cron-job
35
+ ------------------------
36
+ #!/bin/bash
37
+ txt=`sd my-website -mq`
38
+ if [ $? -ne 0 ]
39
+ then
40
+ echo "Error!!!"
41
+ echo -e "\\r\\n $txt" > elog.txt
42
+ cat emsg.txt elog.txt > email.txt
43
+ ssmtp site.monitor@gmail.com < email.txt
44
+ else echo "OK"
45
+ fi
46
+
47
+ https://github.com/wharsojo/selenium-dsl - Enjoy!!!
48
+ END
49
+ end
@@ -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'
7
7
 
8
8
  require 'term/ansicolor'
9
9
  include Term::ANSIColor
@@ -16,7 +16,7 @@ class SeleniumDsl
16
16
 
17
17
  def init
18
18
  nodes = /^(\>*([\-\w]*(\.[.\[\]\-\d\w]+|[#:][\-\d\w]+)|\w+(\[\w+\=[\d\w"]+\])*)|\/[\w@"=\[\]]+)(\[\d+\])*/
19
- action = /^[~]\w+(\:\w+)*/
19
+ action = /^[~@]\w+(\:\w+)*/
20
20
  @driver = nil
21
21
  @nodes = nil
22
22
  @return = nil
@@ -24,7 +24,7 @@ class SeleniumDsl
24
24
  @code = {}
25
25
  @path = '~'
26
26
  @opt = ''
27
- @r_eng = [/^(mock|debug|chrome|firefox|remote|phantomjs|visit|wait|quit|if)/]
27
+ @r_eng = [/^(chrome|firefox|remote|phantomjs|visit|wait|quit|if)/] #mock|debug|
28
28
  @r_mcr = [/^\$[\-\w]+ *\=/,/^\$[\-\w]+[^\=]/]
29
29
  @r_cmd = [nodes, action]
30
30
  @r_mod = [/^(def +|end)/]
@@ -64,13 +64,22 @@ class SeleniumDsl
64
64
  stx = parse_cmd(line) if !stx
65
65
  stx = parse_fnc(line) if !stx
66
66
  end
67
+ @driver.quit if opt_q && @driver
67
68
  print "\n"
68
69
  end
69
70
 
70
71
  private
71
72
 
73
+ def opt_m
74
+ @opt=~/\-.*[m]/
75
+ end
76
+
77
+ def opt_q
78
+ @opt=~/\-.*[q]/
79
+ end
80
+
72
81
  def opt_v
73
- @opt=~/\-[v]/
82
+ @opt=~/\-.*[v]/
74
83
  end
75
84
 
76
85
  def _code_
@@ -108,19 +117,22 @@ class SeleniumDsl
108
117
  end
109
118
 
110
119
  def failed
111
- print 'F'.red if !opt_v
120
+ print (opt_m ? 'F' : 'F'.red) if !opt_v
112
121
  c = _code_
113
122
  l = c[:line]
114
123
  r = c[:code]
115
124
  y = 2
116
- puts "\n=====>>>>ASSERT FAILED!!!<<<<=====".yellow
125
+ e = "\n=====>>>>ASSERT FAILED!!!<<<<====="
126
+ puts (opt_m ? e : e.yellow)
117
127
  y.times do |idx|
118
128
  no = (l-y)+idx
119
- tx = r[no].send(idx<(y-1) ? :green : :red)
129
+ tx = "#{r[no]}#{idx<(y-1) ? '' : ' ...Error'}"
130
+ tx = (idx<(y-1) ? tx.green : tx.red) if !opt_m
120
131
  puts "#{no+1}. #{tx}"
121
132
  end
122
133
  puts "#{l+1}. #{r[l]}" if r[l]
123
- puts caller
134
+ # puts caller
135
+ @driver.quit if opt_q && @driver
124
136
  Kernel.exit(1)
125
137
  end
126
138
  end
@@ -41,9 +41,9 @@ class SeleniumDsl
41
41
  @nodes = nodes if nodes
42
42
  nodes
43
43
  end
44
- print '.'.green if !opt_v
45
- # rescue Exception => e
46
- # failed
44
+ print (opt_m ? '.' : '.'.green) if !opt_v
45
+ rescue Exception => e
46
+ failed
47
47
  end
48
48
 
49
49
  def find_elements(typ,el,idx)
@@ -71,9 +71,9 @@ class SeleniumDsl
71
71
  @nodes = nodes if nodes
72
72
  nodes
73
73
  end
74
- print '.'.green if !opt_v
75
- # rescue Exception => e
76
- # failed
74
+ print (opt_m ? '.' : '.'.green) if !opt_v
75
+ rescue Exception => e
76
+ failed
77
77
  end
78
78
 
79
79
  def parse_cmd(line)
@@ -118,10 +118,15 @@ class SeleniumDsl
118
118
  if cmd==[] #no command supplied
119
119
  cmd << "~val" if (str=prm[/[=~]+/]) && str.length==1
120
120
  end
121
- c1,c2 = cmd[0].split(':',2)
122
- if (exc = in_commands?(c1))
123
- @return = nil
124
- send("_#{exc}",prm,c2)
121
+ if cmd[0][0]=="@"
122
+ @return = @nodes.attribute(cmd[0][1,99])
123
+ assert(prm)
124
+ else
125
+ c1,c2 = cmd[0].split(':',2)
126
+ if (exc = in_commands?(c1))
127
+ @return = nil
128
+ send("_#{exc}",prm,c2)
129
+ end
125
130
  end
126
131
  true
127
132
  else
@@ -152,9 +157,9 @@ class SeleniumDsl
152
157
  line = prm.strip.split(splt,2)
153
158
  if line.length==2
154
159
  if (parse_cmd(line[0]) && eval("\"#{@return}\" #{splt} /#{line[1]}/"))
155
- print '.'.green if !opt_v
160
+ print (opt_m ? '.' : '.'.green) if !opt_v
156
161
  else
157
- failed #print 'F'.red if !opt_v
162
+ failed #print (opt_m ? 'F' : 'F'.red) if !opt_v
158
163
  end
159
164
  end
160
165
  end
@@ -173,7 +178,7 @@ class SeleniumDsl
173
178
  def assert(prm)
174
179
  if prm[0,2]=='=~'
175
180
  if @return =~ /#{prm[2,99].strip}/
176
- print '.'.green if !opt_v
181
+ print (opt_m ? '.' : '.'.green) if !opt_v
177
182
  else
178
183
  failed
179
184
  end
@@ -47,9 +47,9 @@ class SeleniumDsl
47
47
  @mock = true
48
48
  end
49
49
 
50
- def _debug(prm)
51
- binding.pry
52
- end
50
+ # def _debug(prm)
51
+ # binding.pry
52
+ # end
53
53
 
54
54
  def _visit(prm)
55
55
  _firefox('') if !@driver
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
  s.executables = ["sd","selenium-dsl"]
20
20
  s.add_runtime_dependency "selenium-webdriver"
21
- s.add_runtime_dependency "pry"
22
21
  s.add_runtime_dependency "term-ansicolor"
23
- s.post_install_message = ">>Enjoy your SDSL!!!<<"
22
+ # s.add_runtime_dependency "pry"
23
+ s.post_install_message = "\ncmd: sd [Enter]\n>>Enjoy your Selenium DSL!!!<<"
24
24
  end
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.3
4
+ version: 0.1.5
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-12 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: pry
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: term-ansicolor
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +65,11 @@ files:
81
65
  - lib/selenium_dsl/macros.rb
82
66
  homepage: http://github.com/wharsojo/selenium-dsl
83
67
  licenses: []
84
- post_install_message: ! '>>Enjoy your SDSL!!!<<'
68
+ post_install_message: ! '
69
+
70
+ cmd: sd [Enter]
71
+
72
+ >>Enjoy your Selenium DSL!!!<<'
85
73
  rdoc_options: []
86
74
  require_paths:
87
75
  - lib