jenkins-bot has submitted this change and it was merged. Change subject: Selenium: use composition instead of inheritance ......................................................................
Selenium: use composition instead of inheritance Bug: 48142 Change-Id: I511187727d001a4995ad130f0baf50e4f5571534 --- R selenium_cuc/features/support/modules/create_entity_module.rb A selenium_cuc/features/support/modules/entity_module.rb M selenium_cuc/features/support/modules/url_module.rb M selenium_cuc/features/support/pages/create_item_page.rb D selenium_cuc/features/support/pages/entity_page.rb M selenium_cuc/features/support/pages/item_page.rb 6 files changed, 143 insertions(+), 129 deletions(-) Approvals: Zfilipin: Looks good to me, approved jenkins-bot: Verified diff --git a/selenium_cuc/features/support/pages/create_entity_page.rb b/selenium_cuc/features/support/modules/create_entity_module.rb similarity index 91% rename from selenium_cuc/features/support/pages/create_entity_page.rb rename to selenium_cuc/features/support/modules/create_entity_module.rb index d94ef83..f073923 100644 --- a/selenium_cuc/features/support/pages/create_entity_page.rb +++ b/selenium_cuc/features/support/modules/create_entity_module.rb @@ -6,8 +6,9 @@ # # page object for CreateEntity special page base class -class CreateEntityPage < EntityPage +module CreateEntityPage include PageObject + include EntityPage text_field(:createEntityLabelField, :id => "wb-newentity-label") text_field(:createEntityDescriptionField, :id => "wb-newentity-description") diff --git a/selenium_cuc/features/support/modules/entity_module.rb b/selenium_cuc/features/support/modules/entity_module.rb new file mode 100644 index 0000000..1a9f8e0 --- /dev/null +++ b/selenium_cuc/features/support/modules/entity_module.rb @@ -0,0 +1,127 @@ +# -*- encoding : utf-8 -*- +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# page object for entity page + +#require 'ruby_selenium' + +module EntityPage + include PageObject + include SitelinkPage + include AliasPage + include StatementPage + include ULSPage + + @@property_url = "" + @@property_id = "" + @@item_url = "" + @@item_id = "" + + # ***** ACCESSORS ***** + # label UI + h1(:mwFirstHeading, :id => "firstHeading") + h1(:firstHeading, :xpath => "//h1[contains(@class, 'wb-firstHeading')]") + h1(:uiPropertyEdittool, :class => "wb-ui-propertyedittool") + span(:entityLabelSpan, :xpath => "//h1[contains(@class, 'wb-firstHeading')]/span/span") + text_field(:labelInputField, :xpath => "//h1[contains(@class, 'wb-firstHeading')]/span/span/input") + link(:editLabelLink, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(1)") + link(:editLabelLinkDisabled, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(1)") + link(:saveLabelLink, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(1)") + link(:saveLabelLinkDisabled, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(1)") + link(:cancelLabelLink, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(2)") + link(:cancelLabelLinkDisabled, :css => "h1.wb-firstHeading .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(2)") + + # description UI + span(:entityDescriptionSpan, :xpath => "//div[contains(@class, 'wb-ui-descriptionedittool')]/span[contains(@class, 'wb-property-container-value')]/span") + text_field(:descriptionInputField, :xpath => "//div[contains(@class, 'wb-ui-descriptionedittool')]/span[contains(@class, 'wb-property-container-value')]/span/input") + link(:editDescriptionLink, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(1)") + link(:editDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(1)") + link(:saveDescriptionLink, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(1)") + link(:saveDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(1)") + link(:cancelDescriptionLink, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton:not(.wikibase-toolbarbutton-disabled):nth-child(2)") + link(:cancelDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool .wikibase-toolbar > a.wikibase-toolbarbutton-disabled:nth-child(2)") + + span(:apiCallWaitingMessage, :class => "wb-ui-propertyedittool-editablevalue-waitmsg") + + # edit-tab + list_item(:editTab, :id => "ca-edit") + + # spinner + div(:entitySpinner, :xpath => "//div[contains(@class, 'wb-entity-spinner')]") + + # tooltips & error tooltips + div(:wbTooltip, :class => "tipsy-inner") + div(:wbErrorDiv, :class => "wikibase-wbtooltip-error-top-message") + div(:wbErrorDetailsDiv, :class => "wikibase-wbtooltip-error-details") + link(:wbErrorDetailsLink, :class => "wikibase-wbtooltip-error-details-link") + + # mw notifications + div(:mwNotificationContent, :xpath => "//div[@id='mw-notification-area']/div/div[contains(@class, 'mw-notification-content')]") + + # ***** METHODS ***** + def wait_for_api_callback + #TODO: workaround for weird error randomly claiming that apiCallWaitingMessage-element is not attached to the DOM anymore + sleep 1 + return + wait_until do + apiCallWaitingMessage? == false + end + end + + def wait_for_entity_to_load + wait_until do + entitySpinner? == false + end + end + + def wait_for_editLabelLink + wait_until do + editLabelLink? + end + end + + def change_label(label) + if editLabelLink? + editLabelLink + end + self.labelInputField= label + saveLabelLink + ajax_wait + wait_for_api_callback + end + + def change_description(description) + if editDescriptionLink? + editDescriptionLink + end + self.descriptionInputField= description + saveDescriptionLink + ajax_wait + wait_for_api_callback + end + + def wait_for_mw_notification_shown + wait_until do + mwNotificationContent? == true + end + end + + def ajax_wait + sleep 1 + while (script = @browser.execute_script("return jQuery.active")) == 1 do + sleep(1.0/3) + end + return true + end + + # creates a random string + def generate_random_string(length=8) + chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' + string = '' + length.times { string << chars[rand(chars.size)] } + return string + end +end diff --git a/selenium_cuc/features/support/modules/url_module.rb b/selenium_cuc/features/support/modules/url_module.rb index e95d25f..69ba144 100644 --- a/selenium_cuc/features/support/modules/url_module.rb +++ b/selenium_cuc/features/support/modules/url_module.rb @@ -1,3 +1,13 @@ +# -*- encoding : utf-8 -*- +# Wikidata UI tests +# +# Author:: Tobias Gritschacher ([email protected]) +# License:: GNU GPL v2+ +# +# Reused and modified from https://github.com/wikimedia/qa-browsertests/blob/master/features/support/modules/url_module.rb +# +# module for URLs + module URL def self.client_url(name) if ENV['WIKIDATA_CLIENT_URL'] diff --git a/selenium_cuc/features/support/pages/create_item_page.rb b/selenium_cuc/features/support/pages/create_item_page.rb index a15af26..5ef4e77 100644 --- a/selenium_cuc/features/support/pages/create_item_page.rb +++ b/selenium_cuc/features/support/pages/create_item_page.rb @@ -6,8 +6,9 @@ # # page object for CreateItem special page -class CreateItemPage < CreateEntityPage +class CreateItemPage include PageObject + include CreateEntityPage include URL page_url URL.repo_url("Special:NewItem") diff --git a/selenium_cuc/features/support/pages/entity_page.rb b/selenium_cuc/features/support/pages/entity_page.rb deleted file mode 100644 index 9c9c0a0..0000000 --- a/selenium_cuc/features/support/pages/entity_page.rb +++ /dev/null @@ -1,126 +0,0 @@ -# -*- encoding : utf-8 -*- -# Wikidata UI tests -# -# Author:: Tobias Gritschacher ([email protected]) -# License:: GNU GPL v2+ -# -# page object for entity page - -#require 'ruby_selenium' - -class EntityPage# < RubySelenium - include PageObject - include SitelinkPage - include AliasPage - include StatementPage - include ULSPage - - @@property_url = "" - @@property_id = "" - @@item_url = "" - @@item_id = "" - - # ***** ACCESSORS ***** - # label UI - h1(:mwFirstHeading, :id => "firstHeading") - h1(:firstHeading, :xpath => "//h1[contains(@class, 'wb-firstHeading')]") - h1(:uiPropertyEdittool, :class => "wb-ui-propertyedittool") - span(:entityLabelSpan, :xpath => "//h1[contains(@class, 'wb-firstHeading')]/span/span") - link(:editLabelLink, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(1)") - link(:editLabelLinkDisabled, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button-disabled:nth-child(1)") - text_field(:labelInputField, :xpath => "//h1[contains(@class, 'wb-firstHeading')]/span/span/input") - link(:cancelLabelLink, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(2)") - link(:saveLabelLinkDisabled, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button-disabled:nth-child(1)") - link(:cancelLabelLinkDisabled, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button-disabled:nth-child(2)") - link(:saveLabelLink, :css => "h1.wb-firstHeading > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(1)") - - # description UI - span(:entityDescriptionSpan, :xpath => "//div[contains(@class, 'wb-ui-descriptionedittool')]/span[contains(@class, 'wb-property-container-value')]/span") - link(:editDescriptionLink, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(1)") - link(:editDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button-disabled:nth-child(1)") - text_field(:descriptionInputField, :xpath => "//div[contains(@class, 'wb-ui-descriptionedittool')]/span[contains(@class, 'wb-property-container-value')]/span/input") - link(:cancelDescriptionLink, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(2)") - link(:saveDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button:nth-child(1)") - link(:cancelDescriptionLinkDisabled, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > span.wb-ui-toolbar-button:nth-child(2)") - link(:saveDescriptionLink, :css => "div.wb-ui-descriptionedittool > span > span.wb-ui-propertyedittool-editablevalue-toolbarparent > span.wb-ui-toolbar > span.wb-ui-toolbar-group > span.wb-ui-toolbar-group > a.wb-ui-toolbar-button:nth-child(1)") - - span(:apiCallWaitingMessage, :class => "wb-ui-propertyedittool-editablevalue-waitmsg") - - # edit-tab - list_item(:editTab, :id => "ca-edit") - - # spinner - div(:entitySpinner, :xpath => "//div[contains(@class, 'wb-entity-spinner')]") - - # tooltips & error tooltips - div(:wbTooltip, :class => "tipsy-inner") - div(:wbErrorDiv, :class => "wb-tooltip-error-top-message") - div(:wbErrorDetailsDiv, :class => "wb-tooltip-error-details") - link(:wbErrorDetailsLink, :class => "wb-tooltip-error-details-link") - - # mw notifications - div(:mwNotificationContent, :xpath => "//div[@id='mw-notification-area']/div/div[contains(@class, 'mw-notification-content')]") - # ***** METHODS ***** - def wait_for_api_callback - #TODO: workaround for weird error randomly claiming that apiCallWaitingMessage-element is not attached to the DOM anymore - sleep 1 - return - wait_until do - apiCallWaitingMessage? == false - end - end - - def wait_for_entity_to_load - wait_until do - entitySpinner? == false - end - end - - def wait_for_editLabelLink - wait_until do - editLabelLink? - end - end - - def change_label(label) - if editLabelLink? - editLabelLink - end - self.labelInputField= label - saveLabelLink - ajax_wait - wait_for_api_callback - end - - def change_description(description) - if editDescriptionLink? - editDescriptionLink - end - self.descriptionInputField= description - saveDescriptionLink - ajax_wait - wait_for_api_callback - end - - def wait_for_mw_notification_shown - wait_until do - mwNotificationContent? == true - end - end - - def ajax_wait - sleep 1 - while (script = @browser.execute_script("return jQuery.active")) == 1 do - sleep(1.0/3) - end - return true - end - - # creates a random string - def generate_random_string(length=8) - chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' - string = '' - length.times { string << chars[rand(chars.size)] } - return string - end -end diff --git a/selenium_cuc/features/support/pages/item_page.rb b/selenium_cuc/features/support/pages/item_page.rb index a49592b..b6d2764 100644 --- a/selenium_cuc/features/support/pages/item_page.rb +++ b/selenium_cuc/features/support/pages/item_page.rb @@ -8,8 +8,9 @@ #require 'ruby_selenium' -class ItemPage < EntityPage +class ItemPage include PageObject + include EntityPage # ***** METHODS ***** # item url navigation -- To view, visit https://gerrit.wikimedia.org/r/63857 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I511187727d001a4995ad130f0baf50e4f5571534 Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Tobias Gritschacher <[email protected]> Gerrit-Reviewer: Cmcmahon <[email protected]> Gerrit-Reviewer: Rachel99 <[email protected]> Gerrit-Reviewer: Tobias Gritschacher <[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
