mobilify 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -18
- data/features/step_definitions/link_steps.rb +2 -2
- data/features/step_definitions/navigation_step.rb +1 -1
- data/features/support/manta_page.rb +2 -2
- data/lib/mobilify.rb +9 -9
- data/lib/mobilify/version.rb +1 -1
- data/mobilify.gemspec +2 -2
- metadata +5 -5
data/README.md
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
# Mobilify
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/mobilify.png)](http://badge.fury.io/rb/mobilify)
|
3
3
|
|
4
|
-
|
4
|
+
Mobilify allows you to create one page object and write one test for your web application, but execute different methods as part of that test given the context. Just change context when initializing your object.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
Mobilify allows you to create one page object and write one test. You write tests for the desktop, and it will grab mobile elements when necessary. Just define the context during page initialization.
|
9
|
-
|
10
|
-
#### Usage
|
11
|
-
To Mobilify your page objects, ```include Mobilify``` in the page class. For each method requiring a mobile replacement, create an element definition with ```mobile_``` prepended to the original's name.
|
6
|
+
## Usage
|
7
|
+
To Mobilify your page objects, ```include Mobilify``` in the page class. For each method requiring a mobile replacement, create an element (or method) definition with your context prepended to the original's name (like `mobile_`).
|
12
8
|
|
13
9
|
```ruby
|
14
10
|
# method
|
@@ -17,27 +13,23 @@ text_field(:password, :id => "user-pw")
|
|
17
13
|
text_field(:mobile_password, :id => "mobile-pw")
|
18
14
|
```
|
19
15
|
|
20
|
-
Mobilify will replace called methods with their
|
16
|
+
Mobilify will replace called methods with their contextual counterparts if two conditions are met. First, a hash with a key-value pair of `:context => :{your_context}` is passed to the page object constructor. And second, the page object responds to `{your_context}_method`.
|
21
17
|
|
22
18
|
```ruby
|
23
19
|
# constructor
|
24
|
-
my_page = Page.new(@browser, :
|
20
|
+
my_page = Page.new(@browser, :context => :mobile)
|
25
21
|
```
|
26
22
|
|
27
23
|
To navigate to your page object during initialization, pass the key-value pair ```:visit => true``` to the constructor.
|
28
24
|
```ruby
|
29
25
|
# visiting
|
30
26
|
my_page = Page.new(@browser, :visit => true)
|
31
|
-
my_page = Page.new(@browser, :visit => true, :
|
27
|
+
my_page = Page.new(@browser, :visit => true, :context => :mobile)
|
32
28
|
```
|
33
29
|
|
34
30
|
#### Example
|
35
31
|
|
36
|
-
You're testing a responsive page with a link to your registration form. But you can only identify the link with XPath, and the XPath changes between your desktop-sized application and your mobile-sized application.
|
37
|
-
|
38
|
-
* Call two different methods in two different specs, each pointing to its own XPath
|
39
|
-
* Call two different methods in one spec, using logic to determine the call correctly
|
40
|
-
* Call the same method in one spec and Mobilify the page object for mobile testing
|
32
|
+
You're testing a responsive page with a link to your registration form. But you can only identify the link with XPath, and the XPath changes between your desktop-sized application and your mobile-sized application.
|
41
33
|
|
42
34
|
```ruby
|
43
35
|
# spec/page.rb
|
@@ -64,11 +56,11 @@ RSpec.configure do |config|
|
|
64
56
|
case ENV['BROWSER']
|
65
57
|
when 'desktop'
|
66
58
|
@browser = Watir::Browser.new :firefox
|
67
|
-
@
|
59
|
+
@my_context = :desktop
|
68
60
|
when 'mobile'
|
69
61
|
driver = Webdriver::UserAgent.driver(:browser => :firefox, :agent => :iphone)
|
70
62
|
@browser = Watir::Browser.new driver
|
71
|
-
@
|
63
|
+
@my_context = :mobile
|
72
64
|
end
|
73
65
|
end
|
74
66
|
end
|
@@ -80,7 +72,7 @@ require 'spec_helper'
|
|
80
72
|
require 'page'
|
81
73
|
|
82
74
|
describe Page do
|
83
|
-
let(:page) { Page.new(@browser, :
|
75
|
+
let(:page) { Page.new(@browser, :context => @my_context, :visit => true) }
|
84
76
|
|
85
77
|
describe "#to_registration" do
|
86
78
|
it "takes me to the registration form" do
|
@@ -15,11 +15,11 @@ Then /^I should receive true$/ do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Then /^I should receive the desktop link element$/ do
|
18
|
-
@element.inspect.should include(':
|
18
|
+
@element.inspect.should include(':xpath=>"//div[@class=\'panel-body\']//a[contains(@href, \'/cmap/\')]"')
|
19
19
|
end
|
20
20
|
|
21
21
|
Then /^I should receive the mobile link element$/ do
|
22
|
-
@element.inspect.should include(':
|
22
|
+
@element.inspect.should include(':xpath=>"//div[@class=\'col-xs-6\']/a[contains(@href, \'/cmap/\')]"')
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^I should land on the map page$/ do
|
@@ -5,6 +5,6 @@ class MantaPage
|
|
5
5
|
|
6
6
|
page_url "http://www.manta.com/c/mm2fqg7"
|
7
7
|
|
8
|
-
link(:map, :
|
9
|
-
link(:mobile_map, :
|
8
|
+
link(:map, :xpath => "//div[@class='panel-body']//a[contains(@href, '/cmap/')]")
|
9
|
+
link(:mobile_map, :xpath => "//div[@class='col-xs-6']/a[contains(@href, '/cmap/')]")
|
10
10
|
end
|
data/lib/mobilify.rb
CHANGED
@@ -5,32 +5,32 @@ module Mobilify
|
|
5
5
|
|
6
6
|
def initialize(browser, opts = {})
|
7
7
|
super(browser, opts[:visit] || false)
|
8
|
-
@
|
9
|
-
mobilify! if
|
8
|
+
@context = opts[:context]
|
9
|
+
mobilify! if context?
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.included(klass)
|
13
13
|
klass.send :include, PageObject
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
@
|
16
|
+
def context?
|
17
|
+
@context
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def mobilify!
|
23
|
+
context = @context.to_s
|
24
|
+
|
23
25
|
methods.
|
24
|
-
select { |m| m.to_s.start_with?
|
25
|
-
select { |m| respond_to? m.to_s.gsub(
|
26
|
+
select { |m| m.to_s.start_with? "#{context}_" }.
|
27
|
+
select { |m| respond_to? m.to_s.gsub("#{context}_", '') }.
|
26
28
|
map { |m| self.method(m) }.each do |method|
|
27
29
|
(class << self; self; end).class_eval do
|
28
|
-
define_method(method.name.to_s.gsub(
|
30
|
+
define_method(method.name.to_s.gsub("#{context}_", ''), method)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
|
-
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
36
|
require 'mobilify/version'
|
data/lib/mobilify/version.rb
CHANGED
data/mobilify.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Mobilify::VERSION
|
9
9
|
spec.authors = ["Johnson Denen"]
|
10
10
|
spec.email = ["jdenen@manta.com"]
|
11
|
-
spec.description = %q{switch seamlessly between page-object methods when testing your web app
|
12
|
-
spec.summary = %q{switch seamlessly between page-object methods when testing your web app
|
11
|
+
spec.description = %q{switch seamlessly between page-object methods when testing your web app in different contexts}
|
12
|
+
spec.summary = %q{switch seamlessly between page-object methods when testing your web app in different contexts}
|
13
13
|
spec.homepage = "http://github.com/jdenen/mobilify"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobilify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: page-object
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
description: switch seamlessly between page-object methods when testing your web app
|
111
|
-
|
111
|
+
in different contexts
|
112
112
|
email:
|
113
113
|
- jdenen@manta.com
|
114
114
|
executables: []
|
@@ -154,8 +154,8 @@ rubyforge_project:
|
|
154
154
|
rubygems_version: 1.8.23
|
155
155
|
signing_key:
|
156
156
|
specification_version: 3
|
157
|
-
summary: switch seamlessly between page-object methods when testing your web app
|
158
|
-
different
|
157
|
+
summary: switch seamlessly between page-object methods when testing your web app in
|
158
|
+
different contexts
|
159
159
|
test_files:
|
160
160
|
- features/desktop_link.feature
|
161
161
|
- features/mobile_link.feature
|