selenium-more 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +17 -3
- data/VERSION +1 -1
- data/lib/selenium/more/hooks.rb +26 -13
- data/selenium-more.gemspec +3 -3
- data/spec/lib/selenium/more/hooks_spec.rb +78 -14
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 430e38cc3db22c67bb1f5a90da710a3ddc8912df
|
4
|
+
data.tar.gz: a070b39f1307a447122ff77e23543a1eac61c393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a0592166dfa8f6850894987faef78c8ec5322b694ea40fb3549cfd155e7fcb5357dfedb625ecf0ba5557c1004d49db81559dd9278584be580aa64343051062
|
7
|
+
data.tar.gz: 80464f2ff87df53202486101b6a79ba672e3e8c01d1f50d7438cda9d2a4b59687856f3286c928be434a6407723666c599a79842b6378b96fea31c576d42571c3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Selenium WebDriver utilities.
|
|
5
5
|
## Features
|
6
6
|
|
7
7
|
* hook interface to selenium-webdriver
|
8
|
-
* utilities for test
|
8
|
+
* utilities for test (not yet)
|
9
9
|
* session management
|
10
10
|
* implicit and explicit wait
|
11
11
|
* retry
|
@@ -35,8 +35,8 @@ Sample Code:
|
|
35
35
|
class Selenium::WebDriver::Driver
|
36
36
|
include Selenium::More::Hooks
|
37
37
|
|
38
|
-
hook :get, before: ->(driver) { puts driver.current_url }
|
39
|
-
after: ->(driver, ret) { puts driver.
|
38
|
+
hook :get, before: ->(driver, url) { puts driver.current_url }
|
39
|
+
after: ->(driver, ret, url) { puts driver.current_url }
|
40
40
|
end
|
41
41
|
|
42
42
|
driver = Selenium::WebDriver.for :phantomjs
|
@@ -50,6 +50,20 @@ about:blank
|
|
50
50
|
http://example.com/
|
51
51
|
```
|
52
52
|
|
53
|
+
You can also add hook to each instance of ::Selenium::WebDriver::Driver. It results the same with above.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Selenium::WebDriver::Driver
|
57
|
+
include Selenium::More::Hooks
|
58
|
+
end
|
59
|
+
|
60
|
+
driver = Selenium::WebDriver.for :phantomjs
|
61
|
+
driver.hook :get, before: ->(driver, url) { puts driver.current_url }
|
62
|
+
after: ->(driver, ret, url) { puts driver.current_url }
|
63
|
+
|
64
|
+
driver.get "http://example.com/"
|
65
|
+
```
|
66
|
+
|
53
67
|
### session management
|
54
68
|
|
55
69
|
T.B.D.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/selenium/more/hooks.rb
CHANGED
@@ -6,22 +6,35 @@ module Selenium::More
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
def self.module_to_prepend(method_name, before: nil, after: nil)
|
10
|
+
raise ArgumentError, "at least one of before or after is needed" unless before || after
|
11
|
+
|
12
|
+
Module.new do
|
13
|
+
define_method method_name do |*args|
|
14
|
+
before.call(self, *args) if before
|
15
|
+
ret = super(*args)
|
16
|
+
after.call(self, ret, *args) if after
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
ret
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
+
def hook(method_name, opts)
|
24
|
+
if respond_to?(method_name.to_sym)
|
25
|
+
# when ruby < 2.1.0, prepend is private method
|
26
|
+
self.singleton_class.__send__(:prepend, Hooks.module_to_prepend(method_name, opts))
|
27
|
+
else
|
28
|
+
raise NoMethodError, "no #{method_name} to hook"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def hook(method_name, opts)
|
34
|
+
if instance_methods.include?(method_name.to_sym)
|
35
|
+
prepend Hooks.module_to_prepend(method_name, opts)
|
23
36
|
else
|
24
|
-
raise NoMethodError, "no #{
|
37
|
+
raise NoMethodError, "no #{method_name} to hook"
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
data/selenium-more.gemspec
CHANGED
@@ -28,11 +28,11 @@ _DESCRIPTION_
|
|
28
28
|
spec.add_development_dependency "rake"
|
29
29
|
|
30
30
|
# test
|
31
|
-
spec.
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0.0.beta"
|
32
32
|
|
33
33
|
# to run selenium-standalone-server
|
34
|
-
spec.
|
34
|
+
spec.add_development_dependency "selenium-connect"
|
35
35
|
|
36
36
|
# auto test
|
37
|
-
spec.
|
37
|
+
spec.add_development_dependency "guard-rspec"
|
38
38
|
end
|
@@ -3,16 +3,21 @@ require "spec_helper"
|
|
3
3
|
require "selenium/more/hooks"
|
4
4
|
|
5
5
|
describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
|
6
|
+
let(:base_class) do
|
7
|
+
Class.new(described_class) do
|
8
|
+
include Selenium::More::Hooks
|
9
|
+
|
10
|
+
def spy
|
11
|
+
@spy ||= []
|
12
|
+
end
|
13
|
+
attr_writer :spy
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
6
17
|
context ".hook" do
|
7
18
|
context "of before and after" do
|
8
19
|
let(:klass) do
|
9
|
-
Class.new(
|
10
|
-
include Selenium::More::Hooks
|
11
|
-
|
12
|
-
def spy
|
13
|
-
@spy ||= []
|
14
|
-
end
|
15
|
-
|
20
|
+
Class.new(base_class) do
|
16
21
|
hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
|
17
22
|
after: ->(driver, ret) { driver.spy << "after_hook1" }
|
18
23
|
hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
|
@@ -32,13 +37,23 @@ describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
|
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
|
-
context "of
|
40
|
+
context "of before" do
|
36
41
|
let(:klass) do
|
37
|
-
Class.new(
|
38
|
-
|
42
|
+
Class.new(base_class) do
|
43
|
+
hook :get, before: ->(driver, url) { driver.spy = url }
|
44
|
+
end
|
45
|
+
end
|
39
46
|
|
40
|
-
|
47
|
+
let(:driver) { klass.for :remote, desired_capabilities: :htmlunit }
|
41
48
|
|
49
|
+
it "passes args to before hook" do
|
50
|
+
expect { driver.get "about:blank" }.to change { driver.spy }.to("about:blank")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "of after" do
|
55
|
+
let(:klass) do
|
56
|
+
Class.new(base_class) do
|
42
57
|
hook :current_url, after: ->(driver, ret) { driver.spy = ret }
|
43
58
|
end
|
44
59
|
end
|
@@ -54,13 +69,62 @@ describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
|
|
54
69
|
context "when no method is available" do
|
55
70
|
it "raise NoMethodError" do
|
56
71
|
expect {
|
57
|
-
Class.new(
|
58
|
-
include Selenium::More::Hooks
|
59
|
-
|
72
|
+
Class.new(base_class) do
|
60
73
|
hook :hoge, before: ->(driver) { driver }
|
61
74
|
end
|
62
75
|
}.to raise_exception(NoMethodError, "no hoge to hook")
|
63
76
|
end
|
64
77
|
end
|
65
78
|
end
|
79
|
+
|
80
|
+
context "#hook" do
|
81
|
+
context "of before and after" do
|
82
|
+
let(:klass) { base_class }
|
83
|
+
|
84
|
+
let(:driver) do
|
85
|
+
driver = klass.for :remote, desired_capabilities: :htmlunit
|
86
|
+
driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
|
87
|
+
after: ->(driver, ret) { driver.spy << "after_hook1" }
|
88
|
+
driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
|
89
|
+
after: ->(driver, ret) { driver.spy << "after_hook2" }
|
90
|
+
driver
|
91
|
+
end
|
92
|
+
|
93
|
+
it "is called before and after in order" do
|
94
|
+
expect { driver.current_url }.to change { driver.spy }.to(%w[ before_hook2 before_hook1 after_hook1 after_hook2 ])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when no method is available" do
|
99
|
+
let(:klass) { base_class }
|
100
|
+
|
101
|
+
let(:driver) { base_class.for :remote, desired_capabilities: :htmlunit }
|
102
|
+
|
103
|
+
it "raise NoMethodError" do
|
104
|
+
expect {
|
105
|
+
driver.hook :hoge, before: ->(driver) { driver }
|
106
|
+
}.to raise_exception(NoMethodError, "no hoge to hook")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "convination with .hook and #hook" do
|
112
|
+
let(:klass) do
|
113
|
+
Class.new(base_class) do
|
114
|
+
hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
|
115
|
+
after: ->(driver, ret) { driver.spy << "after_hook1" }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
let(:driver) do
|
120
|
+
driver = klass.for :remote, desired_capabilities: :htmlunit
|
121
|
+
driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
|
122
|
+
after: ->(driver, ret) { driver.spy << "after_hook2" }
|
123
|
+
driver
|
124
|
+
end
|
125
|
+
|
126
|
+
it "is called before and after in order" do
|
127
|
+
expect { driver.current_url }.to change { driver.spy }.to(%w[ before_hook2 before_hook1 after_hook1 after_hook2 ])
|
128
|
+
end
|
129
|
+
end
|
66
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium-more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okitan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: selenium-webdriver
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.0.0.beta
|
62
|
-
type: :
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
-
type: :
|
90
|
+
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
@@ -108,6 +108,7 @@ extra_rdoc_files: []
|
|
108
108
|
files:
|
109
109
|
- ".gitignore"
|
110
110
|
- ".travis.yml"
|
111
|
+
- CHANGELOG.md
|
111
112
|
- Gemfile
|
112
113
|
- Guardfile
|
113
114
|
- LICENSE.txt
|