diff --git a/features/settings_page/profile.feature b/features/settings_page/profile.feature index 6ba58a9b2..b8e1e1dff 100644 --- a/features/settings_page/profile.feature +++ b/features/settings_page/profile.feature @@ -23,7 +23,7 @@ Scenario: Unsuccessful avatar image upload, file is too big Given I'm on the profile page Then I click on image within ".avatar-container" element And I attach a "Moon.png" file to "user_avatar_input" field - Then I click "Update" button + Then I click "Upload" button And I should see "Avatar file size must be less than 0.2 MB" error message under "user_avatar_input" field @javascript @@ -31,7 +31,7 @@ Scenario: Unsuccessful avatar image upload, file is invalid Given I'm on the profile page Then I click on image within ".avatar-container" element And I attach a "File.txt" file to "user_avatar_input" field - Then I click "Update" button + Then I click "Upload" button And I should see "Avatar content type is invalid" error message under "user_avatar_input" field @javascript @@ -39,7 +39,7 @@ Scenario: Successful upload avatar image Given I'm on the profile page Then I click on image within ".avatar-container" element And I attach a "Star.png" file to "user_avatar_input" field - Then I click "Update" button + Then I click "Upload" button And I should see "Your account has been updated successfully" flash message @javascript @@ -69,11 +69,11 @@ Scenario: Successfully changes user initials @javascript Scenario: Successfully changes user email Given I'm on the profile page - Then I click on Edit on "settings_page.new_email" input field + Then I click on Edit on "settings_page.email" input field And I change "nonadmin@myorg.com" with "user@myorg.com" email And I fill in "mypassword1234" in Current password field Then I click "Update" button - And I should see "user@myorg.com" in "settings_page.new_email" input field + And I should see "user@myorg.com" in "settings_page.email" input field @javascript Scenario: Unsuccessful Password Change, password is too short diff --git a/features/step_definitions/profile_steps.rb b/features/step_definitions/profile_steps.rb index 7e53135e2..08b4c3fdd 100644 --- a/features/step_definitions/profile_steps.rb +++ b/features/step_definitions/profile_steps.rb @@ -11,6 +11,7 @@ Then(/^I click on Browse button$/) do end Then(/^I change "([^"]*)" with "([^"]*)" email$/) do |prev_email, new_email| + wait_for_ajax find(:xpath, "//input[@value='#{prev_email}']").set(new_email) end diff --git a/features/step_definitions/shared_steps.rb b/features/step_definitions/shared_steps.rb index 3f5f5ea92..1fdbaf378 100644 --- a/features/step_definitions/shared_steps.rb +++ b/features/step_definitions/shared_steps.rb @@ -51,6 +51,7 @@ Then(/^I attach a "([^"]*)" file to "([^"]*)" field$/) do |file, field_id| end Then(/^I should see "([^"]*)" error message under "([^"]*)" field$/) do |message, field_id| + wait_for_ajax parent = find_by_id(field_id).first(:xpath, './/..') expect(parent).to have_content(message) end diff --git a/features/support/env.rb b/features/support/env.rb index 15800a0f4..79c706ef3 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,6 +4,8 @@ # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. +ENV['CUCUMBER'] = 'cucumber' + require 'cucumber/rails' require 'capybara/cucumber' require 'capybara-webkit' @@ -32,7 +34,7 @@ end Capybara.javascript_driver = :webkit Capybara.default_max_wait_time = 30 - +Capybara.asset_host = 'http://localhost:3000' # Precompile webpacker to avoid render bugs in capybara webkit # global hook throws an error :( https://github.com/cucumber/cucumber/wiki/Hooks Before('@compile') do diff --git a/features/support/wait.rb b/features/support/wait.rb new file mode 100644 index 000000000..28aecb7e9 --- /dev/null +++ b/features/support/wait.rb @@ -0,0 +1,11 @@ +# @TODO make this funtion work! +def wait_for_ajax + counter = 0 + while page.evaluate_script('axios.interceptors.response.use(function(response) { return 1 })').to_i > 0 + counter += 1 + sleep(0.1) + if (0.1 * counter) >= Capybara.default_max_wait_time + raise "AJAX request took longer than #{Capybara.default_max_wait_time} seconds." + end + end +end