Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent AePageObjects::Collection#size from waiting #207

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/ae_page_objects/elements/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ def each
end

def size
node.all(:xpath, item_xpath, options.merge(wait: false)).size
#
# In some cases when #size is called while the DOM is updating, Capybara
# will catch (and swallow) underlying exceptions such as
# `Selenium::WebDriver::Error::StaleElementReferenceError`.
# When this happens it will wait up to the max wait time, which can cause
# issues for `AePageObjects.wait_until` blocks.
#
# To prevent this issue the #all and #size calls are made with the Capybara
# wait time set to 0.
#
Capybara.using_wait_time(0) do
node.all(:xpath, item_xpath, options).size
end
end

def last
Expand Down
8 changes: 4 additions & 4 deletions test/unit/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_locator_options__blank
magazine.stubs(:item_xpath).returns('item_xpath')

bullet1_stub = mock(:allow_reload!)
magazine_node.expects(:all).with(:xpath, 'item_xpath', wait: false).returns([bullet1_stub])
magazine_node.expects(:all).with(:xpath, 'item_xpath', {}).returns([bullet1_stub])
magazine_node.expects(:first).with(:xpath, '(item_xpath)[1]', minimum: 0).returns(bullet1_stub)
assert_equal bullet1_stub, magazine.at(0).node
end
Expand All @@ -115,7 +115,7 @@ def test_locator_options__present
magazine.stubs(:item_xpath).returns("item_xpath")

bullet1_stub = mock(:allow_reload!)
magazine_node.expects(:all).with(:xpath, 'item_xpath', { capybara: 'options', wait: false }).returns([bullet1_stub])
magazine_node.expects(:all).with(:xpath, 'item_xpath', { capybara: 'options' }).returns([bullet1_stub])
magazine_node.expects(:first).with(:xpath, "(item_xpath)[1]", { capybara: 'options', minimum: 0 }).returns(bullet1_stub)
assert_equal bullet1_stub, magazine.at(0).node
end
Expand All @@ -136,7 +136,7 @@ def test_empty
magazine = clip.new(parent, :name => "18_holder")
magazine.stubs(:item_xpath).returns("item_xpath")

magazine_node.stubs(:all).with(:xpath, "item_xpath", wait: false).returns([])
magazine_node.stubs(:all).with(:xpath, "item_xpath", {}).returns([])

assert_equal 0, magazine.size

Expand Down Expand Up @@ -169,7 +169,7 @@ def test_non_empty

bullet1_stub = stub(:allow_reload!)
bullet2_stub = stub(:allow_reload!)
magazine_node.stubs(:all).with(:xpath, "item_xpath", wait: false).returns([bullet1_stub, bullet2_stub])
magazine_node.stubs(:all).with(:xpath, "item_xpath", {}).returns([bullet1_stub, bullet2_stub])

assert_equal 2, magazine.size

Expand Down
24 changes: 12 additions & 12 deletions test/unit/dsl/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_collection__no_is__no_contains__block
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, AePageObjects::Element, first_owner_page_object)

Expand Down Expand Up @@ -61,7 +61,7 @@ def test_collection__is__no_contains__block

first_owner_page_object = stub(:allow_reload!)

previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, previous_owners_class.item_class, first_owner_page_object)

Expand Down Expand Up @@ -97,7 +97,7 @@ def test_collection__is__no_contains__block__no_item_class

first_owner_page_object = stub(:allow_reload!)

previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, previous_owners_class.item_class, first_owner_page_object)

Expand Down Expand Up @@ -135,7 +135,7 @@ def test_collection__is__no_contains__no_block
previous_owners = verify_element_on_parent(jon, :previous_owners, previous_owners_class, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -173,7 +173,7 @@ def test_collection__is__contains__no_block__same_item_class
previous_owners = verify_element_on_parent(jon, :previous_owners, previous_owners_class, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -209,7 +209,7 @@ def test_collection__is__contains__no_block__different_item_class
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, previous_owners_class, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -243,7 +243,7 @@ def test_collection__no_is__contains__no_block
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -279,7 +279,7 @@ def test_collection__no_is__contains__block
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -322,7 +322,7 @@ def test_collection__is__contains__block
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, previous_owners_class, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, previous_owner_class, first_owner_page_object)

Expand Down Expand Up @@ -350,7 +350,7 @@ def test_collection__no_is__no_contains__no_block
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element(previous_owners, 0, AePageObjects::Element, first_owner_page_object)
end
Expand All @@ -375,7 +375,7 @@ def test_collection__locator
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, AePageObjects::Element, first_owner_page_object)

Expand Down Expand Up @@ -410,7 +410,7 @@ def test_nested_element__locator__proc
previous_owners = verify_element_on_parent_with_intermediary_class(jon, :previous_owners, AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = stub(:allow_reload!)
previous_owners_page_object.expects(:all).with(:xpath, ".//*", wait: false).returns([first_owner_page_object])
previous_owners_page_object.expects(:all).with(:xpath, ".//*", {}).returns([first_owner_page_object])
previous_owners_page_object.expects(:first).with(:xpath, "(.//*)[1]", minimum: 0).returns(first_owner_page_object)
first_owner = verify_item_element_with_intermediary_class(previous_owners, 0, AePageObjects::Element, first_owner_page_object)

Expand Down