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 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
- We don't like to maintain a lot of test code. Which means, we don't want to rewrite the same tests for the same web application on different platforms. It's easy when those different platforms are browsers, because the site doesn't change much (at all?).
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
- But, it's a challenge to reuse code when the different platforms are desktop and mobile browsers. The elements move, and their identifiers change. We could create separate page objects for desktop and mobile, with a mixin object for the shared stuff. Or we could create one page object with all the elements, and write two different tests. Seems like a waste both ways.
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 ```mobile_``` counterparts if two conditions are met. First, a hash with a key-value pair of ```:agent => :mobile``` is passed to the page object constructor. And second, the page object responds to a ```mobile_``` version of the called method.
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, :agent => :mobile)
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, :agent => :mobile)
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. You could:
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
- @agent = :desktop
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
- @agent = :mobile
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, :agent => @agent, :visit => true) }
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(':id=>"map-tab-link"')
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(':class=>"pvm prm"')
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
@@ -10,5 +10,5 @@ Given /^I am using a mobile device$/ do
10
10
  end
11
11
 
12
12
  Given /^I navigate to a Manta profile$/ do
13
- @page = MantaPage.new(@browser, :agent => @agent, :visit => true)
13
+ @page = MantaPage.new(@browser, :context => @agent, :visit => true)
14
14
  end
@@ -5,6 +5,6 @@ class MantaPage
5
5
 
6
6
  page_url "http://www.manta.com/c/mm2fqg7"
7
7
 
8
- link(:map, :id => "map-tab-link")
9
- link(:mobile_map, :class => "pvm prm")
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
@@ -5,32 +5,32 @@ module Mobilify
5
5
 
6
6
  def initialize(browser, opts = {})
7
7
  super(browser, opts[:visit] || false)
8
- @mobile = opts[:agent] == :mobile
9
- mobilify! if mobile?
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 mobile?
17
- @mobile
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? 'mobile_' }.
25
- select { |m| respond_to? m.to_s.gsub('mobile_', '') }.
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('mobile_', ''), method)
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'
@@ -1,3 +1,3 @@
1
1
  module Mobilify
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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 at different sizes}
12
- spec.summary = %q{switch seamlessly between page-object methods when testing your web app at different sizes}
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.0.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-29 00:00:00.000000000 Z
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
- at different sizes
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 at
158
- different sizes
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