selenium-webdriver-element-decorators 0.2.0 → 0.3.0
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.
data/README.rdoc
CHANGED
@@ -1,6 +1,29 @@
|
|
1
|
-
=
|
1
|
+
= Selenium 2.0 (WebDriver) Element Decorators
|
2
2
|
|
3
|
-
|
3
|
+
This package implements a set of decorator classes for WebElement's of Selenium 2.0 (WebDriver). They add specific behavoiur to various elements of web interface that allow to write more readable automation scripts. Decorators provide all the same methods as original WebElement, but adds several new methods to deal with forms, selects, checkboxes etc.
|
4
|
+
|
5
|
+
== Sample
|
6
|
+
|
7
|
+
require ''
|
8
|
+
|
9
|
+
browser = Browser.new :firefox
|
10
|
+
browser.navigate.to 'http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_PASSWORD.html'
|
11
|
+
|
12
|
+
form = browser.find_element(:id => 'content').find_element(:tag_name => 'form')
|
13
|
+
form.populate 'realname' => 'John Smith', 'mypassword' => 'qwerty'
|
14
|
+
form.submit
|
15
|
+
|
16
|
+
browser.navigate.to 'http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html'
|
17
|
+
form = browser.find_element(:id => 'content').find_element(:tag_name => 'form')
|
18
|
+
select = form.find_element :name => 'toppings'
|
19
|
+
select.select_by_value ['greenpeppers', 'tomatoes']
|
20
|
+
form.submit
|
21
|
+
|
22
|
+
== Why Decorators?
|
23
|
+
|
24
|
+
Yes, it was possible to inject new methods right inside WebElement class. But decorator pattern looks more suitable because it allows to distinguish web elements of different kind. One may use is_a? method to check their type, and only specific methods are added to each decorator class. What would 'populate' method mean for a button, or 'append' method for an element other than text input field (or password, or text area)?
|
25
|
+
|
26
|
+
Decorators reimplement 'find_element' and 'find_elements' methods. They make an attempt to recognize type of each found element and automatically decorate it according to its type.
|
4
27
|
|
5
28
|
== Contributing to selenium-webdriver-element-decorators
|
6
29
|
|
@@ -6,13 +6,11 @@ module Selenium
|
|
6
6
|
|
7
7
|
class Browser < Element
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
if
|
11
|
-
@element =
|
12
|
-
elsif element.is_a?(Symbol) then
|
13
|
-
@element = Selenium::WebDriver.for element
|
9
|
+
def initialize *args
|
10
|
+
if args.length == 1 and args[1].is_a? Selenium::WebDriver::Driver
|
11
|
+
@element = args[1]
|
14
12
|
else
|
15
|
-
|
13
|
+
@element = Selenium::WebDriver.for *args
|
16
14
|
end
|
17
15
|
@browser = @element
|
18
16
|
end
|
@@ -59,9 +59,12 @@ module Selenium
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def send_keys *args
|
62
|
+
# ----- workaround -----
|
63
|
+
# see http://code.google.com/p/selenium/issues/detail?id=440
|
62
64
|
if @browser.browser == :chrome
|
63
65
|
@element.click
|
64
66
|
end
|
67
|
+
# ----- workaround -----
|
65
68
|
@element.send_keys *args
|
66
69
|
end
|
67
70
|
|
data/spec/form_populate_spec.rb
CHANGED
@@ -7,37 +7,36 @@ describe "Form" do
|
|
7
7
|
include Aux
|
8
8
|
|
9
9
|
it "should populate textbox" do
|
10
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/index_famsupp_1.html',
|
10
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/index_famsupp_1.html', {'color' => 'red'}
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should populate multiple textboxes" do
|
14
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_PASSWORD.html',
|
14
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_PASSWORD.html', {'realname' => 'John Smith', 'mypassword' => 'qwerty'}
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should populate checkboxes" do
|
18
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_CHECKBOX.html',
|
18
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_CHECKBOX.html', {'mushrooms' => true, 'greenpeppers' => false, 'olives' => true, 'onions' => false}, 1
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should populate textarea" do
|
22
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_TEXTAREA.html',
|
22
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_TEXTAREA.html',{ 'comments' => 'bla bla bla'}
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should populate select" do
|
26
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_onFocus.html',
|
26
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_onFocus.html', { 'size' => 'm', 'phone' => '+0 123 4567890' }
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should populate multiple select" do
|
30
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html',
|
30
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html', { 'toppings' => ['greenpeppers', 'tomatoes'] }
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should populate mixed fields" do
|
34
|
-
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_TABINDEX.html',
|
35
|
-
{ 'realname' => 'John Smith', 'email' => 'smith@example.com', 'dep' => 'dev', }
|
34
|
+
populate_and_check 'http://www.htmlcodetutorial.com/forms/_SELECT_TABINDEX.html', { 'realname' => 'John Smith', 'email' => 'smith@example.com', 'dep' => 'dev', }
|
36
35
|
end
|
37
36
|
|
38
|
-
def populate_and_check url,
|
37
|
+
def populate_and_check url, data, form_no = 0
|
39
38
|
@browser.navigate.to url
|
40
|
-
form = @browser.find_elements(:tag_name => 'form')[form_no]
|
39
|
+
form = @browser.find_element(:id => 'content').find_elements(:tag_name => 'form')[form_no]
|
41
40
|
form.populate(data).submit
|
42
41
|
expect_result data
|
43
42
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexei Barantsev
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-18 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -175,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
175
|
requirements:
|
176
176
|
- - ">="
|
177
177
|
- !ruby/object:Gem::Version
|
178
|
-
hash:
|
178
|
+
hash: -945287555
|
179
179
|
segments:
|
180
180
|
- 0
|
181
181
|
version: "0"
|