ripl-watir 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +35 -47
- data/bin/ripl-watir +5 -5
- data/lib/ripl_watir.rb +56 -0
- data/ripl-watir.gemspec +2 -2
- metadata +28 -12
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ may then be performed with bionic superpowers.
|
|
8
8
|
|
9
9
|
gem install ripl_watir
|
10
10
|
|
11
|
-
==
|
11
|
+
== Usage
|
12
12
|
|
13
13
|
Hopefully this serves as some kind of demonstration:
|
14
14
|
|
@@ -23,71 +23,59 @@ ripl console shell.
|
|
23
23
|
|
24
24
|
... add the 'lib' directory to the load path
|
25
25
|
|
26
|
-
Now create a file 'lib/
|
26
|
+
Now create a file 'lib/pages/github.rb' containing the following:
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
extend WatirPageHelper::ClassMethods
|
32
|
-
|
33
|
-
direct_url 'github.com'
|
34
|
-
link :login, text: 'Login'
|
35
|
-
|
36
|
-
def logged_in?
|
37
|
-
browser.div(id: 'user').exists?
|
28
|
+
module Pages::Github
|
29
|
+
def goto
|
30
|
+
browser.goto 'github.com'
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
34
|
... and now be amazed:
|
42
35
|
|
43
|
-
>>
|
36
|
+
>> visit_page :github
|
44
37
|
|
45
|
-
... this creates an instance of the
|
46
|
-
path), mixes
|
47
|
-
goto method (which tells the browser to goto github.com).
|
38
|
+
... this creates an instance of the Pages::Page class, loads 'pages/github' (from whereever it happens to be on the load
|
39
|
+
path), mixes Pages::Github into the page class and calls the
|
40
|
+
goto method (which tells the browser to goto github.com). Amazing?
|
48
41
|
|
49
|
-
|
42
|
+
Now edit the 'lib/pages/github.rb' file to add this method:
|
50
43
|
|
51
|
-
|
44
|
+
module Pages::Github
|
45
|
+
def login
|
46
|
+
browser.link(text: 'Sign in').click
|
47
|
+
end
|
48
|
+
...
|
52
49
|
|
53
|
-
|
50
|
+
... and back in the ripl session:
|
54
51
|
|
55
|
-
|
52
|
+
>> on_page(:github).login
|
56
53
|
|
57
|
-
|
58
|
-
extend WatirPageHelper::ClassMethods
|
54
|
+
This reloads the github page and calls the login method on the page (which clicks the login button).
|
59
55
|
|
60
|
-
|
61
|
-
text_field :password, id: 'password'
|
62
|
-
button :submit, value: 'Log in'
|
56
|
+
Now create a file 'lib/pages/github/login.rb' containing the following:
|
63
57
|
|
58
|
+
module Pages::Github::Login
|
64
59
|
def login email, password
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
browser.text_field(id: 'login_field').set email
|
61
|
+
browser.text_field(id: 'password').set password
|
62
|
+
browser.button(value: 'Sign in').click
|
68
63
|
end
|
69
64
|
end
|
70
65
|
|
71
66
|
... and be further amazed:
|
72
67
|
|
73
|
-
>> on_page(:github, :login)
|
74
|
-
| login_page.login 'me@my.mail.com', 'password'
|
75
|
-
| end
|
68
|
+
>> on_page(:github, :login).login 'me@my.mail.com', 'password'
|
76
69
|
|
77
|
-
... creates another instance of the
|
78
|
-
'
|
79
|
-
path)
|
70
|
+
... creates another instance of the Pages::Page class, reloads
|
71
|
+
'pages/github/login.rb' (from whereever it happens to be on the load
|
72
|
+
path) and mixes Pages::Github::Login into it.
|
80
73
|
|
81
74
|
The main purpose of all this is to be able to modify/define page mixins,
|
82
75
|
and reload them all without having to restart the console or create a
|
83
76
|
new browser session.
|
84
77
|
|
85
|
-
If for example, you added a new page mixin or a new method to an already instantiated one, you
|
86
|
-
|
87
|
-
>> load 'ripl_watir/github/login'
|
88
|
-
|
89
|
-
If the page mixin you've created has not been loaded already, this step
|
90
|
-
is not necessary since the page mixins are only required on first use.
|
78
|
+
If for example, you added a new page mixin or a new method to an already instantiated one, you should find the new method is immediately available.
|
91
79
|
|
92
80
|
If you just want to tell the browser to do something, it is directly
|
93
81
|
available as 'browser' without needing a page object.
|
@@ -96,12 +84,12 @@ available as 'browser' without needing a page object.
|
|
96
84
|
|
97
85
|
== Page Objects
|
98
86
|
|
99
|
-
|
87
|
+
The page objects are always a Pages::Page instance
|
100
88
|
(which is a delegate of Watir::Browser) with a specified mixin.
|
101
89
|
|
102
|
-
This
|
103
|
-
|
104
|
-
against the
|
90
|
+
This mixins add methods specifically for interacting with that particular page.
|
91
|
+
|
92
|
+
You can just define methods against the browser instance varaible or delegate to the page itself.
|
105
93
|
|
106
94
|
These page mixins will be loaded from anywhere on the load path.
|
107
95
|
|
@@ -111,9 +99,9 @@ To use page mixins defined in this way with cucumber, define your
|
|
111
99
|
page objects in a 'lib' (make sure this directory is on the load path)
|
112
100
|
and mix the commands into the cucumber 'world' in env.rb:
|
113
101
|
|
114
|
-
require 'ripl_watir
|
102
|
+
require 'ripl_watir'
|
115
103
|
World RiplWatir::Commands
|
116
104
|
|
117
|
-
As long as your page mixins are in a '
|
105
|
+
As long as your page mixins are in a 'pages' directory on the path
|
118
106
|
and are constants defined (at any depth) under the RiplWatir module, they
|
119
|
-
should be located.
|
107
|
+
should be successfully located.
|
data/bin/ripl-watir
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$: << File.dirname(__FILE__)+'/../lib'
|
2
3
|
require 'ripl'
|
3
|
-
require '
|
4
|
-
|
5
|
-
browser =
|
6
|
-
|
7
|
-
Ripl.start :binding => binding
|
4
|
+
require 'ripl_watir'
|
5
|
+
include RiplWatir::Commands
|
6
|
+
browser = RiplWatir.create
|
7
|
+
Ripl.start binding: binding
|
data/lib/ripl_watir.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'watir-webdriver'
|
2
|
+
require 'watir-webdriver'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Pages
|
6
|
+
class Page
|
7
|
+
attr_reader :browser
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :@browser, :title, :url, :html, :status, :refresh, :back
|
11
|
+
|
12
|
+
def initialize browser
|
13
|
+
@browser = browser
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module RiplWatir
|
19
|
+
class << self
|
20
|
+
attr_accessor :browser
|
21
|
+
|
22
|
+
def create
|
23
|
+
@browser = ::Watir::Browser.new ENV['WEBDRIVER'] || :firefox
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Commands
|
28
|
+
def classify s
|
29
|
+
s.to_s.split('_').map(&:capitalize).join
|
30
|
+
end
|
31
|
+
|
32
|
+
def page_class *args
|
33
|
+
page = Pages::Page.new RiplWatir.browser
|
34
|
+
load "pages/#{args.join '/'}.rb"
|
35
|
+
mod = Pages
|
36
|
+
args.each do |name|
|
37
|
+
mod = mod.const_get classify name
|
38
|
+
end
|
39
|
+
page.extend mod
|
40
|
+
page
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_page *args
|
44
|
+
page_class(*args).tap do |p|
|
45
|
+
yield p if block_given?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def visit_page *args
|
50
|
+
on_page(*args) do |p|
|
51
|
+
p.goto
|
52
|
+
yield p if block_given?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/ripl-watir.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ripl-watir"
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.3'
|
7
7
|
s.authors = ["Mark Ryall"]
|
8
8
|
s.email = ["mark@ryall.name"]
|
9
9
|
s.homepage = "https://github.com/markryall/ripl_watir"
|
@@ -21,7 +21,7 @@ EOF
|
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
23
|
s.add_runtime_dependency "ripl"
|
24
|
-
s.add_runtime_dependency "watir-
|
24
|
+
s.add_runtime_dependency "watir-webdriver"
|
25
25
|
|
26
26
|
s.add_development_dependency "rake"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-watir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ripl
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
|
-
name: watir-
|
27
|
-
requirement:
|
31
|
+
name: watir-webdriver
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rake
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
description: ! 'A ripl plugin to provide an interactive shell for creating page objects
|
48
63
|
|
49
64
|
to build an automated testing infrastructure for a site.
|
@@ -61,6 +76,7 @@ files:
|
|
61
76
|
- README.rdoc
|
62
77
|
- Rakefile
|
63
78
|
- bin/ripl-watir
|
79
|
+
- lib/ripl_watir.rb
|
64
80
|
- ripl-watir.gemspec
|
65
81
|
homepage: https://github.com/markryall/ripl_watir
|
66
82
|
licenses: []
|
@@ -76,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
92
|
version: '0'
|
77
93
|
segments:
|
78
94
|
- 0
|
79
|
-
hash: -
|
95
|
+
hash: -3087682925850807916
|
80
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
97
|
none: false
|
82
98
|
requirements:
|
@@ -85,10 +101,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
101
|
version: '0'
|
86
102
|
segments:
|
87
103
|
- 0
|
88
|
-
hash: -
|
104
|
+
hash: -3087682925850807916
|
89
105
|
requirements: []
|
90
106
|
rubyforge_project: ripl-watir
|
91
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.24
|
92
108
|
signing_key:
|
93
109
|
specification_version: 3
|
94
110
|
summary: watir repl for efficiently creating page objects
|