Henning Snater has submitted this change and it was merged. Change subject: Selenium tests for entityselector as search-box ......................................................................
Selenium tests for entityselector as search-box Bug: 48132 Change-Id: Ic9c615f8f1fb331bacf51bdc9eb6a74d787acf35 --- A repo/tests/selenium/special/entity_search_spec.rb M selenium/Rakefile M selenium/lib/modules/entity_selector_module.rb A selenium/lib/pages/repo_main_page.rb 4 files changed, 199 insertions(+), 7 deletions(-) Approvals: Henning Snater: Verified; Looks good to me, approved jenkins-bot: Verified diff --git a/repo/tests/selenium/special/entity_search_spec.rb b/repo/tests/selenium/special/entity_search_spec.rb new file mode 100644 index 0000000..752f6d8 --- /dev/null +++ b/repo/tests/selenium/special/entity_search_spec.rb @@ -0,0 +1,152 @@ +# Wikidata UI tests +# +# Author:: Tobias Gritschacher (tobias.gritschac...@wikimedia.de) +# License:: GNU GPL v2+ +# +# tests for entity search using the entity selector widget + +require 'spec_helper' + +num_items = 1 +alias_a = generate_random_string(8) +alias_b = generate_random_string(8) + +# items +count = 0 +items = Array.new +while count < num_items do + items.push({"label"=>generate_random_string(10), "description"=>generate_random_string(20)}) + count = count + 1 +end + +describe "Check entityselector search" do + before :all do + # set up: create items + items.each do |item| + visit_page(CreateItemPage) do |page| + item['id'] = page.create_new_item(item['label'], item['description']) + item['url'] = page.current_url + end + end + end + + context "Check common behavior" do + it "should check for autocomplete in searchbox" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput?.should be_true + page.entitySelectorSearchInput = items[0]["label"][0..7] + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearchInput.should == items[0]["label"] + end + end + end + + context "Check suggestions" do + it "should check for empty suggestions" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = "foo" # non existent item + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearch?.should be_true + page.count_search_results.should == 1 # just the "containing" element + page.get_search_results[0].text.include?("containing...").should be_true + page.get_search_results[0].text.include?("foo").should be_true + end + end + it "should check for suggestion based on label" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = items[0]["label"] # existent item + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearch?.should be_true + page.count_search_results.should == 2 # 1 suggestion & the "containing" element + page.get_search_results[0].text.include?(items[0]["label"]).should be_true + page.get_search_results[0].text.include?(items[0]["description"]).should be_true + page.get_search_results[1].text.include?("containing...").should be_true + page.get_search_results[1].text.include?(items[0]["label"]).should be_true + + page.entitySelectorSearchInput_element.clear + page.entitySelectorSearchInput = items[0]["label"][0..7] # label fragment of existent item + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearch?.should be_true + page.count_search_results.should == 2 # 1 suggestion & the "containing" element + page.get_search_results[0].text.include?(items[0]["label"]).should be_true + page.get_search_results[0].text.include?(items[0]["description"]).should be_true + page.get_search_results[1].text.include?("containing...").should be_true + page.get_search_results[1].text.include?(items[0]["label"][0..7]).should be_true + end + end + it "should check for suggestion based on alias" do + on_page(ItemPage) do |page| + page.navigate_to items[0]["url"] + page.wait_for_entity_to_load + page.add_aliases([alias_a, alias_b]) + end + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = alias_a # alias of an existing item + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearch?.should be_true + page.count_search_results.should == 2 # 1 suggestion & the "containing" element + page.get_search_results[0].text.include?(items[0]["label"]).should be_true + page.get_search_results[0].text.include?(items[0]["description"]).should be_true + page.get_search_results[0].text.include?("Also known as: " + alias_a).should be_true + page.get_search_results[1].text.include?("containing...").should be_true + page.get_search_results[1].text.include?(alias_a).should be_true + + page.entitySelectorSearchInput_element.clear + page.entitySelectorSearchInput = alias_a[0..6] # alias-fragment of an existing item + ajax_wait + page.wait_for_suggestions_list + page.entitySelectorSearch?.should be_true + page.count_search_results.should == 2 # 1 suggestion & the "containing" element + page.get_search_results[0].text.include?(items[0]["label"]).should be_true + page.get_search_results[0].text.include?(items[0]["description"]).should be_true + page.get_search_results[0].text.include?("Also known as: " + alias_a).should be_true + page.get_search_results[1].text.include?("containing...").should be_true + page.get_search_results[1].text.include?(alias_a[0..6]).should be_true + end + end + it "should trigger regular search for nonexistent item" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = "foo" # non existent item + ajax_wait + page.wait_for_suggestions_list + page.get_search_results[0].click + end + on_page(SearchPage) do |page| + page.searchResultDiv?.should be_true + page.searchResults?.should be_false + page.noResults?.should be_true + end + end + it "should trigger regular search for existing item" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = items[0]["label"] # existent item + ajax_wait + page.wait_for_suggestions_list + page.get_search_results[1].click + end + on_page(SearchPage) do |page| + page.searchResultDiv?.should be_true + page.searchResults?.should be_true + page.noResults?.should be_false + page.count_search_results.should == 1 + page.firstResultLabelSpan_element.text.should == items[0]["label"] + end + end + it "should click on suggested item" do + visit_page(RepoMainPage) do |page| + page.entitySelectorSearchInput = items[0]["label"] # existent item + ajax_wait + page.wait_for_suggestions_list + page.get_search_results[0].click + page.wait_for_entity_to_load + page.entityLabelSpan?.should be_true + page.entityLabelSpan.should == items[0]["label"] + end + end + end +end diff --git a/selenium/Rakefile b/selenium/Rakefile index 73f4384..1efca87 100644 --- a/selenium/Rakefile +++ b/selenium/Rakefile @@ -278,6 +278,11 @@ spec.pattern = '../repo/tests/selenium/item/revision_spec.rb' end +RSpec::Core::RakeTask.new(:entity_search) do |spec| + spec.ruby_opts = "-I lib:spec" + spec.pattern = '../repo/tests/selenium/special/entity_search_spec.rb' +end + task :run_tests, :taskname, :browser, :remote, :os do |t, args| task = args[:taskname] || :all setup_env(args[:browser], args[:remote], args[:os]) diff --git a/selenium/lib/modules/entity_selector_module.rb b/selenium/lib/modules/entity_selector_module.rb index 8be78fb..0f0f587 100644 --- a/selenium/lib/modules/entity_selector_module.rb +++ b/selenium/lib/modules/entity_selector_module.rb @@ -15,18 +15,39 @@ span(:firstEntitySelectorDescription, :xpath => "//ul[contains(@class, 'ui-entityselector-list')]/li/a/span/span[contains(@class, 'ui-entityselector-description')]") text_field(:entitySelectorInput, :xpath => "//div[contains(@class, 'wb-claimlist')]//input[contains(@class, 'ui-entityselector-input')]", :index => 0) text_field(:entitySelectorInput2, :xpath => "//div[contains(@class, 'wb-claimlist')]//input[contains(@class, 'ui-entityselector-input')]", :index => 1) + text_field(:entitySelectorSearchInput, :id => "searchInput") + unordered_list(:entitySelectorSearch, :xpath => "//body/ul[contains(@class, 'ui-entityselector-list')]") def wait_for_entity_selector_list wait_until do entitySelectorList? end end -end -def select_entity(label) - self.entitySelectorInput = label - ajax_wait - self.wait_for_entity_selector_list - firstEntitySelectorLink - ajax_wait + def wait_for_suggestions_list + wait_until do + entitySelectorSearch? + end + end + + def select_entity(label) + self.entitySelectorInput = label + ajax_wait + self.wait_for_entity_selector_list + firstEntitySelectorLink + ajax_wait + end + + def count_search_results + entitySelectorSearch_element.items + end + + def get_search_results + results = [] + entitySelectorSearch_element.each do |li| + results << li + end + results + end + end diff --git a/selenium/lib/pages/repo_main_page.rb b/selenium/lib/pages/repo_main_page.rb new file mode 100644 index 0000000..232f9f0 --- /dev/null +++ b/selenium/lib/pages/repo_main_page.rb @@ -0,0 +1,14 @@ +# -*- encoding : utf-8 -*- +# Wikidata UI tests +# +# Author:: Tobias Gritschacher (tobias.gritschac...@wikimedia.de) +# License:: GNU GPL v2+ +# +# page object for repo main page + +class RepoMainPage < ItemPage + include PageObject + + page_url WIKI_REPO_URL + +end -- To view, visit https://gerrit.wikimedia.org/r/64045 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic9c615f8f1fb331bacf51bdc9eb6a74d787acf35 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de> Gerrit-Reviewer: Henning Snater <henning.sna...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits