webdrone 0.9.8 → 0.9.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3a26ea163cdfb711c8037ff6e8550bb9ba27787
4
- data.tar.gz: 02e5a85d31ddde91b0448c24a7ee48d5ba759db4
3
+ metadata.gz: 2a8be3ed6b1bf005705bffb2b3ad835a65b02ae4
4
+ data.tar.gz: 4694591f750bc154f188a5deb4443429c18464b7
5
5
  SHA512:
6
- metadata.gz: f55b9f99a04f3b36013c2371f7ff5ff567889dad77cb0d3d68b3f51556ca2386a0e7d66ff1b33c5c797618725ba4444670197d04a6a81413d8897828063ffbf3
7
- data.tar.gz: 38be7081da5b436cefaf46c3fa80663e98a0ae0343e0f3a8f3c2fc17c33a8efaec0c1dd4d5720dcd933c55a6e323b6fa27fa57bff04564d1074defe95f98e9cf
6
+ metadata.gz: dcf687350868122854d483f3f74cc19819d8ca1d997f027ce8cb43d8bbc7eff8afa5ac4b4207f8fe4b5db7b04aa85b09587bd7f0fd2940d8822b520aa0426007
7
+ data.tar.gz: 2147db1b5d9f128e0a3a9c4a53c87ad45280eff43327433a3ec30b282946bcdc03713a43844f20f827def47aa19e7d765ccbfbded55df1ff05340306ade565b9
data/README.md CHANGED
@@ -24,109 +24,10 @@ Check for updates:
24
24
 
25
25
  $ gem update webdrone
26
26
 
27
- ## Usage
28
-
29
- Create a browser:
30
-
31
- ```ruby
32
- require 'webdrone'
33
-
34
- a0 = Webdrone.create timeout: 5
35
- a0.open.url 'http://www.google.com/'
36
- a0.quit
37
-
38
- # or
39
- Webdrone.create timeout: 5 do |a0|
40
- a0.open.url 'http://www.google.com/'
41
- end
42
- ```
43
-
44
- Take a screenshot:
45
-
46
- ```ruby
47
- a0.shot.screen 'login' # saves to screenshot-0001-login.png
48
- a0.shot.screen 'home' # saves to screenshot-0002-home.png
49
- ```
50
-
51
- Working with forms:
52
-
53
- ```ruby
54
-
55
- Webdrone.create do |a0|
56
- a0.open.url 'http://www.google.com/'
57
- a0.form.set 'q', 'A0::WebDrone'
58
- a0.form.submit
59
- end
60
-
61
-
62
- # or
63
- a0.form.with_xpath '//label[contains(.,"%s")]/following-sibling::*/*[self::input | self::textarea | self::select]' do
64
- set 'label', 'value'
65
- xlsx sheet: 'ejemplo'
66
- end
67
- a0.form.submit
68
- ```
69
-
70
- Filling a form from an xlsx spreadsheet:
71
- ```ruby
72
- TODO
73
- ```
74
-
75
-
76
-
77
- Config:
78
-
79
- ```ruby
80
- TODO
81
- ```
82
-
83
- Saving screenshots and downloaded files to a directory:
84
-
85
- ```ruby
86
- a0 = Webdrone.create create_outdir: true
87
- print a0.conf.outdir # <= default is webdrone_output_%date%_%time%
88
-
89
- a0.open.url 'http://www.google.cl/'
90
- a0.form.set 'q', "Download sample file filetype:xls\n"
91
- a0.shot.screen 'homepage' # screenshot is saved in output directory
92
- a0.clic.xpath '//h3' # xls file is saved in output directory
93
-
94
- # or specify directory yourself
95
- a0 = Webdrone.create outdir: '/tmp/evidences'
96
- print a0.conf.outdir # <= "/tmp/evidences"
97
- ```
98
-
99
-
100
-
101
- Creating tabs and switching iframes:
102
-
103
- ```ruby
104
- a0.ctxt.create_tab
105
- a0.open.url 'http:://example.com/'
106
- a0.ctxt.with_frame 'iframe_name' do
107
- a0.find.on 'Some link or button'
108
- end
109
- ```
110
-
111
- Getting text:
112
-
113
- ```ruby
114
- puts a0.text.id 'some_id'
115
- puts a0.text.xpath 'some_xpath'
116
- ```
117
-
118
- Verifying text and HTML attributes
119
-
120
- ```ruby
121
- a0.vrfy.id 'some_id', contains: 'SOME TEXT'
122
- a0.vrfy.xpath 'some_xpath', eq: 'EXACT TEXT'
123
- a0.vrfy.link 'link', attr: 'disabled', eq: 'true'
124
- a0.vrfy.link 'link', attr: 'sample', contains: 'something'
125
- ```
126
-
127
27
  ## Documentation
128
28
 
129
- Docs can be found [here](http://www.rubydoc.info/gems/webdrone).
29
+ * [Documentation Wiki](https://github.com/a0/a0-webdrone-ruby/wiki)
30
+ * Docs can be found [here](http://www.rubydoc.info/gems/webdrone).
130
31
 
131
32
  ## Development
132
33
 
data/lib/webdrone.rb CHANGED
@@ -15,6 +15,7 @@ require 'webdrone/wait'
15
15
  require 'webdrone/text'
16
16
  require 'webdrone/vrfy'
17
17
  require 'webdrone/html'
18
+ require 'os'
18
19
  require 'selenium-webdriver'
19
20
  require 'xpath'
20
21
  require 'rubyXL'
@@ -25,7 +25,7 @@ module Webdrone
25
25
  @@chrome_prefs
26
26
  end
27
27
 
28
- def initialize(browser: 'chrome', create_outdir: true, outdir: nil, timeout:, maximize: true, error: :raise_report, chrome_prefs: nil, firefox_profile: nil)
28
+ def initialize(browser: 'firefox', create_outdir: true, outdir: nil, timeout:, maximize: true, error: :raise_report, chrome_prefs: nil, firefox_profile: nil)
29
29
  if create_outdir or outdir
30
30
  outdir ||= File.join("webdrone_output", Time.new.strftime('%Y%m%d_%H%M%S'))
31
31
  self.conf.outdir = outdir
@@ -37,13 +37,7 @@ module Webdrone
37
37
  @driver = Selenium::WebDriver.for browser.to_sym, prefs: chrome_prefs, args: ['--disable-popup-blocking']
38
38
  elsif outdir != nil and browser.to_sym == :firefox
39
39
  firefox_profile = Browser.firefox_profile if firefox_profile == nil
40
- case RbConfig::CONFIG['host_os'].downcase
41
- when /mingw|mswin/
42
- # Windows
43
- downdir = outdir.gsub("/", "\\")
44
- else
45
- downdir = outdir
46
- end
40
+ downdir = OS.windows? ? outdir.gsub("/", "\\") : outdir
47
41
  firefox_profile['browser.download.dir'] = downdir
48
42
  @driver = Selenium::WebDriver.for browser.to_sym, profile: firefox_profile
49
43
  else
data/lib/webdrone/clic.rb CHANGED
@@ -12,46 +12,25 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(text, n: 1, all: false, visible: true)
16
- @a0.find.id(text, n: n, all: all, visible: visible).click
15
+ def clic(text, n: 1, all: false, visible: true)
16
+ item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
17
+ if item.is_a? Array
18
+ item.each(&:click)
19
+ else
20
+ item.click
21
+ end
17
22
  rescue => exception
18
23
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
19
24
  end
20
25
 
21
- def css(text, n: 1, all: false, visible: true)
22
- @a0.find.css(text, n: n, all: all, visible: visible).click
23
- rescue => exception
24
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
25
- end
26
-
27
- def link(text, n: 1, all: false, visible: true)
28
- @a0.find.link(text, n: n, all: all, visible: visible).click
29
- rescue => exception
30
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
31
- end
32
-
33
- def button(text, n: 1, all: false, visible: true)
34
- @a0.find.button(text, n: n, all: all, visible: visible).click
35
- rescue => exception
36
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
37
- end
26
+ alias_method :id, :clic
27
+ alias_method :css, :clic
28
+ alias_method :link, :clic
29
+ alias_method :button, :clic
30
+ alias_method :on, :clic
31
+ alias_method :option, :clic
32
+ alias_method :xpath, :clic
38
33
 
39
- def on(text, n: 1, all: false, visible: true)
40
- @a0.find.on(text, n: n, all: all, visible: visible).click
41
- rescue => exception
42
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
43
- end
44
-
45
- def option(text, n: 1, all: false, visible: true)
46
- @a0.find.option(text, n: n, all: all, visible: visible).click
47
- rescue => exception
48
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
49
- end
50
-
51
- def xpath(text, n: 1, all: false, visible: true)
52
- @a0.find.xpath(text, n: n, all: all, visible: visible).click
53
- rescue => exception
54
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
55
- end
34
+ protected :clic
56
35
  end
57
36
  end
@@ -47,6 +47,7 @@ module Webdrone
47
47
  def report
48
48
  report_script
49
49
  report_screenshot
50
+ report_os
50
51
  report_exception
51
52
  report_time
52
53
  end
@@ -56,7 +57,8 @@ module Webdrone
56
57
  ini, fin = [@location.lineno - 10 - 1, @location.lineno + 10 - 1]
57
58
  ini = 0 if ini < 0
58
59
 
59
- write_title "#{@location.path} AT LINE #{sprintf '%3d', @location.lineno}"
60
+ write_title "LOCATION OF ERROR"
61
+ write_line "#{@location.path} AT LINE #{sprintf '%3d', @location.lineno}"
60
62
  File.readlines(@location.path)[ini..fin].each_with_index do |line, index|
61
63
  lno = index + ini + 1
62
64
  if lno == @location.lineno
@@ -77,10 +79,12 @@ module Webdrone
77
79
  begin
78
80
  @a0.ctxt.with_conf error: :raise do
79
81
  file = @a0.shot.screen 'a0_webdrone_error_report'
80
- write_line "Screenshot Saved filename: #{file.path}"
82
+ write_line "Screenshot saved succesfully filename:"
83
+ write_line "#{File.expand_path(file.path)}"
81
84
  end
82
85
  rescue => exception
83
- write_line "Error Saving screenhot: #{exception}"
86
+ write_line "Error Saving screenshot, exception:"
87
+ write_line "#{exception}"
84
88
  end
85
89
 
86
90
  dump_error_report
@@ -106,6 +110,15 @@ module Webdrone
106
110
  end
107
111
  end
108
112
 
113
+ def report_os
114
+ write_title "SYSTEM INFO"
115
+
116
+ write_line "A0 WEBDRONE VERSION: #{Webdrone::VERSION}"
117
+ write_line OS.report
118
+
119
+ dump_error_report
120
+ end
121
+
109
122
  def report_time
110
123
  write_title "#{Time.new}"
111
124
 
data/lib/webdrone/form.rb CHANGED
@@ -12,7 +12,7 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def with_xpath(xpath, &block)
15
+ def with_xpath(xpath = nil, &block)
16
16
  @xpath = xpath
17
17
  instance_eval &block
18
18
  rescue => exception
@@ -44,8 +44,8 @@ module Webdrone
44
44
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
45
45
  end
46
46
 
47
- def mark(key, color: 'red')
48
- @a0.mark.flash self.find_item(key), color: color
47
+ def mark(key, color: '#af1616', times: 3, sleep: 0.05)
48
+ @a0.mark.mark_item self.find_item(key), color: color, times: times, sleep: sleep
49
49
  rescue => exception
50
50
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
51
51
  end
@@ -67,8 +67,10 @@ module Webdrone
67
67
 
68
68
  protected
69
69
  def find_item(key)
70
- if @xpath
71
- @lastitem = @a0.driver.find_element :xpath, sprintf(@xpath, key)
70
+ if @xpath.respond_to? :call
71
+ @lastitem = @a0.find.xpath @xpath.call(key).to_s
72
+ elsif @xpath.is_a? String and @xpath.include? '%s'
73
+ @lastitem = @a0.find.xpath sprintf(@xpath, key)
72
74
  else
73
75
  @lastitem = @a0.find.xpath XPath::HTML.field(key).to_s
74
76
  end
data/lib/webdrone/mark.rb CHANGED
@@ -12,69 +12,43 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(text, color: 'red', n: 1, all: false, visible: true)
16
- flash @a0.find.id(text, n: n, all: all, visible: visible), color: color
15
+ def mark(text, n: 1, all: false, visible: true, color: '#af1616', times: 3, sleep: 0.05)
16
+ item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
17
+ mark_item item, color: color, times: times, sleep: sleep
17
18
  rescue => exception
18
19
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
19
20
  end
20
21
 
21
- def css(text, color: 'red', n: 1, all: false, visible: true)
22
- flash @a0.find.css(text, n: n, all: all, visible: visible), color: color
23
- rescue => exception
24
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
25
- end
26
-
27
- def link(text, color: 'red', n: 1, all: false, visible: true)
28
- flash @a0.find.link(text, n: n, all: all, visible: visible), color: color
29
- rescue => exception
30
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
31
- end
32
-
33
- def button(text, color: 'red', n: 1, all: false, visible: true)
34
- flash @a0.find.button(text, n: n, all: all, visible: visible), color: color
35
- rescue => exception
36
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
37
- end
38
-
39
- def on(text, color: 'red', n: 1, all: false, visible: true)
40
- flash @a0.find.on(text, n: n, all: all, visible: visible), color: color
41
- rescue => exception
42
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
43
- end
44
-
45
- def option(text, color: 'red', n: 1, all: false, visible: true)
46
- flash @a0.find.option(text, n: n, all: all, visible: visible), color: color
47
- rescue => exception
48
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
49
- end
50
-
51
- def xpath(text, color: 'red', n: 1, all: false, visible: true)
52
- flash @a0.find.xpath(text, n: n, all: all, visible: visible), color: color
53
- rescue => exception
54
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
55
- end
56
-
57
- def flash(item, color: 'red')
58
- 3.times do
59
- border item, 'white'
60
- sleep 0.05
61
- border item, 'black'
62
- sleep 0.05
63
- border item, color
64
- sleep 0.05
22
+ alias_method :id, :mark
23
+ alias_method :css, :mark
24
+ alias_method :link, :mark
25
+ alias_method :button, :mark
26
+ alias_method :on, :mark
27
+ alias_method :option, :mark
28
+ alias_method :xpath, :mark
29
+
30
+ def mark_item(item, color: '#af1616', times: 3, sleep: 0.05)
31
+ times.times do
32
+ mark_item_border item, 'white'
33
+ sleep sleep
34
+ mark_item_border item, 'black'
35
+ sleep sleep
36
+ mark_item_border item, color
37
+ sleep sleep
65
38
  end
66
39
  item
67
40
  end
68
41
 
69
- protected
70
- def border(item, color)
71
- if item.is_a? Array
72
- item.each do |item|
73
- @a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
74
- end
75
- else
76
- @a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
42
+ def mark_item_border(item, color)
43
+ if item.is_a? Array
44
+ item.each do |item|
45
+ @a0.exec.script("arguments[0].style.outline = '2px solid #{color}'", item)
77
46
  end
47
+ else
48
+ @a0.exec.script("arguments[0].style.outline = '2px solid #{color}'", item)
78
49
  end
50
+ end
51
+
52
+ protected :mark, :mark_item_border
79
53
  end
80
54
  end
data/lib/webdrone/text.rb CHANGED
@@ -12,7 +12,7 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def find_text(text, n: 1, all: false, visible: true)
15
+ def text(text, n: 1, all: false, visible: true)
16
16
  item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
17
17
  if item.is_a? Array
18
18
  item.collect(&:text)
@@ -23,13 +23,13 @@ module Webdrone
23
23
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
24
24
  end
25
25
 
26
- alias_method :id, :find_text
27
- alias_method :css, :find_text
28
- alias_method :link, :find_text
29
- alias_method :button, :find_text
30
- alias_method :on, :find_text
31
- alias_method :option, :find_text
32
- alias_method :xpath, :find_text
26
+ alias_method :id, :text
27
+ alias_method :css, :text
28
+ alias_method :link, :text
29
+ alias_method :button, :text
30
+ alias_method :on, :text
31
+ alias_method :option, :text
32
+ alias_method :xpath, :text
33
33
 
34
34
  def page_title
35
35
  @a0.driver.title
@@ -37,6 +37,6 @@ module Webdrone
37
37
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
38
38
  end
39
39
 
40
- protected :find_text
40
+ protected :text
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Webdrone
2
- VERSION = "0.9.8"
2
+ VERSION = "0.9.9"
3
3
  end
data/lib/webdrone/vrfy.rb CHANGED
@@ -12,49 +12,16 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
16
- vrfy @a0.find.id(text), attr: attr, eq: eq, contains: contains
17
- rescue => exception
18
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
19
- end
20
-
21
- def css(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
22
- vrfy @a0.find.css(text), attr: attr, eq: eq, contains: contains
23
- rescue => exception
24
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
25
- end
26
-
27
- def link(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
28
- vrfy @a0.find.link(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
29
- rescue => exception
30
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
31
- end
32
-
33
- def button(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
34
- vrfy @a0.find.button(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
35
- rescue => exception
36
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
37
- end
38
-
39
- def on(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
40
- vrfy @a0.find.on(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
41
- rescue => exception
42
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
43
- end
44
-
45
- def option(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
46
- vrfy @a0.find.option(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
47
- rescue => exception
48
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
49
- end
50
-
51
- def xpath(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
52
- vrfy @a0.find.xpath(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
53
- rescue => exception
54
- Webdrone.report_error(@a0, exception, Kernel.caller_locations)
15
+ def vrfy(text, n: 1, all: false, visible: true, attr: nil, eq: nil, contains: nil)
16
+ item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
17
+ if item.is_a? Array
18
+ item.each { |x| vrfy_item x, attr: attr, eq: eq, contains: contains }
19
+ else
20
+ vrfy_item item, attr: attr, eq: eq, contains: contains
21
+ end
55
22
  end
56
23
 
57
- def vrfy(item, attr: nil, eq: nil, contains: nil)
24
+ def vrfy_item(item, attr: nil, eq: nil, contains: nil)
58
25
  if attr != nil
59
26
  r = item.attribute(attr) == eq if eq != nil
60
27
  r = item.attribute(attr).include? contains if contains != nil
@@ -73,5 +40,15 @@ module Webdrone
73
40
  end
74
41
  end
75
42
  end
43
+
44
+ alias_method :id, :vrfy
45
+ alias_method :css, :vrfy
46
+ alias_method :link, :vrfy
47
+ alias_method :button, :vrfy
48
+ alias_method :on, :vrfy
49
+ alias_method :option, :vrfy
50
+ alias_method :xpath, :vrfy
51
+
52
+ protected :vrfy, :vrfy_item
76
53
  end
77
54
  end
data/webdrone.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rspec"
33
33
  spec.add_development_dependency "ci_reporter_rspec"
34
34
  spec.add_development_dependency "parallel_tests"
35
+ spec.add_runtime_dependency "os"
35
36
  spec.add_runtime_dependency "selenium-webdriver"
36
37
  spec.add_runtime_dependency "xpath"
37
38
  spec.add_runtime_dependency "rubyXL"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldrin Martoq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: os
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: selenium-webdriver
85
99
  requirement: !ruby/object:Gem::Requirement