web-object 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b27cc7c593f89557072eb0230513efa244302191
4
- data.tar.gz: 9835f0fa4aa79272ad5365bbcff74def017e570a
3
+ metadata.gz: fd547488b2887d00bb588a8db5ff4944bb20d515
4
+ data.tar.gz: 15c86935df1d98dc89f594732a6f43f625ffe4dd
5
5
  SHA512:
6
- metadata.gz: bc1dd0cabf5605ff0915436b590e13a9e37a58babdd3d41cac1ea4cdab27df275e9d540762fa966ee749f1149c55d8d596e6ba984f8c302275f0b4efc932a974
7
- data.tar.gz: 0e0c2175d5c9046b235bb93eca9d42340ae6184e30abaca4500fc87c53e58aa83e266f3ff23a1573df0e123d47e5b02eb7d1604850fb2b7693c8fa34dbfb2122
6
+ metadata.gz: 96df1f4533a1130f7e3f5ba0608537182e8dd848f5c38b738be6f6ba9a5e69285737cb1d9623d3a1b188a50cf3f7ca99a5ff3ce12ddb951a24876cad3965eb8c
7
+ data.tar.gz: 6aaa349dc3b5fa0a4f25cb505a9c044a0ca89a396e28116fa000bb4e30f29054f7d445000acee9aad460ef4bbf6ae49cdc53cfd35ef7ee4c435377cfd5c9952e
data/LICENCE CHANGED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016-2017 Kaushal Rupani
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- #web-object
1
+ # web-object
2
2
 
3
3
  Create page-object style test framework using original webdriver flavor.
4
4
  Now what does original webdriver flavor is, it simply means, no additional wrappers, no additional syntax.
@@ -13,7 +13,8 @@ commands on it like send_keys, click, displayed? .. and so on...
13
13
  - [Install using bundler](#bundler)
14
14
  - [Syntax](#syntax)
15
15
  - [Finding Element](#find_element)
16
- - [Finding Multiple Elements](#find_elements)
16
+ - [Finding Multiple Elements](#find_elements)
17
+ - [Syntax Summary](#summary)
17
18
  - [Usage](#usage)
18
19
  - [Aliases](#alias)
19
20
  - [Contributing](#contributing)
@@ -21,7 +22,7 @@ commands on it like send_keys, click, displayed? .. and so on...
21
22
 
22
23
 
23
24
  ## <a name="install"></a> Installation :eyes:
24
- There are multiple ways in which you can install and use testnow gem.
25
+ There are multiple ways in which you can install and use web-object gem.
25
26
  You must have Ruby installed before you can install this gem.
26
27
 
27
28
  ### <a name="gem" /> 1. Install using gem command
@@ -51,10 +52,9 @@ To use web-object, you need to extend your page class with web-object
51
52
  Syntax
52
53
  element :name_of_element, {:locator_strategy => "locator value"}
53
54
  or
54
- find :name_of_element, {:locator_strategy => "locator value"}
55
-
56
- Returns an object of WebElement
57
-
55
+ find :name_of_element, {:locator_strategy => "locator value"}, error=false
56
+
57
+
58
58
  Eg:
59
59
  ```
60
60
  element :login_email, {:id => "email"}
@@ -68,21 +68,34 @@ find :login_password, {:css => "#pwd"}
68
68
  find :login_button, {:xpath => "//button[@id='signin']"}
69
69
  ```
70
70
 
71
+ Returns an object of WebElement.
72
+ Raise an exception by default if element is not found.
73
+ Will return Boolean false if error=false parameter is explicitly passed and element is not found.
74
+
75
+ Eg of error handling as mentioned above:
76
+ ```
77
+ 1) element :login_button, {:id => 'signIn'}
78
+ 2) element :profile_link, {:css => '.user_profile'}, error=false
79
+
80
+ # Example 1 will raise element not found exception if element not found on the page
81
+ # Example 2 will just return a Boolean false if element not found on the page
82
+
83
+ ```
84
+
85
+
71
86
 
72
87
  ### <a name="find_elements"></a> 2. Finding Multiple Element
73
88
  Syntax
74
89
  elements :name_of_element, {:locator_strategy => "locator value"}
75
90
  or
76
- all :name_of_element, {:locator_strategy => "locator value"}
91
+ all :name_of_element, {:locator_strategy => "locator value"}, error=true
77
92
  or
78
93
  element_list :name_of_element, {:locator_strategy => "locator value"}
79
94
 
80
- Returns an array of WebElement objects
81
-
82
95
  Eg:
83
96
  ```
84
97
  elements :product_prices, {:id => "prices"}
85
- elements :active_users, {:css => ".users>#active"}
98
+ elements :active_users, {:css => ".users>#active"}, error=true
86
99
  ```
87
100
  or
88
101
  ```
@@ -95,10 +108,30 @@ all :product_prices, {:id => "prices"}
95
108
  all :active_users, {:css => ".users>#active"}
96
109
  ```
97
110
 
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.__
111
+ Returns an array of WebElement objects.
112
+ Return an empty array in element is not found by default.
113
+ Will raise an error if error=true parameter explicitly passed and element is not found.
100
114
 
115
+
116
+ Eg of error handling as mentioned above:
117
+ ```
118
+ 1) elements :names, {:id => 'names'}, error=true
119
+ 2) elements :header_tabs, {:css => '.menu-item'}
120
+
121
+ # Example 1 will raise element not found exception if element not found on the page
122
+ # Example 2 will just return an empty array if element not found on the page
123
+
124
+ ```
101
125
 
126
+ ### <a name="summary"></a> 3. Syntax Summary :
127
+ * error parameter is completely optional and web-object will continue to work as before.
128
+ * Default behaviour will now match the same as webdriver.
129
+ * __Finding single element will raise an exception by default if element not found on the page.__
130
+ * __Finding multiple elements will return a blank array by default if element not found on the page.__
131
+ * error parameter is used only to reverse the natural default behaviour.
132
+ * __Finding single element will return Boolean false if error paramter is sent as false and element not found on the page.__
133
+ * __Finding multiple elements will raise exception if error paramter is sent as true and element not found on the page.__
134
+
102
135
 
103
136
  ## <a name="usage"></a> Usage :eyes:
104
137
  Now as we saw how to create page objects, lets see how to put it to practical use.
@@ -1,2 +1,19 @@
1
1
  require 'selenium-webdriver'
2
- require 'web-object/web-object'
2
+ require 'web-object/element'
3
+ require 'web-object/elements'
4
+
5
+ class WebObject
6
+ include Element
7
+ include Elements
8
+
9
+ def initialize(driver)
10
+ @driver = driver
11
+ end
12
+
13
+ singleton_class.send(:alias_method, :find, :element)
14
+ singleton_class.send(:alias_method, :element_list, :elements)
15
+ singleton_class.send(:alias_method, :all, :elements)
16
+
17
+ end
18
+
19
+ PageObject = WebObject
@@ -0,0 +1,34 @@
1
+ module Element
2
+
3
+ def self.included(base)
4
+ base.extend FindElement
5
+ end
6
+
7
+ module FindElement
8
+
9
+ # @method element(element_name, locator, error=true)
10
+ # @param element_name [:Symbol]
11
+ # @param locator [Hash]
12
+ # @param error [Boolean] -- default true
13
+ # @return [Selenium::WebDriver::Element]
14
+ # @return [Boolean false] -- if element not found and error parameter = false
15
+
16
+ def element(element_name, locator, error=true)
17
+ send(:define_method, element_name) do
18
+ wait = Selenium::WebDriver::Wait.new(:timeout => 0.5)
19
+ begin
20
+ wait.until { @driver.find_element(locator) }
21
+ rescue Selenium::WebDriver::Error::TimeOutError
22
+ if error
23
+ raise "Could not find element using '#{locator.first.key}=#{locator.first.key}' strategy"
24
+ else
25
+ return false
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,34 @@
1
+ module Elements
2
+
3
+ def self.included(base)
4
+ base.extend FindElements
5
+ end
6
+
7
+ module FindElements
8
+
9
+ # @method element(element_name, locator, error=false)
10
+ # @param element_name [:Symbol]
11
+ # @param locator [Hash]
12
+ # @param error [Boolean] - default false
13
+ # @return [Selenium::WebDriver::Element]
14
+ # @return [empty Array] -- if element not found and error parameter = false
15
+
16
+ def elements(element_name, locator, error=false)
17
+ send(:define_method, element_name) do
18
+ wait = Selenium::WebDriver::Wait.new(:timeout => 0.5)
19
+ begin
20
+ wait.until { !@driver.find_elements(locator).empty? }
21
+ @driver.find_elements(locator)
22
+ rescue Selenium::WebDriver::Error::TimeOutError
23
+ if error
24
+ raise "Could not find any elements using '#{locator.first.key}=#{locator.first.key}' strategy"
25
+ else
26
+ return []
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -1 +1 @@
1
- 0.1
1
+ 0.2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-object
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaushal Rupani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -35,10 +35,12 @@ files:
35
35
  - LICENCE
36
36
  - README.md
37
37
  - lib/web-object.rb
38
+ - lib/web-object/element.rb
39
+ - lib/web-object/elements.rb
38
40
  - lib/web-object/version
39
- - lib/web-object/web-object.rb
40
41
  homepage: https://github.com/krupani/web_object
41
- licenses: []
42
+ licenses:
43
+ - MIT
42
44
  metadata: {}
43
45
  post_install_message:
44
46
  rdoc_options: []
@@ -1,38 +0,0 @@
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
-