Skip to content

Commit

Permalink
Update all refs to time helper
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-hill committed Sep 1, 2021
1 parent 5e78a69 commit 9fd0bd2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
30 changes: 14 additions & 16 deletions features/step_definitions/element_explicit_waiting_steps.rb
@@ -1,9 +1,8 @@
# frozen_string_literal: true

When('I wait for the element that takes a while to appear') do
@overridden_wait_time = 1.6
start_time = Time.now
@test_site.slow.last_link(wait: @overridden_wait_time)
@test_site.slow.last_link(wait: upper_bound_delay)
@duration = Time.now - start_time
end

Expand All @@ -14,14 +13,14 @@
Then("an exception is raised when I wait for an element that won't appear") do
start_time = Time.now

expect { @test_site.slow.last_link(wait: 0.1) }
expect { @test_site.slow.last_link(wait: lower_bound_delay) }
.to raise_error(Capybara::ElementNotFound)

expect(Time.now - start_time).to be < 0.15
expect(Time.now - start_time).to be < time_delay
end

Then('I get an error when I wait for an element to vanish within the limit') do
expect { @test_site.home.wait_until_header_invisible(wait: 0.18) }
expect { @test_site.home.wait_until_header_invisible(wait: time_delay) }
.to raise_error(SitePrism::ElementInvisibilityTimeoutError)
end

Expand All @@ -31,7 +30,7 @@
end

Then('I can wait a variable time for elements to disappear') do
expect { @test_site.vanishing.removed_elements(wait: 0.7, count: 0) }
expect { @test_site.vanishing.removed_elements(wait: upper_bound_delay, count: 0) }
.not_to raise_error

expect(@test_site.vanishing).to have_no_removed_elements
Expand All @@ -40,10 +39,10 @@
Then('I get a timeout error when waiting for an element to become visible within the limit') do
start_time = Time.now

expect { @test_site.slow.wait_until_invisible_visible(wait: 0.18) }
expect { @test_site.slow.wait_until_invisible_visible(wait: time_delay) }
.to raise_error(SitePrism::ElementVisibilityTimeoutError)

expect(Time.now - start_time).to be_between(0.18, 0.38)
expect(Time.now - start_time).to be_between(time_delay, upper_bound_delay)
end

Then('I get a timeout error when waiting for an element with default limit') do
Expand All @@ -62,9 +61,8 @@
end

When('I wait for a specific amount of time until an element is visible') do
@overridden_wait_time = 3.5
start_time = Time.now
@test_site.slow.wait_until_last_link_visible(wait: @overridden_wait_time)
@test_site.slow.wait_until_last_link_visible(wait: upper_bound_delay)
@duration = Time.now - start_time
end

Expand All @@ -73,32 +71,32 @@
end

When('I wait a specific amount of time for a particular element to vanish') do
@test_site.vanishing.wait_until_delayed_invisible(wait: 0.75)
@test_site.vanishing.wait_until_delayed_invisible(wait: upper_bound_delay)
end

Then('I am not made to wait for the full default duration') do
expect(@duration).to be < Capybara.default_max_wait_time
end

Then('I am not made to wait for the full overridden duration') do
expect(@duration).to be < @overridden_wait_time
expect(@duration).to be < upper_bound_delay
end

Then('I can override the wait time using a Capybara.using_wait_time block') do
start_time = Time.now
Capybara.using_wait_time(0.1) do
Capybara.using_wait_time(lower_bound_delay) do
expect { @test_site.slow.last_link }
.to raise_error(Capybara::ElementNotFound)
end

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('I am not made to wait to check a nonexistent element for invisibility') do
start = Time.new
@test_site.home.wait_until_nonexistent_element_invisible(wait: 10)
@test_site.home.wait_until_nonexistent_element_invisible(wait: lower_bound_delay)

expect(Time.new - start).to be < 1
expect(Time.new - start).to be < upper_bound_delay
end

Then('an error is thrown when waiting for an element in a vanishing section') do
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/elements_steps.rb
Expand Up @@ -24,6 +24,6 @@
end

Then('I can wait a variable time and pass query parameters') do
expect { @test_site.home.list_of_people(wait: 10, minimum: 1) }
expect { @test_site.home.list_of_people(wait: upper_bound_delay, minimum: 1) }
.not_to raise_error
end
16 changes: 8 additions & 8 deletions features/step_definitions/implicit_waiting_steps.rb
Expand Up @@ -4,58 +4,58 @@
start_time = Time.now
@test_site.slow.last_link

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the slow elements are waited for') do
start_time = Time.now
@test_site.slow.even_links

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the slow section is waited for') do
start_time = Time.now
@test_site.slow.first_section

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the slow sections are waited for') do
start_time = Time.now
@test_site.slow.all_sections(count: 2)

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the boolean test for a slow element is waited for') do
start_time = Time.now

expect(@test_site.slow.has_last_link?).to be true

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the boolean test for slow elements are waited for') do
start_time = Time.now

expect(@test_site.slow.has_even_links?).to be true

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the boolean test for a slow section is waited for') do
start_time = Time.now

expect(@test_site.slow.has_first_section?).to be true

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end

Then('the boolean test for slow sections are waited for') do
start_time = Time.now

expect(@test_site.slow.has_all_sections?(count: 2)).to be true

expect(Time.now - start_time).to be_between(0.1, 0.3)
expect(Time.now - start_time).to be_between(lower_bound_delay, upper_bound_delay)
end
4 changes: 2 additions & 2 deletions features/step_definitions/navigation_steps.rb
Expand Up @@ -74,11 +74,11 @@
end

Then('I am not made to wait to continue') do
expect(@duration).to be < 0.1
expect(@duration).to be < time_delay
end

Then('I am made to wait to continue') do
expect(@duration).to be > 0.175
expect(@duration).to be > time_delay
end

Then('the page will not be marked as loaded') do
Expand Down
10 changes: 5 additions & 5 deletions features/step_definitions/section_explicit_waiting_steps.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true

When('I wait an overridden time for the section that takes a while to appear') do
@test_site.slow.first_section(wait: 0.8)
@test_site.slow.first_section(wait: upper_bound_delay)
end

When('I wait for the section that takes a while to vanish') do
@test_site.vanishing.wait_until_delayed_section_invisible
end

Then("an exception is raised when I wait for a section that won't appear") do
expect { @test_site.slow.first_section(wait: 0.05) }
expect { @test_site.slow.first_section(wait: lower_bound_delay) }
.to raise_error(Capybara::ElementNotFound)
end

Expand All @@ -23,20 +23,20 @@
end

When('I wait an overridden time for the section to vanish') do
@test_site.vanishing.wait_until_delayed_section_invisible(wait: 0.75)
@test_site.vanishing.wait_until_delayed_section_invisible(wait: upper_bound_delay)
end

Then('the slow section appears') do
expect(@test_site.slow).to have_first_section
end

Then('an error is raised when waiting an overridden time for the section to vanish') do
expect { @test_site.vanishing.wait_until_container_invisible(wait: 0.25) }
expect { @test_site.vanishing.wait_until_container_invisible(wait: time_delay) }
.to raise_error(SitePrism::ElementInvisibilityTimeoutError)
end

When('I wait for the collection of sections that takes a while to disappear') do
@test_site.vanishing.removed_sections(wait: 0.75, count: 0)
@test_site.vanishing.removed_sections(wait: upper_bound_delay, count: 0)
end

Then('the sections are no longer present') do
Expand Down
2 changes: 0 additions & 2 deletions features/support/time_helper.rb
Expand Up @@ -9,8 +9,6 @@ def upper_bound_delay
time_delay * 2
end

private

# This is set in the html script `test_site/slow.htm` in the `setTimeout` function
def time_delay
0.175
Expand Down

0 comments on commit 9fd0bd2

Please sign in to comment.