webdrone 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +52 -23
- data/lib/webdrone.rb +2 -1
- data/lib/webdrone/browser.rb +18 -2
- data/lib/webdrone/clic.rb +6 -2
- data/lib/webdrone/conf.rb +7 -1
- data/lib/webdrone/ctxt.rb +1 -1
- data/lib/webdrone/find.rb +6 -2
- data/lib/webdrone/mark.rb +10 -6
- data/lib/webdrone/shot.rb +1 -0
- data/lib/webdrone/text.rb +6 -2
- data/lib/webdrone/version.rb +1 -1
- data/lib/webdrone/vrfy.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb888344d4b82d0c3747d3812b275d13313accc0
|
4
|
+
data.tar.gz: 1b373f581493ed391fc44e82fa1040909ac037cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 545229f0fa9da4eff8a7e477810e37bb10112a1684cccde6c210e861ea9e1d0ec43c31eecbf17d7e886ec7094ed0ea0ba0890b6d60cf6c0d104082623b4e88d1
|
7
|
+
data.tar.gz: 384975fb4517f9a7bf2923798e94db24c0a3686d92d77cfa0110777ddfe89b05f8e481adc2556ba713a6199809791006c316005d30781f43392d5111db3db5f7
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Yet another selenium webdriver wrapper, ruby version.
|
4
4
|
|
5
|
+
There is a groovy version available, at https://github.com/a0/a0-webdrone-groovy.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -26,53 +28,69 @@ Create a browser:
|
|
26
28
|
require 'webdrone'
|
27
29
|
|
28
30
|
a0 = Webdrone.create
|
29
|
-
a0.open.url
|
31
|
+
a0.open.url 'http://www.google.com/'
|
30
32
|
a0.quit
|
31
33
|
|
32
34
|
# or
|
33
35
|
Webdrone.create do |a0|
|
34
|
-
a0.open.url
|
36
|
+
a0.open.url 'http://www.google.com/'
|
35
37
|
end
|
36
38
|
```
|
37
39
|
|
38
40
|
Take a screenshot:
|
39
41
|
|
40
42
|
```ruby
|
41
|
-
|
42
|
-
|
43
|
-
Webdrone.create do |a0|
|
44
|
-
a0.open.url 'http://www.google.com/'
|
45
|
-
a0.shot.name 'start page'
|
46
|
-
end
|
43
|
+
a0.shot.name 'login' # saves to screenshot-0001-login.png
|
44
|
+
a0.shot.name 'home' # saves to screenshot-0002-home.png
|
47
45
|
```
|
48
46
|
|
49
|
-
|
47
|
+
Working with forms:
|
50
48
|
|
51
49
|
```ruby
|
52
|
-
|
53
|
-
|
54
|
-
Webdrone.create do |a0|
|
55
|
-
a0.open.url 'http://www.google.com/'
|
56
|
-
a0.form.set 'q', 'A0::WebDrone'
|
57
|
-
a0.form.submit
|
50
|
+
a0.form.set 'q', 'A0::WebDrone'
|
51
|
+
a0.form.submit
|
58
52
|
end
|
59
53
|
|
60
54
|
# or
|
61
|
-
a0.open.url 'http://www.google.com/'
|
62
55
|
a0.form.with_xpath '//label[contains(.,"%s")]/following-sibling::*/*[self::input | self::textarea | self::select]' do
|
63
|
-
set
|
64
|
-
xlsx
|
56
|
+
set 'label', 'value'
|
57
|
+
xlsx sheet: 'ejemplo'
|
65
58
|
end
|
66
59
|
a0.form.submit
|
67
60
|
```
|
68
61
|
|
62
|
+
Filling a form from an xlsx spreadsheet:
|
63
|
+
```ruby
|
64
|
+
a0.conf.timeout 10
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
69
|
Config:
|
70
70
|
|
71
71
|
```ruby
|
72
72
|
a0.conf.timeout 10
|
73
73
|
```
|
74
74
|
|
75
|
-
|
75
|
+
Saving screenshots and downloaded files to a directory:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
a0 = Webdrone.create create_outdir: true
|
79
|
+
print a0.conf.outdir # <= default is webdrone_output_%date%_%time%
|
80
|
+
|
81
|
+
a0.open.url 'http://www.google.cl/'
|
82
|
+
a0.form.set 'q', "Download sample file filetype:xls\n"
|
83
|
+
a0.shot.screen 'homepage' # screenshot is saved in output directory
|
84
|
+
a0.clic.xpath '//h3' # xls file is saved in output directory
|
85
|
+
|
86
|
+
# or specify directory yourself
|
87
|
+
a0 = Webdrone.create outdir: '/tmp/evidences'
|
88
|
+
print a0.conf.outdir # <= "/tmp/evidences"
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
Creating tabs and switching iframes:
|
76
94
|
|
77
95
|
```ruby
|
78
96
|
a0.ctxt.create_tab
|
@@ -80,11 +98,22 @@ a0.open.url 'http:://example.com/'
|
|
80
98
|
a0.ctxt.with_frame 'iframe_name' do
|
81
99
|
a0.find.on 'Some link or button'
|
82
100
|
end
|
83
|
-
|
101
|
+
```
|
102
|
+
|
103
|
+
Getting text:
|
84
104
|
|
85
|
-
|
86
|
-
a0.
|
105
|
+
```ruby
|
106
|
+
puts a0.text.id 'some_id'
|
107
|
+
puts a0.text.xpath 'some_xpath'
|
108
|
+
```
|
109
|
+
|
110
|
+
Verifying text and HTML attributes
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
a0.vrfy.id 'some_id', contains: 'SOME TEXT'
|
114
|
+
a0.vrfy.xpath 'some_xpath', eq: 'EXACT TEXT'
|
87
115
|
a0.vrfy.link 'link', attr: 'disabled', eq: 'true'
|
116
|
+
a0.vrfy.link 'link', attr: 'sample', contains: 'something'
|
88
117
|
```
|
89
118
|
|
90
119
|
|
@@ -97,7 +126,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
97
126
|
|
98
127
|
## Contributing
|
99
128
|
|
100
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/a0/webdrone-ruby.
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/a0/a0-webdrone-ruby.
|
101
130
|
|
102
131
|
|
103
132
|
## License
|
data/lib/webdrone.rb
CHANGED
@@ -17,6 +17,7 @@ require 'selenium-webdriver'
|
|
17
17
|
require 'xpath'
|
18
18
|
require 'rubyXL'
|
19
19
|
require 'irb'
|
20
|
+
require 'fileutils'
|
20
21
|
|
21
22
|
module Webdrone
|
22
23
|
def self.create(*args)
|
@@ -26,7 +27,7 @@ module Webdrone
|
|
26
27
|
yield a0
|
27
28
|
ensure
|
28
29
|
a0.quit
|
29
|
-
end
|
30
|
+
end
|
30
31
|
else
|
31
32
|
a0
|
32
33
|
end
|
data/lib/webdrone/browser.rb
CHANGED
@@ -2,8 +2,24 @@ module Webdrone
|
|
2
2
|
class Browser
|
3
3
|
attr_accessor :driver
|
4
4
|
|
5
|
-
def initialize(browser: 'chrome')
|
6
|
-
|
5
|
+
def initialize(browser: 'chrome', create_outdir: false, outdir: nil)
|
6
|
+
if create_outdir or outdir
|
7
|
+
outdir ||= "webdrone_output_#{Time.new.strftime('%Y%m%d_%H%M')}"
|
8
|
+
self.conf.outdir = outdir
|
9
|
+
end
|
10
|
+
if outdir != nil and browser.to_sym == :chrome
|
11
|
+
prefs = { download: { prompt_for_download: false, default_directory: outdir } }
|
12
|
+
@driver = Selenium::WebDriver.for browser.to_sym, prefs: prefs
|
13
|
+
elsif outdir != nil and browser.to_sym == :firefox
|
14
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
15
|
+
profile['browser.download.dir'] = outdir
|
16
|
+
profile['browser.download.folderList'] = 2
|
17
|
+
profile['browser.download.manager.showWhenStarting'] = false
|
18
|
+
profile['browser.helperApps.neverAsk.saveToDisk'] = "images/jpeg, application/pdf, application/octet-stream"
|
19
|
+
@driver = Selenium::WebDriver.for browser.to_sym, profile: profile
|
20
|
+
else
|
21
|
+
@driver = Selenium::WebDriver.for browser.to_sym
|
22
|
+
end
|
7
23
|
end
|
8
24
|
|
9
25
|
def quit
|
data/lib/webdrone/clic.rb
CHANGED
@@ -12,8 +12,8 @@ module Webdrone
|
|
12
12
|
@a0 = a0
|
13
13
|
end
|
14
14
|
|
15
|
-
def id(
|
16
|
-
@a0.find.id(
|
15
|
+
def id(text)
|
16
|
+
@a0.find.id(text).click
|
17
17
|
end
|
18
18
|
|
19
19
|
def link(text, n: 1, all: false, visible: true)
|
@@ -28,6 +28,10 @@ module Webdrone
|
|
28
28
|
@a0.find.on(text, n: n, all: all, visible: visible).click
|
29
29
|
end
|
30
30
|
|
31
|
+
def option(text, n: 1, all: false, visible: true)
|
32
|
+
@a0.find.option(text, n: n, all: all, visible: visible).click
|
33
|
+
end
|
34
|
+
|
31
35
|
def xpath(text, n: 1, all: false, visible: true)
|
32
36
|
@a0.find.xpath(text, n: n, all: all, visible: visible).click
|
33
37
|
end
|
data/lib/webdrone/conf.rb
CHANGED
@@ -6,15 +6,21 @@ module Webdrone
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class Conf
|
9
|
-
attr_accessor :a0, :timeout
|
9
|
+
attr_accessor :a0, :timeout, :outdir
|
10
10
|
|
11
11
|
def initialize(a0)
|
12
12
|
@a0 = a0
|
13
|
+
@outdir = "."
|
13
14
|
end
|
14
15
|
|
15
16
|
def timeout=(val)
|
16
17
|
@timeout = val
|
17
18
|
@a0.driver.manage.timeouts.implicit_wait = val
|
18
19
|
end
|
20
|
+
|
21
|
+
def outdir=(val)
|
22
|
+
@outdir = val
|
23
|
+
FileUtils.mkdir_p val
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
data/lib/webdrone/ctxt.rb
CHANGED
data/lib/webdrone/find.rb
CHANGED
@@ -12,9 +12,9 @@ module Webdrone
|
|
12
12
|
@a0 = a0
|
13
13
|
end
|
14
14
|
|
15
|
-
def id(
|
15
|
+
def id(text)
|
16
16
|
@a0.wait.for do
|
17
|
-
@a0.driver.find_element :id,
|
17
|
+
@a0.driver.find_element :id, text
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -30,6 +30,10 @@ module Webdrone
|
|
30
30
|
self.xpath XPath::HTML.link_or_button(text).to_s, n: n, all: all, visible: visible
|
31
31
|
end
|
32
32
|
|
33
|
+
def option(text, n: 1, all: false, visible: true)
|
34
|
+
self.xpath XPath::HTML.option(text).to_s, n: n, all: all, visible: visible
|
35
|
+
end
|
36
|
+
|
33
37
|
def xpath(text, n: 1, all: false, visible: true)
|
34
38
|
@a0.wait.for do
|
35
39
|
items = @a0.driver.find_elements :xpath, text
|
data/lib/webdrone/mark.rb
CHANGED
@@ -12,8 +12,8 @@ module Webdrone
|
|
12
12
|
@a0 = a0
|
13
13
|
end
|
14
14
|
|
15
|
-
def id(
|
16
|
-
flash @a0.find.id(
|
15
|
+
def id(text, color: 'red')
|
16
|
+
flash @a0.find.id(text), color: color
|
17
17
|
end
|
18
18
|
|
19
19
|
def link(text, color: 'red', n: 1, all: false, visible: true)
|
@@ -28,24 +28,28 @@ module Webdrone
|
|
28
28
|
flash @a0.find.on(text, n: n, all: all, visible: visible), color: color
|
29
29
|
end
|
30
30
|
|
31
|
+
def option(text, color: 'red', n: 1, all: false, visible: true)
|
32
|
+
flash @a0.find.option(text, n: n, all: all, visible: visible), color: color
|
33
|
+
end
|
34
|
+
|
31
35
|
def xpath(text, color: 'red', n: 1, all: false, visible: true)
|
32
36
|
flash @a0.find.xpath(text, n: n, all: all, visible: visible), color: color
|
33
37
|
end
|
34
38
|
|
35
39
|
def flash(item, color: 'red')
|
36
40
|
3.times do
|
37
|
-
border 'white'
|
41
|
+
border item, 'white'
|
38
42
|
sleep 0.1
|
39
|
-
border 'blue'
|
43
|
+
border item, 'blue'
|
40
44
|
sleep 0.1
|
41
|
-
border
|
45
|
+
border item, color
|
42
46
|
sleep 0.1
|
43
47
|
end
|
44
48
|
item
|
45
49
|
end
|
46
50
|
|
47
51
|
protected
|
48
|
-
def border(
|
52
|
+
def border(item, color)
|
49
53
|
if item.is_a? Array
|
50
54
|
item.each do |item|
|
51
55
|
@a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
|
data/lib/webdrone/shot.rb
CHANGED
data/lib/webdrone/text.rb
CHANGED
@@ -12,8 +12,8 @@ module Webdrone
|
|
12
12
|
@a0 = a0
|
13
13
|
end
|
14
14
|
|
15
|
-
def id(
|
16
|
-
@a0.find.id(
|
15
|
+
def id(text)
|
16
|
+
@a0.find.id(text).text
|
17
17
|
end
|
18
18
|
|
19
19
|
def link(text, n: 1, all: false, visible: true)
|
@@ -28,6 +28,10 @@ module Webdrone
|
|
28
28
|
@a0.find.on(text, n: n, all: all, visible: visible).text
|
29
29
|
end
|
30
30
|
|
31
|
+
def option(text, n: 1, all: false, visible: true)
|
32
|
+
@a0.find.option(text, n: n, all: all, visible: visible).text
|
33
|
+
end
|
34
|
+
|
31
35
|
def xpath(text, n: 1, all: false, visible: true)
|
32
36
|
@a0.find.xpath(text, n: n, all: all, visible: visible).text
|
33
37
|
end
|
data/lib/webdrone/version.rb
CHANGED
data/lib/webdrone/vrfy.rb
CHANGED
@@ -12,8 +12,8 @@ module Webdrone
|
|
12
12
|
@a0 = a0
|
13
13
|
end
|
14
14
|
|
15
|
-
def id(
|
16
|
-
vrfy @a0.find.id(
|
15
|
+
def id(text, attr: nil, eq: nil, contains: nil)
|
16
|
+
vrfy @a0.find.id(text), attr: attr, eq: eq, contains: contains
|
17
17
|
end
|
18
18
|
|
19
19
|
def link(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
@@ -28,6 +28,10 @@ module Webdrone
|
|
28
28
|
vrfy @a0.find.on(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
29
29
|
end
|
30
30
|
|
31
|
+
def option(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
32
|
+
vrfy @a0.find.option(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
33
|
+
end
|
34
|
+
|
31
35
|
def xpath(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
32
36
|
vrfy @a0.find.xpath(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
33
37
|
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aldrin Martoq
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|