diff --git a/features/elements.feature b/features/elements.feature index 4fb82f7..70338d5 100644 --- a/features/elements.feature +++ b/features/elements.feature @@ -11,6 +11,7 @@ Feature: Interaction with groups of elements Scenario: Get groups of elements from within a section Then I can see individual people in the people list + And I can see optioned individual people in the people list Scenario: Page with no elements Then the page does not have a group of elements diff --git a/features/step_definitions/elements_steps.rb b/features/step_definitions/elements_steps.rb index 58fdd30..cdb051d 100644 --- a/features/step_definitions/elements_steps.rb +++ b/features/step_definitions/elements_steps.rb @@ -16,6 +16,12 @@ expect(@test_site.home.people).to have_individuals(count: 4) end +Then('I can see optioned individual people in the people list') do + expect(@test_site.home.people.optioned_individuals.size).to eq(4) + + expect(@test_site.home.people).to have_optioned_individuals(count: 4) +end + Then('I can wait a variable time and pass specific parameters') do @test_site.home.wait_for_lots_of_links(0.1, count: 2) Capybara.using_wait_time(0.3) do diff --git a/features/step_definitions/section_steps.rb b/features/step_definitions/section_steps.rb index f87570f..ca7f265 100644 --- a/features/step_definitions/section_steps.rb +++ b/features/step_definitions/section_steps.rb @@ -116,7 +116,7 @@ end Then("I can see a section's full text") do - expect(@test_site.home.people.text).to eq('People person 1 person 2 person 3 person 4') + expect(@test_site.home.people.text).to eq('People person 1 person 2 person 3 person 4 object 1') expect(@test_site.home.container_with_element.text).to eq('This will be removed when you click submit above') end diff --git a/lib/site_prism/element_container.rb b/lib/site_prism/element_container.rb index cc2f674..37302d0 100644 --- a/lib/site_prism/element_container.rb +++ b/lib/site_prism/element_container.rb @@ -8,7 +8,7 @@ def element(element_name, *find_args) build(element_name, *find_args) do define_method(element_name.to_s) do |*runtime_args, &element_block| self.class.raise_if_block(self, element_name.to_s, !element_block.nil?) - find_first(*find_args, *runtime_args) + find_first(*self.class.merge_args(find_args, runtime_args)) end end end @@ -17,7 +17,7 @@ def elements(collection_name, *find_args) build(collection_name, *find_args) do define_method(collection_name.to_s) do |*runtime_args, &element_block| self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?) - find_all(*find_args, *runtime_args) + find_all(*self.class.merge_args(find_args, runtime_args)) end end end @@ -31,7 +31,7 @@ def section(section_name, *args, &block) section_class, find_args = extract_section_options(args, &block) build(section_name, *find_args) do define_method section_name do |*runtime_args, &runtime_block| - section_class.new self, find_first(*find_args, *runtime_args), &runtime_block + section_class.new self, find_first(*self.class.merge_args(find_args, runtime_args)), &runtime_block end end end @@ -41,7 +41,7 @@ def sections(section_collection_name, *args, &block) build(section_collection_name, *find_args) do define_method(section_collection_name) do |*runtime_args, &element_block| self.class.raise_if_block(self, section_collection_name.to_s, !element_block.nil?) - find_all(*find_args, *runtime_args).map do |element| + find_all(*self.class.merge_args(find_args, runtime_args)).map do |element| section_class.new(self, element) end end @@ -85,6 +85,16 @@ def raise_wait_for_no_if_failed(obj, name, timeout, failed) "Timed out after #{timeout}s waiting for no #{obj.class}##{name}" end + def merge_args(find_args, runtime_args, override_options = {}) + find_args = find_args.dup + runtime_args = runtime_args.dup + options = {} + options.merge!(find_args.pop) if find_args.last.is_a? Hash + options.merge!(runtime_args.pop) if runtime_args.last.is_a? Hash + options.merge!(override_options) + [*find_args, *runtime_args, options] + end + private def build(name, *find_args) @@ -127,7 +137,7 @@ def create_existence_checker(element_name, *find_args) define_method(method_name) do |*runtime_args| wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0 Capybara.using_wait_time(wait_time) do - element_exists?(*find_args, *runtime_args) + element_exists?(*self.class.merge_args(find_args, runtime_args)) end end end @@ -139,7 +149,7 @@ def create_nonexistence_checker(element_name, *find_args) define_method(method_name) do |*runtime_args| wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0 Capybara.using_wait_time(wait_time) do - element_does_not_exist?(*find_args, *runtime_args) + element_does_not_exist?(*self.class.merge_args(find_args, runtime_args)) end end end @@ -150,7 +160,7 @@ def create_waiter(element_name, *find_args) create_helper_method(method_name, *find_args) do define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args| result = Capybara.using_wait_time(timeout) do - element_exists?(*find_args, *runtime_args) + element_exists?(*self.class.merge_args(find_args, runtime_args)) end self.class.raise_wait_for_if_failed(self, element_name.to_s, timeout, !result) result @@ -163,7 +173,7 @@ def create_nonexistence_waiter(element_name, *find_args) create_helper_method(method_name, *find_args) do define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args| result = Capybara.using_wait_time(timeout) do - element_does_not_exist?(*find_args, *runtime_args) + element_does_not_exist?(*self.class.merge_args(find_args, runtime_args)) end self.class.raise_wait_for_no_if_failed(self, element_name.to_s, timeout, !result) result @@ -175,10 +185,8 @@ def create_visibility_waiter(element_name, *find_args) method_name = "wait_until_#{element_name}_visible" create_helper_method(method_name, *find_args) do define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args| - Timeout.timeout(timeout, SitePrism::TimeOutWaitingForElementVisibility) do - Capybara.using_wait_time 0 do - sleep 0.05 until element_exists?(*find_args, *runtime_args, visible: true) - end + unless element_exists?(*self.class.merge_args(find_args, runtime_args, visible: true, wait: timeout)) + raise SitePrism::TimeOutWaitingForElementVisibility end end end @@ -188,10 +196,8 @@ def create_invisibility_waiter(element_name, *find_args) method_name = "wait_until_#{element_name}_invisible" create_helper_method(method_name, *find_args) do define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args| - Timeout.timeout(timeout, SitePrism::TimeOutWaitingForElementInvisibility) do - Capybara.using_wait_time 0 do - sleep 0.05 while element_exists?(*find_args, *runtime_args, visible: true) - end + unless element_does_not_exist?(*self.class.merge_args(find_args, runtime_args, visible: true, wait: timeout)) + raise SitePrism::TimeOutWaitingForElementInvisibility end end end diff --git a/test_site/html/home.htm b/test_site/html/home.htm index fa12b47..573a0d1 100644 --- a/test_site/html/home.htm +++ b/test_site/html/home.htm @@ -56,6 +56,7 @@