Skip to content

Commit b4190e0

Browse files
author
Libo Liu
committed
Add a textarea element
Add new clear options to set a value for textareas. By default, in chrome selenium test, when `set` value of text-related node, it would only prepend the first line. As the capybara chrome node: it only send a space and a backspace to clear the text. https://bit.ly/3zpJZYJ However, this will **ONLY** clear the first line of the textarea. In this commit, we added a Textarea element to override the `set` method to clear all text in the textarea. This is following the set definition in the Capybara: it says we could use `[[:command, 'a'], :backspace]` to clear all text. Github capybara/selenium/node.rb#L55: https://bit.ly/3CtlTP3 It works both for firefox and chrome
1 parent 8cd0aa1 commit b4190e0

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/ae_page_objects.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module AePageObjects
1414
autoload :Form, 'ae_page_objects/elements/form'
1515
autoload :Select, 'ae_page_objects/elements/select'
1616
autoload :Checkbox, 'ae_page_objects/elements/checkbox'
17+
autoload :Textarea, 'ae_page_objects/elements/textarea'
1718

1819
class << self
1920
attr_accessor :default_router
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module AePageObjects
2+
class Textarea < Element
3+
def set(value)
4+
node.set(value, { clear: clear_keys })
5+
end
6+
7+
private
8+
9+
def clear_keys
10+
[[:command, 'a'], :backspace]
11+
end
12+
end
13+
end

test/unit/dsl/element_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ def test_element__is__checkbox
8888
verify_element_on_parent(jon, :kind, AePageObjects::Checkbox, kind_page_object)
8989
end
9090

91+
def test_element__is__textarea
92+
kitty = Class.new(AePageObjects::Document) do
93+
element :description, is: AePageObjects::Textarea
94+
end
95+
96+
assert kitty.method_defined?(:description)
97+
assert_equal [:description], kitty.element_attributes.keys
98+
99+
stub_current_window
100+
101+
jon = kitty.new
102+
103+
description_page_object = stub(:allow_reload!)
104+
capybara_stub.session.expects(:first).with("#description", minimum: 0).returns(description_page_object)
105+
verify_element_on_parent(jon, :description, AePageObjects::Textarea, description_page_object)
106+
end
107+
91108
def test_element__is__special_widget
92109
special_widget = Class.new(AePageObjects::Element)
93110

0 commit comments

Comments
 (0)