appom 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/lib/appom.rb +47 -0
- data/lib/appom/cucumber.rb +6 -0
- data/lib/appom/element_container.rb +92 -0
- data/lib/appom/page.rb +16 -0
- data/lib/appom/version.rb +3 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19d5e9be64b9d999fbae65e039edf9bcaf536d4ddab5b038d75794a4a5f1026a
|
4
|
+
data.tar.gz: b0b1008c8e03da65545f6186b054a3f571243f94c1d41b226fb60b3f517e99af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd95475d8526f2d9342e19d9abbbedb3e590904c5d02877b3c97aa9413ee28be7917cad67641db82146d83c4d918cc224e3a2237f99a0ecea5b3064c029bbd1d
|
7
|
+
data.tar.gz: b19155129ddc7b46408af1494089c1dad03d85dbade07f98ba38637e175fb591a163f56b12a7d77a64e8334bda7a2846c097436344998bdce8abd6db1003a203
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Harry.Tran
|
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,70 @@
|
|
1
|
+
# Appom
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/appom.svg)](http://badge.fury.io/rb/appom)
|
3
|
+
|
4
|
+
A Page Object Model for Appium
|
5
|
+
|
6
|
+
Appom gives you a simple, clean and semantic for describing your application. Appom implements the Page Object Model pattern on top of Appium.
|
7
|
+
|
8
|
+
## Idea
|
9
|
+
If you have used the [Page Object Model](https://medium.com/tech-tajawal/page-object-model-pom-design-pattern-f9588630800b) (POM) with Appium you will probably know about [Capybara](https://github.com/teamcapybara/capybara) and [SitePrism](https://github.com/natritmeyer/site_prism). But CapyBara and SitePrism are designed for the web rather than the mobile.
|
10
|
+
|
11
|
+
Using POM with SitePrism and CapyBara makes interacting with Appium really not that direct. And Appium is not confirmed to work well with these two libraries.
|
12
|
+
|
13
|
+
Wishing to use the Page Object Model in the simplest way we created Appom. The idea created for Appom is taken from CapyBara and SitePrism.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'appom'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install appom
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Here's an overview of how Appom is designed to be used:
|
34
|
+
|
35
|
+
### Register Appium Driver
|
36
|
+
Appium use appium directly to find elements. So that to use Appom you must register Appium Driver for Appom
|
37
|
+
```ruby
|
38
|
+
Appom.register_driver do
|
39
|
+
options = {
|
40
|
+
appium_lib: appium_lib_options,
|
41
|
+
caps: caps
|
42
|
+
}
|
43
|
+
Appium::Driver.new(options, false)
|
44
|
+
end
|
45
|
+
```
|
46
|
+
`appium_lib_options` and `caps` are options to initiate a appium driver. You can follow [Appium Ruby Client](https://github.com/appium/ruby_lib)
|
47
|
+
|
48
|
+
|
49
|
+
### Define a page
|
50
|
+
```ruby
|
51
|
+
class LoginPage < Appom::Page
|
52
|
+
element :email, :accessibility_id, 'email_text_field'
|
53
|
+
element :password, :accessibility_id, 'password_text_field'
|
54
|
+
element :sign_in_button, :accessibility_id, 'sign_in_button'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at [Appom](https://github.com/hoangtaiki/appom). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
67
|
+
|
68
|
+
## Code of Conduct
|
69
|
+
|
70
|
+
Everyone interacting in the Appom project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hoangtaiki/appom/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/appom.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'appom/version'
|
4
|
+
require 'appium_lib'
|
5
|
+
require 'appom/cucumber'
|
6
|
+
|
7
|
+
module Appom
|
8
|
+
# A item was defined without a selector
|
9
|
+
class InvalidElementError < StandardError; end
|
10
|
+
# A block was passed to the method, which it cannot interpret
|
11
|
+
class UnsupportedBlockError < StandardError; end
|
12
|
+
|
13
|
+
autoload :ElementContainer, 'appom/element_container'
|
14
|
+
autoload :Page, 'appom/page'
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :driver
|
18
|
+
|
19
|
+
# Register a new appium driver for Appom.
|
20
|
+
# @return [Appium::Driver] A appium driver instance
|
21
|
+
def register_driver(&block)
|
22
|
+
@driver = block.call()
|
23
|
+
setup_exit_handler
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a new global driver and quits the old one if it exists.
|
27
|
+
def start_driver
|
28
|
+
@driver.start_driver
|
29
|
+
end
|
30
|
+
|
31
|
+
# Reset the device, relaunching the application.
|
32
|
+
def reset_driver
|
33
|
+
@driver.reset
|
34
|
+
end
|
35
|
+
|
36
|
+
# After run all scenario and exit we will quit driver to close appliction under test
|
37
|
+
def setup_exit_handler
|
38
|
+
main = Process.pid
|
39
|
+
at_exit do
|
40
|
+
@driver.driver_quit if Process.pid == main
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
World(Appom)
|
47
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Appom
|
2
|
+
module ElementContainer
|
3
|
+
def self.included(klass)
|
4
|
+
klass.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_reader :mapped_items
|
9
|
+
|
10
|
+
# Raise if contain a block
|
11
|
+
def raise_if_block(obj, name, has_block, type)
|
12
|
+
return unless has_block
|
13
|
+
|
14
|
+
puts "Type passed in: #{type}"
|
15
|
+
puts "#{obj.class}##{name} does not accept blocks"
|
16
|
+
|
17
|
+
raise Appom::UnsupportedBlockError
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
#
|
22
|
+
# Declare an element with name and args to find it
|
23
|
+
#
|
24
|
+
# element :email, :accessibility_id, 'email_text_field'
|
25
|
+
#
|
26
|
+
# @param name Element name
|
27
|
+
# @param *find_args An array contain information to find the element. It contains locator stratery and search target
|
28
|
+
# http://appium.io/docs/en/commands/element/find-element/
|
29
|
+
#
|
30
|
+
# Element doesn't support block so that will raise if pass a block when declare
|
31
|
+
#
|
32
|
+
def element(name, *find_args)
|
33
|
+
build(name, *find_args) do |*runtime_args, &block|
|
34
|
+
raise_if_block(self, name, !block.nil?, :element)
|
35
|
+
define_method(name) do
|
36
|
+
find(*find_args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
#
|
43
|
+
# Declare an elements with name and args to find it
|
44
|
+
#
|
45
|
+
# elements :contact_cell, :accessibility_id, 'contact_cell'
|
46
|
+
#
|
47
|
+
# @param name Element name
|
48
|
+
# @param *find_args An array contain information to find the elements. It contains locator stratery and search target
|
49
|
+
# http://appium.io/docs/en/commands/element/find-element/
|
50
|
+
#
|
51
|
+
# Elements doesn't support block so that will raise if pass a block when declare
|
52
|
+
#
|
53
|
+
def elements(name, *find_args)
|
54
|
+
build(name, *find_args) do |*runtime_args, &block|
|
55
|
+
define_method(name) do
|
56
|
+
raise_if_block(self, name, !block.nil?, :elements)
|
57
|
+
all(*find_args)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Add item to @mapped_items array
|
64
|
+
#
|
65
|
+
# @param item Item need to add
|
66
|
+
#
|
67
|
+
def add_to_mapped_items(item)
|
68
|
+
@mapped_items ||= []
|
69
|
+
@mapped_items << item
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
# Add item to @mapped_items or define mothod to notify that we can't find item without args
|
75
|
+
def build(name, *find_args)
|
76
|
+
if find_args.empty?
|
77
|
+
create_error_method(name)
|
78
|
+
else
|
79
|
+
add_to_mapped_items(name)
|
80
|
+
yield
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Define mothod to notify that we can't find item without args
|
85
|
+
def create_error_method(name)
|
86
|
+
define_method(name) do
|
87
|
+
raise Appom::InvalidElementError
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/appom/page.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Appom
|
2
|
+
class Page
|
3
|
+
include Appium
|
4
|
+
include ElementContainer
|
5
|
+
|
6
|
+
# Find an element
|
7
|
+
def find(*find_args)
|
8
|
+
Appom.driver.find_element(*find_args)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Find elements
|
12
|
+
def all(*find_args)
|
13
|
+
Appom.driver.find_elements(*find_args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harry.Tran
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appium_lib
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 9.15.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 9.15.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.58'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.58'
|
55
|
+
description: Appom gives you a simple, clean and semantic for describing your application.
|
56
|
+
Appom implements the Page Object Model pattern on top of Appium.
|
57
|
+
email:
|
58
|
+
- hoang@platphormcorp.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- lib/appom.rb
|
66
|
+
- lib/appom/cucumber.rb
|
67
|
+
- lib/appom/element_container.rb
|
68
|
+
- lib/appom/page.rb
|
69
|
+
- lib/appom/version.rb
|
70
|
+
homepage: https://github.com/hoangtaiki/appom
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.7.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A Page Object Model for Appium
|
94
|
+
test_files: []
|