web-object 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENCE +0 -0
- data/README.md +140 -0
- data/lib/web-object/version +1 -0
- data/lib/web-object/web-object.rb +38 -0
- data/lib/web-object.rb +2 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b27cc7c593f89557072eb0230513efa244302191
|
4
|
+
data.tar.gz: 9835f0fa4aa79272ad5365bbcff74def017e570a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc1dd0cabf5605ff0915436b590e13a9e37a58babdd3d41cac1ea4cdab27df275e9d540762fa966ee749f1149c55d8d596e6ba984f8c302275f0b4efc932a974
|
7
|
+
data.tar.gz: 0e0c2175d5c9046b235bb93eca9d42340ae6184e30abaca4500fc87c53e58aa83e266f3ff23a1573df0e123d47e5b02eb7d1604850fb2b7693c8fa34dbfb2122
|
data/LICENCE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#web-object
|
2
|
+
|
3
|
+
Create page-object style test framework using original webdriver flavor.
|
4
|
+
Now what does original webdriver flavor is, it simply means, no additional wrappers, no additional syntax.
|
5
|
+
Hence just create page-objects and start using basic webdriver commands on it.
|
6
|
+
|
7
|
+
Moral of the story, elements created using web-object gem will be objects of WebElement class and one can perform all webdriver
|
8
|
+
commands on it like send_keys, click, displayed? .. and so on...
|
9
|
+
|
10
|
+
## Table of Contents
|
11
|
+
- [Installation](#install)
|
12
|
+
- [Install using gem command](#gem)
|
13
|
+
- [Install using bundler](#bundler)
|
14
|
+
- [Syntax](#syntax)
|
15
|
+
- [Finding Element](#find_element)
|
16
|
+
- [Finding Multiple Elements](#find_elements)
|
17
|
+
- [Usage](#usage)
|
18
|
+
- [Aliases](#alias)
|
19
|
+
- [Contributing](#contributing)
|
20
|
+
- [Issues](#issues)
|
21
|
+
|
22
|
+
|
23
|
+
## <a name="install"></a> Installation :eyes:
|
24
|
+
There are multiple ways in which you can install and use testnow gem.
|
25
|
+
You must have Ruby installed before you can install this gem.
|
26
|
+
|
27
|
+
### <a name="gem" /> 1. Install using gem command
|
28
|
+
Just use following command from you Terminal.
|
29
|
+
```
|
30
|
+
gem install web-object
|
31
|
+
```
|
32
|
+
|
33
|
+
### <a name="bundler" /> 2. Install using bundler
|
34
|
+
You can include it in your Gemfile and run bundle install
|
35
|
+
|
36
|
+
```
|
37
|
+
gem 'web-object'
|
38
|
+
```
|
39
|
+
then run following
|
40
|
+
```
|
41
|
+
bundle install
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
## <a name="syntax"></a> Syntax :eyes:
|
47
|
+
|
48
|
+
To use web-object, you need to extend your page class with web-object
|
49
|
+
|
50
|
+
### <a name="find_element"></a> 1. Finding Element
|
51
|
+
Syntax
|
52
|
+
element :name_of_element, {:locator_strategy => "locator value"}
|
53
|
+
or
|
54
|
+
find :name_of_element, {:locator_strategy => "locator value"}
|
55
|
+
|
56
|
+
Returns an object of WebElement
|
57
|
+
|
58
|
+
Eg:
|
59
|
+
```
|
60
|
+
element :login_email, {:id => "email"}
|
61
|
+
element :login_password, {:css => "#pwd"}
|
62
|
+
element :login_button, {:xpath => "//button[@id='signin']"}
|
63
|
+
```
|
64
|
+
or
|
65
|
+
```
|
66
|
+
find :login_email, {:id => "email"}
|
67
|
+
find :login_password, {:css => "#pwd"}
|
68
|
+
find :login_button, {:xpath => "//button[@id='signin']"}
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
### <a name="find_elements"></a> 2. Finding Multiple Element
|
73
|
+
Syntax
|
74
|
+
elements :name_of_element, {:locator_strategy => "locator value"}
|
75
|
+
or
|
76
|
+
all :name_of_element, {:locator_strategy => "locator value"}
|
77
|
+
or
|
78
|
+
element_list :name_of_element, {:locator_strategy => "locator value"}
|
79
|
+
|
80
|
+
Returns an array of WebElement objects
|
81
|
+
|
82
|
+
Eg:
|
83
|
+
```
|
84
|
+
elements :product_prices, {:id => "prices"}
|
85
|
+
elements :active_users, {:css => ".users>#active"}
|
86
|
+
```
|
87
|
+
or
|
88
|
+
```
|
89
|
+
element_list :product_prices, {:id => "prices"}
|
90
|
+
element_list :active_users, {:css => ".users>#active"}
|
91
|
+
```
|
92
|
+
or
|
93
|
+
```
|
94
|
+
all :product_prices, {:id => "prices"}
|
95
|
+
all :active_users, {:css => ".users>#active"}
|
96
|
+
```
|
97
|
+
|
98
|
+
__Note: Currently finding multiple elements will raise an exception if no element is found.
|
99
|
+
In subsequent version, there will be an option to get back an empty array if no element is found.__
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
## <a name="usage"></a> Usage :eyes:
|
104
|
+
Now as we saw how to create page objects, lets see how to put it to practical use.
|
105
|
+
|
106
|
+
```
|
107
|
+
class Login < WebObject
|
108
|
+
element :login_email, {:id => "email"}
|
109
|
+
element :login_password, {:css => "#pwd"}
|
110
|
+
element :login_button, {:xpath => "//button[@id='signin']"}
|
111
|
+
elements :active_users, {:css => ".users>#active"}
|
112
|
+
|
113
|
+
def login_to_portal(email,pwd)
|
114
|
+
login_email.send_keys(email)
|
115
|
+
login_pwd.send_keys(pwd)
|
116
|
+
login_button.click
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_active_user_count
|
120
|
+
active_users.size
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
## <a name="alias"></a> Aliases :eyes:
|
126
|
+
There is an option to use PageObject class instead of WebObject.
|
127
|
+
Eg:
|
128
|
+
``` class LoginPage < PageObject ```
|
129
|
+
|
130
|
+
Also for elements as mentioned above
|
131
|
+
for `element` there is an option to use `find` (for capybara flavor loving people)
|
132
|
+
for `elements` there is an option to use `element_list` or `all`
|
133
|
+
|
134
|
+
|
135
|
+
## <a name="contributing"></a> Contributing :eyes:
|
136
|
+
Ideas and suggestions are always always most welcome. Please fork this gem code and feel free to add any updates, suggestions etc and create a pull request.
|
137
|
+
|
138
|
+
## <a name="issues"></a> Issues :eyes:
|
139
|
+
If you face any problem related to syntax, usability, documentation then please raise an [issues](https://github.com/krupani/web-object/issues)...
|
140
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
0.1
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class WebObject
|
2
|
+
|
3
|
+
def initialize(driver)
|
4
|
+
@driver = driver
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.element(element_name, locator)
|
8
|
+
send(:define_method, element_name) do
|
9
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 0.5)
|
10
|
+
begin
|
11
|
+
wait.until { @driver.find_element(locator) }
|
12
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
13
|
+
raise "Could not find element using '#{locator.first.key}=#{locator.first.key}' strategy"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
singleton_class.send(:alias_method, :find, :element)
|
19
|
+
|
20
|
+
def self.elements(element_name, locator)
|
21
|
+
send(:define_method, element_name) do
|
22
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 0.5)
|
23
|
+
begin
|
24
|
+
wait.until { !@driver.find_elements(locator).empty? }
|
25
|
+
@driver.find_elements(locator)
|
26
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
27
|
+
raise "Could not find any elements using '#{locator.first.key}=#{locator.first.key}' strategy"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
singleton_class.send(:alias_method, :element_list, :elements)
|
33
|
+
singleton_class.send(:alias_method, :all, :elements)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
PageObject = WebObject
|
38
|
+
|
data/lib/web-object.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web-object
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kaushal Rupani
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: selenium-webdriver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: Helps in generating page object style framework using original webdriver
|
28
|
+
flavor
|
29
|
+
email:
|
30
|
+
- kushrupani@live.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENCE
|
36
|
+
- README.md
|
37
|
+
- lib/web-object.rb
|
38
|
+
- lib/web-object/version
|
39
|
+
- lib/web-object/web-object.rb
|
40
|
+
homepage: https://github.com/krupani/web_object
|
41
|
+
licenses: []
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.5.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Page Objects in Original WebDriver flavor
|
63
|
+
test_files: []
|