webdrone 0.2.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/webdrone.rb +33 -0
- data/lib/webdrone/browser.rb +13 -0
- data/lib/webdrone/clic.rb +35 -0
- data/lib/webdrone/conf.rb +20 -0
- data/lib/webdrone/ctxt.rb +47 -0
- data/lib/webdrone/exec.rb +19 -0
- data/lib/webdrone/find.rb +60 -0
- data/lib/webdrone/form.rb +64 -0
- data/lib/webdrone/mark.rb +58 -0
- data/lib/webdrone/open.rb +19 -0
- data/lib/webdrone/shot.rb +21 -0
- data/lib/webdrone/text.rb +35 -0
- data/lib/webdrone/version.rb +3 -0
- data/lib/webdrone/vrfy.rb +55 -0
- data/lib/webdrone/wait.rb +34 -0
- data/lib/webdrone/xlsx.rb +96 -0
- data/webdrone.gemspec +38 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df9d3629c40609b830bcbd9e51e1d7e502ae12b8
|
4
|
+
data.tar.gz: 695a557b4eed850890db5a14503a091f01564616
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e4a189ae8e8326bf64a0f64dfaf863a1d9145edfdb6f62d7636219d0fcbbe2f77f0c5ab707148bffbd26590b19ac0da1f523f129752cf3ba276e0a402519479
|
7
|
+
data.tar.gz: 1aada967df3d9590b2502ef408960efe7cd07335aa4614e229306c23a4f94e5419a89a01d8c84eb4edb9543c7eae1a8865540905a9c10c21c7108f83c9ffde19
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
webdrone
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Aldrin Martoq
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Webdrone
|
2
|
+
|
3
|
+
Yet another selenium webdriver wrapper, ruby version.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'webdrone'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Install it yourself as:
|
18
|
+
|
19
|
+
$ gem install webdrone
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create a browser:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'webdrone'
|
27
|
+
|
28
|
+
a0 = Webdrone.new
|
29
|
+
a0.open.url 'http://www.google.com/'
|
30
|
+
a0.quit
|
31
|
+
|
32
|
+
# or
|
33
|
+
Webdrone.new do |a0|
|
34
|
+
a0.open.url 'http://www.google.com/'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Take a screenshot:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'webdrone'
|
42
|
+
|
43
|
+
Webdrone.new do |a0|
|
44
|
+
a0.open.url 'http://www.google.com/'
|
45
|
+
a0.shot.name 'start page'
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Filling a form:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'webdrone'
|
53
|
+
|
54
|
+
Webdrone.new do |a0|
|
55
|
+
a0.open.url 'http://www.google.com/'
|
56
|
+
a0.form.set 'q', 'A0::WebDrone'
|
57
|
+
a0.form.submit
|
58
|
+
end
|
59
|
+
|
60
|
+
# or
|
61
|
+
a0.open.url 'http://www.google.com/'
|
62
|
+
a0.form.with_xpath '//label[contains(.,"%s")]/following-sibling::*/*[self::input | self::textarea | self::select]' do
|
63
|
+
set 'label', 'value'
|
64
|
+
xlsx sheet: 'ejemplo'
|
65
|
+
end
|
66
|
+
a0.form.submit
|
67
|
+
```
|
68
|
+
|
69
|
+
Config:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
a0.conf.timeout 10
|
73
|
+
```
|
74
|
+
|
75
|
+
Context, text and verification:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
a0.ctxt.create_tab
|
79
|
+
a0.open.url 'http:://example.com/'
|
80
|
+
a0.ctxt.with_frame 'iframe_name' do
|
81
|
+
a0.find.on 'Some link or button'
|
82
|
+
end
|
83
|
+
puts a0.text.id('something')
|
84
|
+
|
85
|
+
a0.vrfy.id 'another', contains: 'SOME TEXT'
|
86
|
+
a0.vrfy.id 'another', eq: 'EXACT TEXT'
|
87
|
+
a0.vrfy.link 'link', attr: 'disabled', eq: 'true'
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
## Development
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
95
|
+
|
96
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/a0/webdrone-ruby.
|
101
|
+
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
106
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "webdrone"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/webdrone.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'webdrone/version'
|
2
|
+
require 'webdrone/browser'
|
3
|
+
require 'webdrone/open'
|
4
|
+
require 'webdrone/shot'
|
5
|
+
require 'webdrone/find'
|
6
|
+
require 'webdrone/clic'
|
7
|
+
require 'webdrone/exec'
|
8
|
+
require 'webdrone/mark'
|
9
|
+
require 'webdrone/form'
|
10
|
+
require 'webdrone/xlsx'
|
11
|
+
require 'webdrone/conf'
|
12
|
+
require 'webdrone/ctxt'
|
13
|
+
require 'webdrone/wait'
|
14
|
+
require 'webdrone/text'
|
15
|
+
require 'webdrone/vrfy'
|
16
|
+
require 'selenium-webdriver'
|
17
|
+
require 'xpath'
|
18
|
+
require 'rubyXL'
|
19
|
+
|
20
|
+
module Webdrone
|
21
|
+
def self.new(*args)
|
22
|
+
a0 = Webdrone::Browser.new *args
|
23
|
+
if block_given?
|
24
|
+
begin
|
25
|
+
yield a0
|
26
|
+
ensure
|
27
|
+
a0.quit
|
28
|
+
end
|
29
|
+
else
|
30
|
+
a0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def clic
|
4
|
+
@clic ||= Clic.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Clic
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(id)
|
16
|
+
@a0.find.id(id).click
|
17
|
+
end
|
18
|
+
|
19
|
+
def link(text, n: 1, all: false, visible: true)
|
20
|
+
@a0.find.link(text, n: n, all: all, visible: visible).click
|
21
|
+
end
|
22
|
+
|
23
|
+
def button(text, n: 1, all: false, visible: true)
|
24
|
+
@a0.find.button(text, n: n, all: all, visible: visible).click
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(text, n: 1, all: false, visible: true)
|
28
|
+
@a0.find.on(text, n: n, all: all, visible: visible).click
|
29
|
+
end
|
30
|
+
|
31
|
+
def xpath(text, n: 1, all: false, visible: true)
|
32
|
+
@a0.find.xpath(text, n: n, all: all, visible: visible).click
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def conf
|
4
|
+
@conf ||= Conf.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Conf
|
9
|
+
attr_accessor :a0, :timeout
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def timeout=(val)
|
16
|
+
@timeout = val
|
17
|
+
@a0.driver.manage.timeouts.implicit_wait = val
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def ctxt
|
4
|
+
@ctxt ||= Ctxt.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Ctxt
|
9
|
+
attr_accessor :a0, :current_frame
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_tab
|
16
|
+
@a0.exec.script "function a0_ctx_create_tab() { var w = window.open(); w.document.open(); w.document.write('A0 CTXT CREATE TAB'); w.document.close(); } a0_ctx_create_tab();"
|
17
|
+
@a0.driver.switch_to.window @a0.driver.window_handles.last
|
18
|
+
end
|
19
|
+
|
20
|
+
def close_tab
|
21
|
+
@a0.driver.close
|
22
|
+
@a0.driver.switch_to.window @a0.driver.window_handles.last
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_frame(name)
|
26
|
+
old_frame = @current_frame
|
27
|
+
@a0.driver.switch_to.frame name
|
28
|
+
@current_frame = name
|
29
|
+
if block_given?
|
30
|
+
yield
|
31
|
+
@a0.driver.switch_to.parent_frame
|
32
|
+
@current_frame = old_frame
|
33
|
+
end
|
34
|
+
@current_frame
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_alert
|
38
|
+
@a0.wait.for do
|
39
|
+
yield @a0.driver.switch_to.alert
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ignore_alert
|
44
|
+
@a0.exec.script 'alert = function(message){return true;};'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def exec
|
4
|
+
@exec ||= Exec.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Exec
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def script(script, *more)
|
16
|
+
@a0.driver.execute_script(script, *more)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def find
|
4
|
+
@find ||= Find.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Find
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(id)
|
16
|
+
@a0.wait.for do
|
17
|
+
@a0.driver.find_element :id, id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def link(text, n: 1, all: false, visible: true)
|
22
|
+
self.xpath XPath::HTML.link(text).to_s, n: n, all: all, visible: visible
|
23
|
+
end
|
24
|
+
|
25
|
+
def button(text, n: 1, all: false, visible: true)
|
26
|
+
self.xpath XPath::HTML.button(text).to_s, n: n, all: all, visible: visible
|
27
|
+
end
|
28
|
+
|
29
|
+
def on(text, n: 1, all: false, visible: true)
|
30
|
+
self.xpath XPath::HTML.link_or_button(text).to_s, n: n, all: all, visible: visible
|
31
|
+
end
|
32
|
+
|
33
|
+
def xpath(text, n: 1, all: false, visible: true)
|
34
|
+
@a0.wait.for do
|
35
|
+
items = @a0.driver.find_elements :xpath, text
|
36
|
+
choose(items, n, all, visible)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def choose(list, n, all, visible)
|
42
|
+
list = list.select do |x|
|
43
|
+
if visible == true
|
44
|
+
x.displayed?
|
45
|
+
elsif visible == false
|
46
|
+
not x.displayed?
|
47
|
+
else
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if all
|
52
|
+
list
|
53
|
+
elsif n == 1
|
54
|
+
list.first
|
55
|
+
else
|
56
|
+
list[n - 1]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def form
|
4
|
+
@form ||= Form.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Form
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_xpath(xpath, &block)
|
16
|
+
@xpath = xpath
|
17
|
+
instance_eval &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(key, val)
|
21
|
+
item = self.find_item(key)
|
22
|
+
if item.tag_name == 'select'
|
23
|
+
option = item.find_element :xpath, XPath::HTML.option(val).to_s
|
24
|
+
item.click
|
25
|
+
option.click
|
26
|
+
else
|
27
|
+
item.clear
|
28
|
+
item.send_keys(val)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get(key)
|
33
|
+
self.find_item(key)[:value]
|
34
|
+
end
|
35
|
+
|
36
|
+
def clic(key)
|
37
|
+
self.find_item(key).click
|
38
|
+
end
|
39
|
+
|
40
|
+
def mark(key, color: 'red')
|
41
|
+
@a0.mark.flash self.find_item(key), color: color
|
42
|
+
end
|
43
|
+
|
44
|
+
def submit(key = nil)
|
45
|
+
self.find_item(key) if key
|
46
|
+
@lastitem.submit
|
47
|
+
end
|
48
|
+
|
49
|
+
def xlsx(sheet: nil, filename: nil)
|
50
|
+
@a0.xlsx.dict(sheet: sheet, filename: filename).each do |k, v|
|
51
|
+
self.set k, v
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
def find_item(key)
|
57
|
+
if @xpath
|
58
|
+
@lastitem = @a0.driver.find_element :xpath, sprintf(@xpath, key)
|
59
|
+
else
|
60
|
+
@lastitem = @a0.find.xpath XPath::HTML.field(key).to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def mark
|
4
|
+
@mark ||= Mark.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Mark
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(id, color: 'red')
|
16
|
+
flash @a0.find.id(id), color: color
|
17
|
+
end
|
18
|
+
|
19
|
+
def link(text, color: 'red', n: 1, all: false, visible: true)
|
20
|
+
flash @a0.find.link(text, n: n, all: all, visible: visible), color: color
|
21
|
+
end
|
22
|
+
|
23
|
+
def button(text, color: 'red', n: 1, all: false, visible: true)
|
24
|
+
flash @a0.find.button(text, n: n, all: all, visible: visible), color: color
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(text, color: 'red', n: 1, all: false, visible: true)
|
28
|
+
flash @a0.find.on(text, n: n, all: all, visible: visible), color: color
|
29
|
+
end
|
30
|
+
|
31
|
+
def xpath(text, color: 'red', n: 1, all: false, visible: true)
|
32
|
+
flash @a0.find.xpath(text, n: n, all: all, visible: visible), color: color
|
33
|
+
end
|
34
|
+
|
35
|
+
def flash(item, color: 'red')
|
36
|
+
3.times do
|
37
|
+
border 'white', item
|
38
|
+
sleep 0.1
|
39
|
+
border 'blue', item
|
40
|
+
sleep 0.1
|
41
|
+
border color, item
|
42
|
+
sleep 0.1
|
43
|
+
end
|
44
|
+
item
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def border(color, item)
|
49
|
+
if item.is_a? Array
|
50
|
+
item.each do |item|
|
51
|
+
@a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
@a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def shot
|
4
|
+
@shot ||= Shot.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Shot
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def screen(name)
|
16
|
+
@counter = (@counter || 0) + 1
|
17
|
+
filename = sprintf "screenshot-%04d-%s.png", @counter, name
|
18
|
+
@a0.driver.save_screenshot filename
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def text
|
4
|
+
@text ||= Text.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Text
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(id)
|
16
|
+
@a0.find.id(id).text
|
17
|
+
end
|
18
|
+
|
19
|
+
def link(text, n: 1, all: false, visible: true)
|
20
|
+
@a0.find.link(text, n: n, all: all, visible: visible).text
|
21
|
+
end
|
22
|
+
|
23
|
+
def button(text, n: 1, all: false, visible: true)
|
24
|
+
@a0.find.button(text, n: n, all: all, visible: visible).text
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(text, n: 1, all: false, visible: true)
|
28
|
+
@a0.find.on(text, n: n, all: all, visible: visible).text
|
29
|
+
end
|
30
|
+
|
31
|
+
def xpath(text, n: 1, all: false, visible: true)
|
32
|
+
@a0.find.xpath(text, n: n, all: all, visible: visible).text
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def vrfy
|
4
|
+
@vrfy ||= Vrfy.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Vrfy
|
9
|
+
attr_accessor :a0
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(id, attr: nil, eq: nil, contains: nil)
|
16
|
+
vrfy @a0.find.id(id), attr: attr, eq: eq, contains: contains
|
17
|
+
end
|
18
|
+
|
19
|
+
def link(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
20
|
+
vrfy @a0.find.link(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
21
|
+
end
|
22
|
+
|
23
|
+
def button(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
24
|
+
vrfy @a0.find.button(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
25
|
+
end
|
26
|
+
|
27
|
+
def on(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
28
|
+
vrfy @a0.find.on(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
29
|
+
end
|
30
|
+
|
31
|
+
def xpath(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
|
32
|
+
vrfy @a0.find.xpath(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
|
33
|
+
end
|
34
|
+
|
35
|
+
def vrfy(item, attr: nil, eq: nil, contains: nil)
|
36
|
+
if attr != nil
|
37
|
+
r = item.attribute(attr) == eq if eq != nil
|
38
|
+
r = item.attribute(attr).include? contains if contains != nil
|
39
|
+
elsif eq != nil
|
40
|
+
r = item.text == eq
|
41
|
+
elsif contains != nil
|
42
|
+
r = item.text.include? contains
|
43
|
+
end
|
44
|
+
if r == false
|
45
|
+
targ = "eq: [#{eq}]" if eq
|
46
|
+
targ = "contains: [#{contains}]" if contains
|
47
|
+
if attr != nil
|
48
|
+
raise Exception.new "ERROR: Attribute [#{attr}] value [#{item.attribute(attr)}] does not comply #{targ}"
|
49
|
+
else
|
50
|
+
raise Exception.new "ERROR: Value [#{item.text}] does not comply #{targ}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def wait
|
4
|
+
@wait ||= Wait.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Wait
|
9
|
+
attr_accessor :a0, :ignore
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
@ignore = []
|
14
|
+
@ignore << Selenium::WebDriver::Error::StaleElementReferenceError
|
15
|
+
@ignore << Selenium::WebDriver::Error::NoSuchElementError
|
16
|
+
@ignore << Selenium::WebDriver::Error::NoSuchFrameError
|
17
|
+
@ignore << Selenium::WebDriver::Error::InvalidSelectorError
|
18
|
+
end
|
19
|
+
|
20
|
+
def for
|
21
|
+
if @a0.conf.timeout
|
22
|
+
Selenium::WebDriver::Wait.new(timeout: @a0.conf.timeout, ignore: @ignore).until do
|
23
|
+
yield
|
24
|
+
end
|
25
|
+
else
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def time(val)
|
31
|
+
sleep val
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Webdrone
|
2
|
+
class Browser
|
3
|
+
def xlsx
|
4
|
+
@xlsx ||= Xlsx.new self
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Xlsx
|
9
|
+
attr_accessor :a0, :filename, :sheet, :dict, :rows
|
10
|
+
|
11
|
+
def initialize(a0)
|
12
|
+
@a0 = a0
|
13
|
+
@filename = 'data.xlsx'
|
14
|
+
@sheet = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def dict(sheet: nil, filename: nil)
|
18
|
+
update_sheet_filename(sheet, filename)
|
19
|
+
if @dict == nil
|
20
|
+
@dict = {}
|
21
|
+
workbook = RubyXL::Parser.parse(@filename)
|
22
|
+
worksheet = workbook[@sheet]
|
23
|
+
worksheet.sheet_data.rows.tap do |head, *body|
|
24
|
+
body.each do |row|
|
25
|
+
k, v = row[0].value, row[1].value
|
26
|
+
@dict[k] = v
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@dict
|
31
|
+
end
|
32
|
+
|
33
|
+
def rows(sheet: nil, filename: nil, dict: false)
|
34
|
+
update_sheet_filename(sheet, filename)
|
35
|
+
if @rows == nil
|
36
|
+
workbook = RubyXL::Parser.parse(@filename)
|
37
|
+
worksheet = workbook[@sheet]
|
38
|
+
@rows = worksheet.sheet_data.rows.collect do |row|
|
39
|
+
row.cells.collect do |cell|
|
40
|
+
cell.value if cell != nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
if dict
|
45
|
+
head = @rows.shift
|
46
|
+
@rows = @rows.collect do |row|
|
47
|
+
dict = {}
|
48
|
+
row.each_with_index do |val, i|
|
49
|
+
dict[head[i]] = val if head[i] != nil
|
50
|
+
end
|
51
|
+
dict
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@rows
|
55
|
+
end
|
56
|
+
|
57
|
+
def save(sheet: nil, filename: nil, dict: nil, rows: nil)
|
58
|
+
@filename = filename if filename
|
59
|
+
@sheet = sheet if sheet
|
60
|
+
workbook = RubyXL::Parser.parse(@filename)
|
61
|
+
worksheet = workbook[@sheet]
|
62
|
+
if dict != nil
|
63
|
+
worksheet.sheet_data.rows.tap do |head, *body|
|
64
|
+
body.each do |row|
|
65
|
+
k = row[0].value
|
66
|
+
row[1].change_contents(dict[k]) if dict.include?(k)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
elsif rows != nil
|
70
|
+
rows.each_with_index do |row, rowi|
|
71
|
+
row.each_with_index do |data, coli|
|
72
|
+
if worksheet[rowi] == nil || worksheet[rowi][coli] == nil
|
73
|
+
worksheet.add_cell(rowi, coli, data)
|
74
|
+
else
|
75
|
+
worksheet[rowi][coli].change_contents(data)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
workbook.write(filename)
|
81
|
+
@dict = @rows = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
def update_sheet_filename(sheet, filename)
|
86
|
+
if sheet and sheet != @sheet
|
87
|
+
@sheet = sheet
|
88
|
+
@dict = @rows = nil
|
89
|
+
end
|
90
|
+
if filename and filename != @filename
|
91
|
+
@filename = filename
|
92
|
+
@dict = @rows = nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/webdrone.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'webdrone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "webdrone"
|
8
|
+
spec.version = Webdrone::VERSION
|
9
|
+
spec.authors = ["Aldrin Martoq"]
|
10
|
+
spec.email = ["a@a0.cl"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple selenium webdriver wrapper, ruby version.}
|
13
|
+
spec.description = %q{See webpage for more info.}
|
14
|
+
spec.homepage = "http://github.com/a0/a0-webdrone-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "ci_reporter_rspec"
|
34
|
+
spec.add_development_dependency "parallel_tests"
|
35
|
+
spec.add_runtime_dependency "selenium-webdriver"
|
36
|
+
spec.add_runtime_dependency "xpath"
|
37
|
+
spec.add_runtime_dependency "rubyXL"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webdrone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aldrin Martoq
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ci_reporter_rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: parallel_tests
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: selenium-webdriver
|
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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: xpath
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubyXL
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: See webpage for more info.
|
126
|
+
email:
|
127
|
+
- a@a0.cl
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".ruby-gemset"
|
135
|
+
- ".ruby-version"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- lib/webdrone.rb
|
144
|
+
- lib/webdrone/browser.rb
|
145
|
+
- lib/webdrone/clic.rb
|
146
|
+
- lib/webdrone/conf.rb
|
147
|
+
- lib/webdrone/ctxt.rb
|
148
|
+
- lib/webdrone/exec.rb
|
149
|
+
- lib/webdrone/find.rb
|
150
|
+
- lib/webdrone/form.rb
|
151
|
+
- lib/webdrone/mark.rb
|
152
|
+
- lib/webdrone/open.rb
|
153
|
+
- lib/webdrone/shot.rb
|
154
|
+
- lib/webdrone/text.rb
|
155
|
+
- lib/webdrone/version.rb
|
156
|
+
- lib/webdrone/vrfy.rb
|
157
|
+
- lib/webdrone/wait.rb
|
158
|
+
- lib/webdrone/xlsx.rb
|
159
|
+
- webdrone.gemspec
|
160
|
+
homepage: http://github.com/a0/a0-webdrone-ruby
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata:
|
164
|
+
allowed_push_host: https://rubygems.org
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.4.6
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: A simple selenium webdriver wrapper, ruby version.
|
185
|
+
test_files: []
|