Dduvall has submitted this change and it was merged. Change subject: [tests] Fix some bugs with page creation ......................................................................
[tests] Fix some bugs with page creation 1. Unicode problem made it so all non-ascii pages were considered different on every run. 2. We reuse the api client now which speeds up the calls slightly. Its simpler to read too. Change-Id: Ie44d89540a81ee9c1dd3b8ea7beeacb3a3d6c6c8 --- M tests/browser/Gemfile M tests/browser/Gemfile.lock M tests/browser/features/incategory.feature M tests/browser/features/step_definitions/page_steps.rb A tests/browser/features/support/cirrus_search_api_helper.rb M tests/browser/features/support/hooks.rb M tests/browser/selenium_exports_for_vagrant.sh 7 files changed, 55 insertions(+), 50 deletions(-) Approvals: Dduvall: Looks good to me, approved diff --git a/tests/browser/Gemfile b/tests/browser/Gemfile index 1610537..c9b00ec 100644 --- a/tests/browser/Gemfile +++ b/tests/browser/Gemfile @@ -4,6 +4,6 @@ source "https://rubygems.org" gem "mediawiki_api" -gem "mediawiki_selenium", "~> 0.2.0" +gem "mediawiki_selenium", "~> 0.3.0" gem "parallel_tests" gem "rubocop", require: false diff --git a/tests/browser/Gemfile.lock b/tests/browser/Gemfile.lock index 4f4ea5e..cdfa4be 100644 --- a/tests/browser/Gemfile.lock +++ b/tests/browser/Gemfile.lock @@ -2,10 +2,12 @@ remote: https://rubygems.org/ specs: ast (2.0.0) + astrolabe (1.3.0) + parser (>= 2.2.0.pre.3, < 3.0) builder (3.2.2) childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) - cucumber (1.3.16) + cucumber (1.3.17) builder (>= 2.1.2) diff-lcs (>= 1.1.3) gherkin (~> 2.12) @@ -15,7 +17,7 @@ faker (>= 1.1.2) yml_reader (>= 0.3) diff-lcs (1.2.5) - domain_name (0.5.20) + domain_name (0.5.21) unf (>= 0.0.5, < 1.0.0) faker (1.4.3) i18n (~> 0.5) @@ -35,10 +37,11 @@ mediawiki_api (0.2.1) faraday (~> 0.9, >= 0.9.0) faraday-cookie_jar (~> 0.0, >= 0.0.6) - mediawiki_selenium (0.2.25) + mediawiki_selenium (0.3.2) cucumber (~> 1.3, >= 1.3.10) headless (~> 1.0, >= 1.0.1) json (~> 1.8, >= 1.8.1) + mediawiki_api (~> 0.2, >= 0.2.1) page-object (~> 1.0) rest-client (~> 1.6, >= 1.6.7) rspec-expectations (~> 2.14, >= 2.14.4) @@ -54,8 +57,8 @@ watir-webdriver (>= 0.6.9) page_navigation (0.9) data_magic (>= 0.14) - parallel (1.2.4) - parallel_tests (1.0.6) + parallel (1.3.2) + parallel_tests (1.0.7) parallel parser (2.2.0.pre.4) ast (>= 1.1, < 3.0) @@ -67,18 +70,19 @@ netrc (~> 0.7) rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rubocop (0.25.0) + rubocop (0.26.1) + astrolabe (~> 1.3) parser (>= 2.2.0.pre.4, < 3.0) powerpack (~> 0.0.6) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) ruby-progressbar (1.5.1) rubyzip (1.1.6) - selenium-webdriver (2.42.0) - childprocess (>= 0.5.0) + selenium-webdriver (2.43.0) + childprocess (~> 0.5) multi_json (~> 1.0) rubyzip (~> 1.0) - websocket (~> 1.0.4) + websocket (~> 1.0) slop (3.6.0) syntax (1.2.0) unf (0.1.4) @@ -86,7 +90,7 @@ unf_ext (0.0.6) watir-webdriver (0.6.10) selenium-webdriver (>= 2.18.0) - websocket (1.0.7) + websocket (1.2.1) yml_reader (0.3) PLATFORMS @@ -94,6 +98,6 @@ DEPENDENCIES mediawiki_api - mediawiki_selenium (~> 0.2.0) + mediawiki_selenium (~> 0.3.0) parallel_tests rubocop diff --git a/tests/browser/features/incategory.feature b/tests/browser/features/incategory.feature index dd47f2a..2c911f0 100644 --- a/tests/browser/features/incategory.feature +++ b/tests/browser/features/incategory.feature @@ -7,7 +7,7 @@ When I search for incategory:weaponry Then Catapult is in the search results And Amazing Catapult is in the search results - But Two Words is not in the search results + But Two Words is not in the search results And there is no link to create a new page from the search result Scenario: incategory: can be combined with other text diff --git a/tests/browser/features/step_definitions/page_steps.rb b/tests/browser/features/step_definitions/page_steps.rb index 5f54456..2ed2819 100644 --- a/tests/browser/features/step_definitions/page_steps.rb +++ b/tests/browser/features/step_definitions/page_steps.rb @@ -69,40 +69,3 @@ on(ArticlePage).title.index("#{namespace}:").should_not.nil? end end - -def edit_page(title, text, add) - text = File.read("articles/" + text[1..-1]) if text.start_with?("@") - require "mediawiki_api" - fetched_text = get_page_text(title) - # Note that the space keeps words from smashing together - text = fetched_text + " " + text if add - return if fetched_text.strip == text.strip - client = MediawikiApi::Client.new("#{ENV["MEDIAWIKI_URL"]}../w/api.php", false) - client.log_in(ENV["MEDIAWIKI_USER"], ENV["MEDIAWIKI_PASSWORD"]) - result = client.create_page(title, text) - expect(result.status).to eq 200 - expect(result.warnings?).to eq false -end - -# Gets page text using the api. -def get_page_text(title) - require "mediawiki_api" - client = MediawikiApi::Client.new("#{ENV["MEDIAWIKI_URL"]}../w/api.php", false) - fetched_text = client.get_wikitext(title) - return "" if fetched_text.status == 404 - fetched_text.status.should eq 200 - fetched_text.body.strip -end - -# Uploads a file if the file's MD5 doesn't match what is already uploaded. -def upload_file(title, contents, description) - contents = "articles/" + contents - md5 = "md5: #{Digest::MD5.hexdigest(File.read(contents))}" - visit(ArticlePage, using_params: { page_name: title }) do |page| - page.last_file_comment_contains(md5) - step "I am logged in" unless page.upload? - page.upload - end - on(UploadFilePage).upload(contents, description, md5) - on(UploadFilePage).error_element.should_not exist -end diff --git a/tests/browser/features/support/cirrus_search_api_helper.rb b/tests/browser/features/support/cirrus_search_api_helper.rb new file mode 100644 index 0000000..8ba8e13 --- /dev/null +++ b/tests/browser/features/support/cirrus_search_api_helper.rb @@ -0,0 +1,34 @@ +module CirrusSearchApiHelper + def edit_page(title, text, add) + text = File.read("articles/" + text[1..-1]) if text.start_with?("@") + fetched_text = get_page_text(title) + # Note that the space keeps words from smashing together + text = fetched_text + " " + text if add + return if fetched_text.strip == text.strip + api.log_in(ENV["MEDIAWIKI_USER"], ENV["MEDIAWIKI_PASSWORD"]) unless api.logged_in? + result = api.create_page(title, text) + expect(result.status).to eq 200 + expect(result.warnings?).to eq false + end + + # Gets page text using the api. + def get_page_text(title) + fetched_text = api.get_wikitext(title) + return "" if fetched_text.status == 404 + fetched_text.status.should eq 200 + fetched_text.body.strip.force_encoding("utf-8") + end + + # Uploads a file if the file's MD5 doesn't match what is already uploaded. + def upload_file(title, contents, description) + contents = "articles/" + contents + md5 = "md5: #{Digest::MD5.hexdigest(File.read(contents))}" + visit(ArticlePage, using_params: { page_name: title }) do |page| + page.last_file_comment_contains(md5) + step "I am logged in" unless page.upload? + page.upload + end + on(UploadFilePage).upload(contents, description, md5) + on(UploadFilePage).error_element.should_not exist + end +end diff --git a/tests/browser/features/support/hooks.rb b/tests/browser/features/support/hooks.rb index e8ca05f..6f18646 100644 --- a/tests/browser/features/support/hooks.rb +++ b/tests/browser/features/support/hooks.rb @@ -1,5 +1,8 @@ # encoding: utf-8 +World(CirrusSearchApiHelper) + + main = false Before("@setup_main, @filters, @prefix, @bad_syntax, @wildcard, @exact_quotes") do unless main diff --git a/tests/browser/selenium_exports_for_vagrant.sh b/tests/browser/selenium_exports_for_vagrant.sh index a0a85f1..1d621e4 100644 --- a/tests/browser/selenium_exports_for_vagrant.sh +++ b/tests/browser/selenium_exports_for_vagrant.sh @@ -1,6 +1,7 @@ export MEDIAWIKI_USER=admin export MEDIAWIKI_PASSWORD=vagrant export MEDIAWIKI_URL=http://127.0.0.1:8080/wiki/ +export MEDIAWIKI_API_URL=http://127.0.0.1:8080/w/api.php export REUSE_BROWSER=false export SCREENSHOT_FAILURES=true export BROWSER=phantomjs -- To view, visit https://gerrit.wikimedia.org/r/160988 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie44d89540a81ee9c1dd3b8ea7beeacb3a3d6c6c8 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: Manybubbles <[email protected]> Gerrit-Reviewer: Chad <[email protected]> Gerrit-Reviewer: Cmcmahon <[email protected]> Gerrit-Reviewer: Dduvall <[email protected]> Gerrit-Reviewer: Manybubbles <[email protected]> Gerrit-Reviewer: Zfilipin <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
