From b4190e0c75f0c179558ba018e0dd746456a70391 Mon Sep 17 00:00:00 2001 From: Libo Liu Date: Fri, 17 Sep 2021 17:12:44 -0700 Subject: [PATCH 1/3] 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 --- lib/ae_page_objects.rb | 1 + lib/ae_page_objects/elements/textarea.rb | 13 +++++++++++++ test/unit/dsl/element_test.rb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 lib/ae_page_objects/elements/textarea.rb diff --git a/lib/ae_page_objects.rb b/lib/ae_page_objects.rb index db256eb2..553e7097 100644 --- a/lib/ae_page_objects.rb +++ b/lib/ae_page_objects.rb @@ -14,6 +14,7 @@ module AePageObjects autoload :Form, 'ae_page_objects/elements/form' autoload :Select, 'ae_page_objects/elements/select' autoload :Checkbox, 'ae_page_objects/elements/checkbox' + autoload :Textarea, 'ae_page_objects/elements/textarea' class << self attr_accessor :default_router diff --git a/lib/ae_page_objects/elements/textarea.rb b/lib/ae_page_objects/elements/textarea.rb new file mode 100644 index 00000000..a1a215f1 --- /dev/null +++ b/lib/ae_page_objects/elements/textarea.rb @@ -0,0 +1,13 @@ +module AePageObjects + class Textarea < Element + def set(value) + node.set(value, { clear: clear_keys }) + end + + private + + def clear_keys + [[:command, 'a'], :backspace] + end + end +end diff --git a/test/unit/dsl/element_test.rb b/test/unit/dsl/element_test.rb index b4a9b7a4..65dbe39f 100644 --- a/test/unit/dsl/element_test.rb +++ b/test/unit/dsl/element_test.rb @@ -88,6 +88,23 @@ def test_element__is__checkbox verify_element_on_parent(jon, :kind, AePageObjects::Checkbox, kind_page_object) end + def test_element__is__textarea + kitty = Class.new(AePageObjects::Document) do + element :description, is: AePageObjects::Textarea + end + + assert kitty.method_defined?(:description) + assert_equal [:description], kitty.element_attributes.keys + + stub_current_window + + jon = kitty.new + + description_page_object = stub(:allow_reload!) + capybara_stub.session.expects(:first).with("#description", minimum: 0).returns(description_page_object) + verify_element_on_parent(jon, :description, AePageObjects::Textarea, description_page_object) + end + def test_element__is__special_widget special_widget = Class.new(AePageObjects::Element) From f7d203228afab6611cb1fcbe2610737d19fadc00 Mon Sep 17 00:00:00 2001 From: Libo Liu Date: Fri, 1 Oct 2021 13:13:36 -0700 Subject: [PATCH 2/3] Bump to 5.1.0.pre1 --- lib/ae_page_objects/version.rb | 2 +- test/test_apps/shared/engines/forum/lib/forum/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ae_page_objects/version.rb b/lib/ae_page_objects/version.rb index 282122dc..e98b2a97 100644 --- a/lib/ae_page_objects/version.rb +++ b/lib/ae_page_objects/version.rb @@ -1,3 +1,3 @@ module AePageObjects - VERSION = '5.0.0'.freeze + VERSION = '5.1.0.pre1'.freeze end diff --git a/test/test_apps/shared/engines/forum/lib/forum/version.rb b/test/test_apps/shared/engines/forum/lib/forum/version.rb index 9c4eac95..a1463708 100644 --- a/test/test_apps/shared/engines/forum/lib/forum/version.rb +++ b/test/test_apps/shared/engines/forum/lib/forum/version.rb @@ -1,3 +1,3 @@ module Forum - VERSION = "4.1.0" + VERSION = "5.1.0.pre1" end From fe2634426e9e58e39e0697cc963059de70fd6667 Mon Sep 17 00:00:00 2001 From: Libo Liu Date: Fri, 3 Jun 2022 14:14:41 -0700 Subject: [PATCH 3/3] Bump to 5.1.0.pre.2 --- lib/ae_page_objects/version.rb | 2 +- test/test_apps/shared/engines/forum/lib/forum/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ae_page_objects/version.rb b/lib/ae_page_objects/version.rb index e98b2a97..123ed35b 100644 --- a/lib/ae_page_objects/version.rb +++ b/lib/ae_page_objects/version.rb @@ -1,3 +1,3 @@ module AePageObjects - VERSION = '5.1.0.pre1'.freeze + VERSION = '5.1.0.pre.2'.freeze end diff --git a/test/test_apps/shared/engines/forum/lib/forum/version.rb b/test/test_apps/shared/engines/forum/lib/forum/version.rb index a1463708..6fb778d4 100644 --- a/test/test_apps/shared/engines/forum/lib/forum/version.rb +++ b/test/test_apps/shared/engines/forum/lib/forum/version.rb @@ -1,3 +1,3 @@ module Forum - VERSION = "5.1.0.pre1" + VERSION = "5.1.0.pre.2" end