Tobias Gritschacher has submitted this change and it was merged.

Change subject: Use cucumber for aliases tests
......................................................................


Use cucumber for aliases tests

Bug: 53848
Change-Id: Iaeb4acbe0e6e7575804a48d05999be4a89bbe091
---
A selenium_cuc/features/aliases.feature
A selenium_cuc/features/step_definitions/aliases_steps.rb
M selenium_cuc/features/support/modules/alias_module.rb
3 files changed, 402 insertions(+), 28 deletions(-)

Approvals:
  Tobias Gritschacher: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/selenium_cuc/features/aliases.feature 
b/selenium_cuc/features/aliases.feature
new file mode 100644
index 0000000..67cf0e1
--- /dev/null
+++ b/selenium_cuc/features/aliases.feature
@@ -0,0 +1,223 @@
+# Wikidata UI tests
+#
+# Author:: Tobias Gritschacher ([email protected])
+# License:: GNU GPL v2+
+#
+# feature definition for item aliases tests
+
+Feature: Edit aliases
+
+  Background:
+    Given I am on an item page
+
+  @ui_only
+  Scenario: Aliases UI has all required elements
+    Then Aliases UI should be there
+      And Aliases add button should be there
+      And Aliases edit button should not be there
+      And Aliases list should be empty
+
+  @ui_only
+  Scenario: Click add button
+    When I click the aliases add button
+    Then New alias input field should be there
+      And Aliases add button should not be there
+      And Aliases edit button should not be there
+      And Aliases cancel button should be there
+      And Aliases save button should be disabled
+      And Aliases help field should be there
+
+  @ui_only
+  Scenario: Type new alias
+    When I click the aliases add button
+      And I enter 'alias123' as new aliases
+    Then Aliases cancel button should be there
+      And Aliases save button should be there
+      And Modified alias input field should be there
+      And New alias input field should be there
+
+  @ui_only
+  Scenario Outline: Cancel aliases
+    When I click the aliases add button
+      And I enter 'alias123' as new aliases
+      And I <cancel>
+    Then Aliases add button should be there
+      And Aliases save button should not be there
+      And Aliases edit button should not be there
+      And Aliases cancel button should not be there
+      And New alias input field should not be there
+      And Aliases list should be empty
+
+    Examples:
+      | cancel |
+      | click the aliases cancel button |
+      | press the ESC key in the new alias input field |
+
+  @save_aliases @modify_entity
+  Scenario Outline: Save alias
+    When I click the aliases add button
+      And I enter 'alias123' as new aliases
+      And I <save>
+    Then Aliases list should not be empty
+      And Aliases add button should not be there
+      And Aliases cancel button should not be there
+      And Aliases save button should not be there
+      And Aliases edit button should be there
+      And There should be 1 aliases in the list
+      And List of aliases should be 'alias123'
+
+    Examples:
+      | save |
+      | click the aliases save button |
+      | press the RETURN key in the new alias input field |
+
+  @save_aliases @modify_entity
+  Scenario Outline: Save alias and reload
+    When I click the aliases add button
+      And I enter 'alias123' as new aliases
+      And I <save>
+      And I reload the page
+    Then Aliases edit button should be there
+      And There should be 1 aliases in the list
+      And List of aliases should be 'alias123'
+
+    Examples:
+      | save |
+      | click the aliases save button |
+      | press the RETURN key in the new alias input field |
+
+  @save_aliases @modify_entity
+  Scenario: Save multiple aliases
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2', 'alias3' as new aliases
+      And I click the aliases save button
+    Then Aliases list should not be empty
+      And There should be 3 aliases in the list
+      And List of aliases should be 'alias1', 'alias2', 'alias3'
+
+  @save_aliases @modify_entity
+  Scenario: Remove alias
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2' as new aliases
+      And I click the aliases save button
+      And I click the aliases edit button
+      And I click the remove first alias button
+      And I click the aliases save button
+    Then List of aliases should be 'alias2'
+      And There should be 1 aliases in the list
+
+  @save_aliases @modify_entity
+  Scenario: Remove all aliases
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2' as new aliases
+      And I click the aliases save button
+      And I click the aliases edit button
+      And I click the remove first alias button
+      And I click the remove first alias button
+      And I click the aliases save button
+    Then Aliases list should be empty
+      And Aliases add button should be there
+
+  @save_aliases @modify_entity
+  Scenario: Remove all aliases and reload
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2' as new aliases
+      And I click the aliases save button
+      And I click the aliases edit button
+      And I click the remove first alias button
+      And I click the remove first alias button
+      And I click the aliases save button
+      And I reload the page
+    Then Aliases list should be empty
+      And Aliases add button should be there
+
+  @ui_only
+  Scenario: Edit aliases UI
+    When I click the aliases add button
+      And I enter 'alias123' as new aliases
+      And I click the aliases save button
+      And I click the aliases edit button
+    Then New alias input field should be there
+      And First alias input field should contain alias123
+      And Aliases save button should be disabled
+      And Aliases cancel button should be there
+      And First remove alias button should be there
+
+  @save_aliases @modify_entity
+  Scenario: Edit multiple aliases
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2' as new aliases
+      And I click the aliases save button
+      And I click the aliases edit button
+      And I enter 'alias3', 'alias4' as new aliases
+      And I click the remove first alias button
+      And I change the first alias to alias5
+      And I click the aliases save button
+    Then There should be 3 aliases in the list
+      And List of aliases should be 'alias5', 'alias3', 'alias4'
+
+  @ui_only
+  Scenario: Duplicated aliases detection
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2', 'alias1' as new aliases
+    Then Duplicate alias input field should be there
+      And Aliases save button should be there
+      And Aliases cancel button should be there
+
+  @ui_only
+  Scenario: Duplicated aliases resolve
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2', 'alias1' as new aliases
+      And I click the remove first alias button
+    Then Duplicate alias input field should not be there
+
+  @save_aliases @modify_entity
+  Scenario: Save duplicated aliases
+    When I click the aliases add button
+      And I enter 'alias1', 'alias2', 'alias1' as new aliases
+      And I click the aliases save button
+    Then There should be 2 aliases in the list
+      And List of aliases should be 'alias1', 'alias2'
+
+  @save_aliases @modify_entity
+  Scenario Outline: Special inputs for aliases
+    When I click the aliases add button
+      And I enter '<alias>' as new aliases
+      And I click the aliases save button
+    Then There should be 1 aliases in the list
+      And List of aliases should be '<alias_expected>'
+
+    Examples:
+      | alias | alias_expected |
+      | 0 | 0 |
+      |    norm   a lize   me    | norm a lize me |
+      | <script>$("body").empty();</script> | 
<script>$("body").empty();</script> |
+
+  @save_aliases
+  Scenario: Too long input for alias
+    When I click the aliases add button
+      And I enter 
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong'
 as new aliases
+      And I click the aliases save button
+    Then An error message should be displayed
+
+  @save_aliases @modify_entity @bugfix
+  Scenario: Zombie alias bugfix
+    When I click the aliases add button
+      And I enter 'zombie' as new aliases
+      And I click the aliases save button
+      And I reload the page
+      And I click the aliases edit button
+      And I click the remove first alias button
+      And I click the aliases save button
+      And I click the aliases add button
+      And I enter 'alias123' as new aliases
+      And I click the aliases save button
+    Then There should be 1 aliases in the list
+      And List of aliases should be 'alias123'
+
+  @ui_only @bugfix
+  Scenario: Bugfix for addbutton appearing when it should not
+    When I click the aliases add button
+      And I click the aliases cancel button
+      And I click the aliases add button
+    Then Aliases add button should not be there
diff --git a/selenium_cuc/features/step_definitions/aliases_steps.rb 
b/selenium_cuc/features/step_definitions/aliases_steps.rb
new file mode 100644
index 0000000..d4fe045
--- /dev/null
+++ b/selenium_cuc/features/step_definitions/aliases_steps.rb
@@ -0,0 +1,159 @@
+# -*- encoding : utf-8 -*-
+# Wikidata UI tests
+#
+# Author:: Tobias Gritschacher ([email protected])
+# License:: GNU GPL v2+
+#
+# steps for item aliases
+
+When /^I click the aliases add button$/ do
+  on(ItemPage).addAliases
+end
+
+When /^I click the aliases edit button$/ do
+  on(ItemPage).editAliases
+end
+
+When /^I click the aliases cancel button$/ do
+  on(ItemPage).cancelAliases
+end
+
+When /^I click the aliases save button$/ do
+  on(ItemPage) do |page|
+    page.saveAliases
+    page.wait_for_api_callback
+  end
+end
+
+When /^I click the remove first alias button$/ do
+  on(ItemPage).aliasesInputFirstRemove
+end
+
+When /^I press the ESC key in the new alias input field$/ do
+  on(ItemPage).aliasesInputEmpty_element.send_keys :escape
+end
+
+When /^I press the RETURN key in the new alias input field$/ do
+  on(ItemPage) do |page|
+    page.aliasesInputEmpty_element.send_keys :return
+    page.wait_for_api_callback
+  end
+end
+
+When /^I enter (.+) as new aliases$/ do |values|
+  on(ItemPage).add_aliases(eval("[#{values}]"))
+end
+
+When /^I change the first alias to (.+)$/ do |value|
+  on(ItemPage).aliasesInputFirst = value
+end
+
+When /^I change the duplicated alias to (.+)$/ do |value|
+  on(ItemPage) do |page|
+    page.aliasesInputEqual_element.clear
+    page.aliasesInputEqual = value
+  end
+  sleep 10
+end
+
+Then /^Aliases UI should be there$/ do
+  on(ItemPage) do |page|
+    page.aliasesDiv?.should be_true
+    page.aliasesTitle?.should be_true
+  end
+end
+
+Then /^Aliases add button should be there$/ do
+  on(ItemPage).addAliases?.should be_true
+end
+
+Then /^Aliases add button should not be there$/ do
+  on(ItemPage).addAliases_element.visible?.should be_false
+end
+
+Then /^Aliases edit button should be there$/ do
+  on(ItemPage).editAliases?.should be_true
+end
+
+Then /^Aliases edit button should not be there$/ do
+  on(ItemPage).editAliases?.should be_false
+end
+
+Then /^Aliases cancel button should be there$/ do
+  on(ItemPage).cancelAliases?.should be_true
+end
+
+Then /^Aliases cancel button should not be there$/ do
+  on(ItemPage).cancelAliases?.should be_false
+end
+
+Then /^Aliases save button should be there$/ do
+  on(ItemPage).saveAliases?.should be_true
+end
+
+Then /^Aliases save button should not be there$/ do
+  on(ItemPage).saveAliases?.should be_false
+end
+
+Then /^Aliases save button should be disabled$/ do
+  on(ItemPage) do |page|
+    page.saveAliases?.should be_false
+    page.saveAliasesDisabled?.should be_true
+  end
+end
+
+Then /^First remove alias button should be there$/ do
+  on(ItemPage).aliasesInputFirstRemove?.should be_true
+end
+
+Then /^First remove alias button should not be there$/ do
+  on(ItemPage).aliasesInputFirstRemove?.should be_false
+end
+
+Then /^New alias input field should be there$/ do
+  on(ItemPage).aliasesInputEmpty?.should be_true
+end
+
+Then /^New alias input field should not be there$/ do
+  on(ItemPage).aliasesInputEmpty?.should be_false
+end
+
+Then /^Modified alias input field should be there$/ do
+  on(ItemPage).aliasesInputModified?.should be_true
+end
+
+Then /^Modified alias input field should not be there$/ do
+  on(ItemPage).aliasesInputModified?.should be_false
+end
+
+Then /^Duplicate alias input field should be there$/ do
+  on(ItemPage).aliasesInputEqual?.should be_true
+end
+
+Then /^Duplicate alias input field should not be there$/ do
+  on(ItemPage).aliasesInputEqual?.should be_false
+end
+
+Then /^Aliases list should be empty$/ do
+  on(ItemPage).aliasesList?.should be_false
+end
+
+Then /^Aliases list should not be empty$/ do
+  on(ItemPage).aliasesList?.should be_true
+end
+
+Then /^Aliases help field should be there$/ do
+  on(ItemPage).aliasesHelpField?.should be_true
+end
+
+Then /^There should be (\d+) aliases in the list$/ do |num|
+  on(ItemPage).count_existing_aliases.should == num.to_i
+end
+
+Then /^List of aliases should be (.+)$/ do |values|
+  on(ItemPage).get_aliases.should == eval("[#{values}]")
+end
+
+Then /^First alias input field should contain (.+)$/ do |value|
+  on(ItemPage).aliasesInputFirst.should == value
+end
diff --git a/selenium_cuc/features/support/modules/alias_module.rb 
b/selenium_cuc/features/support/modules/alias_module.rb
index eff4e27..bd9cfb7 100644
--- a/selenium_cuc/features/support/modules/alias_module.rb
+++ b/selenium_cuc/features/support/modules/alias_module.rb
@@ -12,19 +12,27 @@
   div(:aliasesDiv, :class => "wb-aliases")
   span(:aliasesTitle, :class => "wb-aliases-label")
   unordered_list(:aliasesList, :class => "wb-aliases-container")
-  link(:addAliases, :xpath => "//div[contains(@class, 
'wb-aliases')]/span[contains(@class, 
'wb-ui-propertyedittool-toolbar')]/span/a[text()='add']")
-  span(:addAliasesDisabled, :xpath => "//div[contains(@class, 
'wb-aliases')]/span[contains(@class, 
'wb-ui-propertyedittool-toolbar')]/span/span")
-  link(:editAliases, :xpath => "//div[contains(@class, 
'wb-aliases')]/div/span[contains(@class, 
'wb-ui-propertyedittool-editablevalue')]/span/span/span/span/a[text()='edit']")
-  link(:saveAliases, :xpath => "//div[contains(@class, 
'wb-aliases')]/div/span[contains(@class, 
'wb-ui-propertyedittool-editablevalue')]/span/span/span/span/a[text()='save']")
-  link(:cancelAliases, :xpath => "//div[contains(@class, 
'wb-aliases')]/div/span[contains(@class, 
'wb-ui-propertyedittool-editablevalue')]/span/span/span/span/a[text()='cancel']")
-  text_field(:aliasesInputFirst, :xpath => "//li[contains(@class, 
'wb-aliases-alias')]/span/input")
-  link(:aliasesInputFirstRemove, :xpath => "//li[contains(@class, 
'wb-aliases-alias')]/a[contains(@class, 'tagadata-close')]")
-  text_field(:aliasesInputEmpty, :xpath => "//li[contains(@class, 
'tagadata-choice-empty')]/span/input")
-  text_field(:aliasesInputModified, :xpath => "//li[contains(@class, 
'tagadata-choice-modified')]/span/input")
-  text_field(:aliasesInputEqual, :xpath => "//li[contains(@class, 
'tagadata-choice-equal')]/span/input")
-  link(:aliasesInputRemove, :xpath => "//li[contains(@class, 
'tagadata-choice-modified')]/a[contains(@class, 'tagadata-close')]")
+  link(:addAliases,    :css => "div.wb-aliases 
a.wb-ui-propertyedittool-toolbarbutton-addbutton:not(.wikibase-toolbarbutton-disabled)")
+  link(:editAliases, :css => "div.wb-aliases 
a.wikibase-toolbareditgroup-editbutton:not(.wikibase-toolbarbutton-disabled)")
+  link(:saveAliases, :css => "div.wb-aliases 
a.wikibase-toolbareditgroup-savebutton:not(.wikibase-toolbarbutton-disabled)")
+  link(:saveAliasesDisabled, :css => "div.wb-aliases 
a.wikibase-toolbareditgroup-savebutton.wikibase-toolbarbutton-disabled")
+  link(:cancelAliases, :css => "div.wb-aliases 
a.wikibase-toolbareditgroup-cancelbutton:not(.wikibase-toolbarbutton-disabled)")
+  text_field(:aliasesInputFirst, :xpath => "//div[contains(@class, 
'wb-ui-aliasesedittool')]//li[contains(@class, 'wb-aliases-alias')]//input")
+  link(:aliasesInputFirstRemove, :css => "div.wb-aliases a.tagadata-close")
+  text_field(:aliasesInputEmpty, :xpath => "//div[contains(@class, 
'wb-ui-aliasesedittool')]//li[contains(@class, 
'tagadata-choice-empty')]//input")
+  text_field(:aliasesInputModified, :xpath => "//div[contains(@class, 
'wb-ui-aliasesedittool')]//li[contains(@class, 
'tagadata-choice-modified')]//input")
+  text_field(:aliasesInputEqual, :xpath => "//div[contains(@class, 
'wb-ui-aliasesedittool')]//li[contains(@class, 
'tagadata-choice-equal')]//input")
+  span(:aliasesHelpField, :css => "div.wb-aliases span.mw-help-field-hint")
 
   # aliases methods
+  def get_aliases
+    aliases = Array.new
+    aliasesList_element.each do |aliasElem|
+      aliases.push(aliasElem.text)
+    end
+    aliases
+  end
+
   def count_existing_aliases
     count = 0
     if aliasesList? == false
@@ -36,26 +44,10 @@
     count
   end
 
-  def get_nth_alias n
-    count = 1
-    if aliasesList_element.exists?
-      aliasesList_element.each do |aliasElem|
-        if count == n
-          return aliasElem
-        end
-        count = count+1
-      end
-    end
-    false
-  end
-
   def add_aliases(aliases)
-    addAliases
     aliases.each do |ali|
       self.aliasesInputEmpty= ali
     end
-    saveAliases
-    ajax_wait
-    wait_for_api_callback
   end
+
 end

-- 
To view, visit https://gerrit.wikimedia.org/r/83089
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaeb4acbe0e6e7575804a48d05999be4a89bbe091
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[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

Reply via email to