Skip to content

Commit

Permalink
Merge pull request #130 from sharetribe/web-step-improvement
Browse files Browse the repository at this point in the history
Improve test stability
  • Loading branch information
bladealslayer committed Feb 18, 2022
2 parents c4bd52a + a41f102 commit 648b584
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -18,6 +18,7 @@ jobs:
BUNDLE_PATH: vendor/bundle
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
RUBYOPT: "-W0"
- image: mysql:5.7.27
environment:
MYSQL_ROOT_PASSWORD=very-secret
Expand Down
6 changes: 2 additions & 4 deletions features/admin2/admin_add_listing_fields.feature
Expand Up @@ -24,8 +24,8 @@ Feature: Admin add a listing fields
And I fill in "selector_label[en]" with "Appartment"
And I fill in "selector_label[fi]" with "Asunto"
And I press "Save option"
Then I should see "Appartment" within "#optionsList"
And I press "Add the listing field"
And I wait for 3 seconds
Then I should see "House type" within ".custom-field-title"

@javascript
Expand All @@ -48,7 +48,6 @@ Feature: Admin add a listing fields
Then I set numeric field min value to 0
And I set numeric field max value to 100
And I press "Add the listing field"
And I wait for 3 seconds
Then I should see "Area" within ".custom-field-title"

@javascript
Expand All @@ -66,8 +65,8 @@ Feature: Admin add a listing fields
And I fill in "selector_label[en]" with "Appartment"
And I fill in "selector_label[fi]" with "Asunto"
And I press "Save option"
Then I should see "Appartment" within "#optionsList"
And I press "Add the listing field"
And I wait for 3 seconds
Then I should see "Checkbox type" within ".custom-field-title"

@javascript
Expand All @@ -78,5 +77,4 @@ Feature: Admin add a listing fields
And I fill in "custom_field[name_attributes][fi]" with "Talon Area"
And I toggle category "Spaces"
And I press "Add the listing field"
And I wait for 3 seconds
Then I should see "Area Date" within ".custom-field-title"
6 changes: 2 additions & 4 deletions features/admin2/admin_add_user_fields.feature
Expand Up @@ -19,8 +19,8 @@ Feature: Admin add a listing fields
And I fill in "selector_label[en]" with "Appartment"
And I fill in "selector_label[fi]" with "Asunto"
And I press "Save option"
Then I should see "Appartment" within "#optionsList"
And I press submit
And I wait for 3 seconds
Then I should see "House type" within ".custom-field-title"

@javascript
Expand All @@ -41,7 +41,6 @@ Feature: Admin add a listing fields
Then I set numeric field min value to 0
And I set numeric field max value to 100
And I press submit
And I wait for 3 seconds
Then I should see "Area" within ".custom-field-title"

@javascript
Expand All @@ -58,8 +57,8 @@ Feature: Admin add a listing fields
And I fill in "selector_label[en]" with "Appartment"
And I fill in "selector_label[fi]" with "Asunto"
And I press "Save option"
Then I should see "Appartment" within "#optionsList"
And I press submit
And I wait for 3 seconds
Then I should see "Checkbox type" within ".custom-field-title"

@javascript
Expand All @@ -69,5 +68,4 @@ Feature: Admin add a listing fields
And I fill in "custom_field[name_attributes][en]" with "Area Date"
And I fill in "custom_field[name_attributes][fi]" with "Talon Area"
And I press submit
And I wait for 3 seconds
Then I should see "Area Date" within ".custom-field-title"
4 changes: 3 additions & 1 deletion features/listings/user_comments_a_listing.feature
Expand Up @@ -73,8 +73,10 @@ Feature: User comments a listing
And there is a listing with title "Massage" from "kassi_testperson1" with category "Services" and with listing shape "Requesting"
And I am logged in as "kassi_testperson2"
When I follow "Massage"
Then I should see "Public discussion" within "#comments"
And I have "click" event handler on "#send_comment_button"
And I press "Send comment"
Then I should see "This field is required."
Then I should see "This field is required." within "#new_comment"

@javascript
Scenario: Trying to add a comment without logging in
Expand Down
36 changes: 36 additions & 0 deletions features/step_definitions/web_steps.rb
Expand Up @@ -59,6 +59,29 @@ def find_field_with_value(value)
end
World(FindHelpers)

module AsyncHelpers

# Run block, which is expected to contain some expectations until all
# expectations are met or until timeout occurs. Useful when the expectation
# depends on some asynchronous behavior.
def eventually(timeout: 5, &block)
end_t = Time.now + timeout

loop do
result = block.call
rescue RSpec::Expectations::ExpectationNotMetError => e
if Time.now >= end_t
raise e
else
sleep 0.1
end
else
return result
end
end
end
World(AsyncHelpers)

Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
Expand Down Expand Up @@ -201,6 +224,12 @@ def find_field_with_value(value)
with_scope(selector) do
expect(page).to have_content(text, normalize_ws: true)
end
rescue RSpec::Expectations::ExpectationNotMetError
puts "Timeout waiting for content '#{text}' within '#{selector}'. Will wait 10s and retry one more time."
sleep 10
with_scope(selector) do
expect(page).to have_content(text, normalize_ws: true)
end
end

Then /^Page should contain "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
Expand Down Expand Up @@ -354,6 +383,13 @@ def find_field_with_value(value)
find(selector).hover
end

When /^I have "([^"]*)" event handler on "([^"]*)"/ do |event, selector|
eventually do
events = page.evaluate_script("$._data($(\"#{selector}\")[0], \"events\")")
expect(events).to include(event)
end
end

Then(/^"([^"]*)" should have CSS property "([^"]*)" with value "([^"]*)"$/) do |selector, property, value|
actual_value = page.evaluate_script("$('#{selector}').css('#{property}')");
expect(actual_value).to be_eql(value)
Expand Down
2 changes: 1 addition & 1 deletion features/support/hapybara.rb
Expand Up @@ -29,6 +29,6 @@
end


Capybara.default_max_wait_time = 20
Capybara.default_max_wait_time = 30
Capybara.ignore_hidden_elements = true
Capybara.default_selector = :css

0 comments on commit 648b584

Please sign in to comment.