Tobias Gritschacher has uploaded a new change for review. https://gerrit.wikimedia.org/r/80063
Change subject: Added cucumber tests for entity descriptions ...................................................................... Added cucumber tests for entity descriptions - small adjustments to label tests were necessary due to better code reuse - added additional tests for empty labels and descriptions Change-Id: I589d13445bb4cedb475ff481eb78fb1276b56963 --- A selenium_cuc/features/description.feature A selenium_cuc/features/empty_label_and_description.feature M selenium_cuc/features/label.feature A selenium_cuc/features/step_definitions/description_steps.rb A selenium_cuc/features/step_definitions/entity_steps.rb M selenium_cuc/features/step_definitions/label_steps.rb M selenium_cuc/features/support/modules/entity_module.rb M selenium_cuc/features/support/pages/item_page.rb M selenium_cuc/features/support/utils/utils.rb 9 files changed, 275 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/63/80063/1 diff --git a/selenium_cuc/features/description.feature b/selenium_cuc/features/description.feature new file mode 100644 index 0000000..54d483f --- /dev/null +++ b/selenium_cuc/features/description.feature @@ -0,0 +1,79 @@ +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# feature definition for item description tests + +Feature: Edit description + + Background: + Given I am on an item page + + Scenario: Description UI has all required elements + Then Original description should be displayed + And Description edit button should be there + And Description cancel button should not be there + + Scenario: Click edit button + When I click the description edit button + Then Description input element should be there + And Description input element should contain original description + And Description cancel button should be there + + Scenario: Modify the description + When I click the description edit button + And I enter MODIFIED DESCRIPTION as description + Then Description save button should be there + And Description cancel button should be there + And Description edit button should not be there + + Scenario: Description cancel + When I click the description edit button + And I enter MODIFIED DESCRIPTION as description + And I click the description cancel button + Then Original description should be displayed + And Description edit button should be there + And Description cancel button should not be there + + Scenario: Description cancel with ESCAPE + When I click the description edit button + And I enter MODIFIED DESCRIPTION as description + And I press the ESC key in the description input field + Then Original description should be displayed + And Description edit button should be there + And Description cancel button should not be there + + Scenario: Description save + When I click the description edit button + And I enter MODIFIED DESCRIPTION as description + And I click the description save button + Then MODIFIED DESCRIPTION should be displayed as description + When I reload the page + Then MODIFIED DESCRIPTION should be displayed as description + + Scenario: Description save with RETURN + When I click the description edit button + And I enter MODIFIED DESCRIPTION as description + And I press the RETURN key in the description input field + Then MODIFIED DESCRIPTION should be displayed as description + When I reload the page + Then MODIFIED DESCRIPTION should be displayed as description + + Scenario: Description with unnormalized value + When I click the description edit button + And I enter bla bla as description + And I click the description save button + Then bla bla should be displayed as description + + Scenario: Description with "0" as value + When I click the description edit button + And I enter 0 as description + And I click the description save button + Then 0 should be displayed as description + + Scenario: Description with a too long value + When I click the description edit button + And I enter looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong as description + And I click the description save button + Then An error message should be displayed diff --git a/selenium_cuc/features/empty_label_and_description.feature b/selenium_cuc/features/empty_label_and_description.feature new file mode 100644 index 0000000..1ccef69 --- /dev/null +++ b/selenium_cuc/features/empty_label_and_description.feature @@ -0,0 +1,47 @@ +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# feature definition for item description tests + +Feature: Empty label and description behaviour + + Background: + Given I am on an item page with empty label and description + + Scenario: Description UI is shown correctly when description is empty + Then Description input element should be there + And Description input element should be empty + And Description edit button should not be there + And Description cancel button should not be there + And Description save button should not be there + + Scenario: Description UI behaves correctly when description is empty + When I enter NEW DESCRIPTION as description + Then Description cancel button should be there + And Description save button should be there + When I click the description cancel button + Then Description cancel button should not be there + And Description edit button should not be there + And Description save button should not be there + And Description input element should be there + And Description input element should be empty + + Scenario: Label UI is shown correctly when label is empty + Then Label input element should be there + And Label input element should be empty + And Label edit button should not be there + And Label cancel button should not be there + And Label save button should not be there + + Scenario: Label UI behaves correctly when label is empty + When I enter NEW LABEL as label + Then Label cancel button should be there + Then Label save button should be there + When I click the label cancel button + Then Label cancel button should not be there + Then Label edit button should not be there + Then Label save button should not be there + Then Label input element should be there + Then Label input element should be empty diff --git a/selenium_cuc/features/label.feature b/selenium_cuc/features/label.feature index 50b3046..5ad26d0 100644 --- a/selenium_cuc/features/label.feature +++ b/selenium_cuc/features/label.feature @@ -8,7 +8,7 @@ Feature: Edit label Background: - Given I am on an entity page + Given I am on an item page Scenario: Label UI has all required elements Then Original label should be displayed @@ -39,7 +39,7 @@ Scenario: Label cancel with ESCAPE When I click the label edit button And I enter MODIFIED LABEL as label - And I press the ESC key + And I press the ESC key in the label input field Then Original label should be displayed And Label edit button should be there And Label cancel button should not be there @@ -55,7 +55,7 @@ Scenario: Label save with RETURN When I click the label edit button And I enter MODIFIED LABEL as label - And I press the RETURN key + And I press the RETURN key in the label input field Then MODIFIED LABEL should be displayed as label When I reload the page Then MODIFIED LABEL should be displayed as label diff --git a/selenium_cuc/features/step_definitions/description_steps.rb b/selenium_cuc/features/step_definitions/description_steps.rb new file mode 100644 index 0000000..9079e7e --- /dev/null +++ b/selenium_cuc/features/step_definitions/description_steps.rb @@ -0,0 +1,95 @@ +# -*- encoding : utf-8 -*- +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# tests for item description + +When /^I click the description edit button$/ do + on(ItemPage).editDescriptionLink +end + +When /^I press the ESC key in the description input field$/ do + on(ItemPage).descriptionInputField_element.send_keys :escape +end + +When /^I press the RETURN key in the description input field$/ do + on(ItemPage) do |page| + page.descriptionInputField_element.send_keys :return + page.wait_for_api_callback + end +end + +When /^I click the description cancel button$/ do + on(ItemPage).cancelDescriptionLink +end + +When /^I click the description save button$/ do + on(ItemPage) do |page| + page.saveDescriptionLink + page.wait_for_api_callback + end +end + +When /^I enter (.+) as description$/ do |value| + on(ItemPage) do |page| + page.descriptionInputField_element.clear + page.descriptionInputField = value + end +end + +Then /^Description edit button should be there$/ do + on(ItemPage).editDescriptionLink?.should be_true +end + +Then /^Description edit button should not be there$/ do + on(ItemPage).editDescriptionLink?.should be_false +end + +Then /^Description input element should be there$/ do + on(ItemPage).descriptionInputField?.should be_true +end + +Then /^Description input element should not be there$/ do + on(ItemPage).descriptionInputField?.should be_false +end + +Then /^Description input element should contain original description$/ do + on(ItemPage).descriptionInputField.should == @entity["description"] +end + +Then /^Description input element should be empty$/ do + on(ItemPage).descriptionInputField.should == "" +end + +Then /^Description cancel button should be there$/ do + on(ItemPage).cancelDescriptionLink?.should be_true +end + +Then /^Description cancel button should not be there$/ do + on(ItemPage).cancelDescriptionLink?.should be_false +end + +Then /^Description save button should be there$/ do + on(ItemPage).saveDescriptionLink?.should be_true +end + +Then /^Description save button should not be there$/ do + on(ItemPage).saveDescriptionLink?.should be_false +end + +Then /^Original description should be displayed$/ do + on(ItemPage) do |page| + page.firstHeading.should be_true + page.entityDescriptionSpan.should be_true + page.entityDescriptionSpan.should == @entity["description"] + end +end + +Then /^(.+) should be displayed as description$/ do |value| + on(ItemPage) do |page| + page.entityDescriptionSpan.should be_true + page.entityDescriptionSpan.should == value + end +end diff --git a/selenium_cuc/features/step_definitions/entity_steps.rb b/selenium_cuc/features/step_definitions/entity_steps.rb new file mode 100644 index 0000000..d74b547 --- /dev/null +++ b/selenium_cuc/features/step_definitions/entity_steps.rb @@ -0,0 +1,29 @@ +# -*- encoding : utf-8 -*- +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# basic steps for entities + +Given /^I am on an item page$/ do + item_data = '{"labels":{"en":{"language":"en","value":"' + generate_random_string(8) + '"}},"descriptions":{"en":{"language":"en","value":"' + generate_random_string(20) + '"}}}' + item = create_new_entity(item_data, 'item') + @entity = item + on(ItemPage).navigate_to_entity item["url"] +end + +Given /^I am on an item page with empty label and description$/ do + item_data = '{"labels":{"en":{"language":"en","value":"' + "" + '"}},"descriptions":{"en":{"language":"en","value":"' + "" + '"}}}' + item = create_new_entity(item_data, 'item') + @entity = item + on(ItemPage).navigate_to_entity item["url"] +end + +Then /^An error message should be displayed$/ do + on(ItemPage).wbErrorDiv?.should be_true +end + +When /^I reload the page$/ do + @browser.refresh +end \ No newline at end of file diff --git a/selenium_cuc/features/step_definitions/label_steps.rb b/selenium_cuc/features/step_definitions/label_steps.rb index 738fa33..b80809d 100644 --- a/selenium_cuc/features/step_definitions/label_steps.rb +++ b/selenium_cuc/features/step_definitions/label_steps.rb @@ -6,26 +6,17 @@ # # tests for item label -label = generate_random_string(8) - -Given /^I am on an entity page$/ do - item_data = '{"labels":{"en":{"language":"en","value":"' + label + '"}},"descriptions":{"en":{"language":"en","value":"' + generate_random_string(20) + '"}}}' - item = create_new_entity(item_data, 'item') - on(ItemPage).navigate_to_item item["url"] -end - When /^I click the label edit button$/ do on(ItemPage).editLabelLink end -When /^I press the ESC key$/ do +When /^I press the ESC key in the label input field$/ do on(ItemPage).labelInputField_element.send_keys :escape end -When /^I press the RETURN key$/ do +When /^I press the RETURN key in the label input field$/ do on(ItemPage) do |page| page.labelInputField_element.send_keys :return - #page.ajax_wait page.wait_for_api_callback end end @@ -37,7 +28,6 @@ When /^I click the label save button$/ do on(ItemPage) do |page| page.saveLabelLink - #page.ajax_wait page.wait_for_api_callback end end @@ -49,16 +39,12 @@ end end -When /^I reload the page$/ do - @browser.refresh -end - Then /^Label edit button should be there$/ do on(ItemPage).editLabelLink?.should be_true end Then /^Label edit button should not be there$/ do - on(ItemPage).editLabelLink?.should be_true + on(ItemPage).editLabelLink?.should be_false end Then /^Label input element should be there$/ do @@ -70,7 +56,11 @@ end Then /^Label input element should contain original label$/ do - on(ItemPage).labelInputField.should == label + on(ItemPage).labelInputField.should == @entity["label"] +end + +Then /^Label input element should be empty$/ do + on(ItemPage).labelInputField.should == "" end Then /^Label cancel button should be there$/ do @@ -85,12 +75,16 @@ on(ItemPage).saveLabelLink?.should be_true end +Then /^Label save button should not be there$/ do + on(ItemPage).saveLabelLink?.should be_false +end + Then /^Original label should be displayed$/ do on(ItemPage) do |page| page.firstHeading.should be_true page.entityLabelSpan.should be_true - @browser.title.include?(label).should be_true - page.entityLabelSpan.should == label + @browser.title.include?(@entity["label"]).should be_true + page.entityLabelSpan.should == @entity["label"] end end @@ -101,8 +95,4 @@ @browser.title.include?(value).should be_true page.entityLabelSpan.should == value end -end - -Then /^An error message should be displayed$/ do - on(ItemPage).wbErrorDiv?.should be_true end diff --git a/selenium_cuc/features/support/modules/entity_module.rb b/selenium_cuc/features/support/modules/entity_module.rb index 78f3626..e967ee2 100644 --- a/selenium_cuc/features/support/modules/entity_module.rb +++ b/selenium_cuc/features/support/modules/entity_module.rb @@ -62,6 +62,11 @@ div(:mwNotificationContent, :xpath => "//div[@id='mw-notification-area']/div/div[contains(@class, 'mw-notification-content')]") # ***** METHODS ***** + def navigate_to_entity url + navigate_to url + wait_for_entity_to_load + end + def wait_for_api_callback #TODO: workaround for weird error randomly claiming that apiCallWaitingMessage-element is not attached to the DOM anymore sleep 1 diff --git a/selenium_cuc/features/support/pages/item_page.rb b/selenium_cuc/features/support/pages/item_page.rb index 51fb6e6..38ec57b 100644 --- a/selenium_cuc/features/support/pages/item_page.rb +++ b/selenium_cuc/features/support/pages/item_page.rb @@ -14,11 +14,6 @@ # ***** METHODS ***** # item url navigation - def navigate_to_item url - navigate_to url - wait_for_entity_to_load - end - def navigate_to_item_en navigate_to @@item_url + "?uselang=en" end diff --git a/selenium_cuc/features/support/utils/utils.rb b/selenium_cuc/features/support/utils/utils.rb index 7065aa8..458078d 100644 --- a/selenium_cuc/features/support/utils/utils.rb +++ b/selenium_cuc/features/support/utils/utils.rb @@ -41,5 +41,7 @@ id = resp["entity"]["id"] url = URL.repo_url(id) - return {"id" => id, "url" => url} + entity_data = ActiveSupport::JSON.decode(data) + entity = {"id" => id, "url" => url, "label" => entity_data["labels"]["en"]["value"], "description" => entity_data["descriptions"]["en"]["value"]} + return entity end \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/80063 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I589d13445bb4cedb475ff481eb78fb1276b56963 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Tobias Gritschacher <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
