diff --git a/tests/browser/features/statements_item.feature b/tests/browser/features/statements_item.feature index f5d9367..819516e 100644 --- a/tests/browser/features/statements_item.feature +++ b/tests/browser/features/statements_item.feature @@ -1,37 +1,52 @@ # Wikidata UI tests # # Author:: Tobias Gritschacher (tobias.gritschacher@wikimedia.de) # License:: GNU GPL v2+ # # feature definition for item type statements tests @chrome @firefox @internet_explorer_10 @internet_explorer_11 @local_config @wikidata.beta.wmflabs.org Feature: Creating statements of type item Background: Given I am on an item page And The copyright warning has been dismissed And Anonymous edit warnings are disabled @modify_entity @repo_login Scenario Outline: Adding a statement of type item Given I have the following properties with datatype: | itemprop | wikibase-item | Given I have the following items: | item1 | When I click the statement add button And I select the claim property itemprop And I enter the label of item as claim value And I Then Statement add button should be there And Statement cancel button should not be there And Statement save button should not be there And Claim entity selector input element should not be there And Claim value input element should not be there And Statement edit button for claim 1 in group 1 should be there And Statement name of group 1 should be the label of itemprop And Statement value of claim 1 in group 1 should be the label of item Examples: | item | save | | item1 | click the statement save button | + + @ui_only @repo_login + Scenario: Select a property, use entity selector + Given I have the following properties with datatype: + | itemprop | wikibase-item | + And I have 3 items beginning with "q" + When I click the statement add button + And I select the claim property itemprop + And I enter q in the claim value input field + And I press the ARROWDOWN key in the claim value input field + And I press the ARROWDOWN key in the claim value input field + And I press the RETURN key in the claim value input field + And I memorize the value of the the claim value input field + And I press the RETURN key in the claim value input field + Then Statement value of claim 1 in group 1 should be what I memorized diff --git a/tests/browser/features/step_definitions/entity_steps.rb b/tests/browser/features/step_definitions/entity_steps.rb index ed02ce2..96dbd58 100644 --- a/tests/browser/features/step_definitions/entity_steps.rb +++ b/tests/browser/features/step_definitions/entity_steps.rb @@ -1,111 +1,117 @@ # -*- encoding : utf-8 -*- # Wikidata UI tests # # Author:: Tobias Gritschacher (tobias.gritschacher@wikimedia.de) # License:: GNU GPL v2+ # # basic steps for entities Given(/^I am logged in to the repo$/) do visit(RepoLoginPage).login_with(ENV['WB_REPO_USERNAME'], ENV['WB_REPO_PASSWORD']) end Given(/^I am not logged in to the repo$/) do visit(RepoLogoutPage) end Given(/^I am on an item page$/) do step 'I have an item to test' step 'I am on the page of the item to test' end Given(/^I have an item to test$/) do step 'I have an item with label "' + generate_random_string(8) + '" and description "' + generate_random_string(20) + '"' end Given(/^I have an item with empty label and description$/) do step 'I have an item with label "" and description ""' end Given(/^I have an item with label "([^"]*)"$/) do |label| step 'I have an item with label "' + label + '" and description "' + generate_random_string(20) + '"' end +Given(/^I have (\d+) items beginning with "([^"]*)"$/) do |num, pre| + (1..num.to_i).each do + step 'I have an item with label "' + pre + generate_random_string(5) + '" and description "' + generate_random_string(20) + '"' + end +end + Given(/^I have an item with label "(.*)" and description "(.*)"$/) do |label, description| item_data = '{"labels":{"en":{"language":"en","value":"' + label + '"}},"descriptions":{"en":{"language":"en","value":"' + description + '"}}}' @item_under_test = on(ItemPage).create_item(item_data) end Given(/^I am on the page of the item to test$/) do on(ItemPage).navigate_to_entity @item_under_test['url'] end Given(/^I am on the page of item (.*)$/) do |item_handle| on(ItemPage).navigate_to_entity @items[item_handle]['url'] end Given(/^I navigate to item (.*) with resource loader debug mode (.*)$/) do |item_id, debug_mode| entity_url = URL.repo_url(ENV['ITEM_NAMESPACE'] + item_id) + '&debug=' + debug_mode on(ItemPage).navigate_to_entity entity_url @item_under_test = on(ItemPage).create_item_data_from_page end Given(/^I navigate to property (.*) with resource loader debug mode (.*)$/) do |property_id, debug_mode| entity_url = URL.repo_url(ENV['PROPERTY_NAMESPACE'] + property_id) + '&debug=' + debug_mode on(ItemPage).navigate_to_entity entity_url @item_under_test = on(ItemPage).create_item_data_from_page end Given(/^I navigate to property id (.*)$/) do |property_id| entity_url = URL.repo_url(ENV['PROPERTY_NAMESPACE'] + property_id) on(ItemPage).navigate_to_entity entity_url @item_under_test = on(ItemPage).create_item_data_from_page end Given(/^I navigate to property handle (.*)$/) do |handle| step 'I navigate to property id ' + @properties[handle]['id'] end Given(/^I have the following properties with datatype:$/) do |props| @properties = on(PropertyPage).create_properties(props) end Given(/^I have the following items:$/) do |handles| @items = on(ItemPage).create_items(handles) end Given(/^I have the following empty items:$/) do |handles| @items = on(ItemPage).create_items(handles, true) end Given(/^The copyright warning has been dismissed$/) do on(ItemPage).set_copyright_ack_cookie end Given(/^Anonymous edit warnings are disabled$/) do on(ItemPage).set_noanonymouseditwarning_cookie end Given(/^I am on an item page with empty label and description$/) do step 'I have an item with empty label and description' step 'I am on the page of the item to test' end Given(/^The following sitelinks do not exist:$/) do |sitelinks| wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api wb_api.log_in(ENV['WB_REPO_USERNAME'], ENV['WB_REPO_PASSWORD']) sitelinks.raw.each do |sitelink| if wb_api.sitelink_exists?(sitelink[0], sitelink[1]) wb_api.remove_sitelink({ site_id: sitelink[0], title: sitelink[1] }, sitelink[0]) end end end Then(/^An error message should be displayed$/) do expect(on(ItemPage).wb_error_div?).to be true end When(/^I reload the page$/) do @browser.refresh on(ItemPage).wait_for_entity_to_load end diff --git a/tests/browser/features/step_definitions/statement_steps.rb b/tests/browser/features/step_definitions/statement_steps.rb index 88f21d9..6f07727 100644 --- a/tests/browser/features/step_definitions/statement_steps.rb +++ b/tests/browser/features/step_definitions/statement_steps.rb @@ -1,281 +1,293 @@ # -*- encoding : utf-8 -*- # Wikidata UI tests # # Author:: Tobias Gritschacher (tobias.gritschacher@wikimedia.de) # License:: GNU GPL v2+ # # tests for statements When(/^I have statements with the following properties and values:$/) do |statements| wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api wb_api.log_in(ENV['WB_REPO_USERNAME'], ENV['WB_REPO_PASSWORD']) statements.raw.each do |statement| property_handle = statement[0] value = on(ItemPage).get_string_snak_value(statement[1]) wb_api.create_claim(@item_under_test['id'], 'value', @properties[property_handle]['id'], value) end end When(/^I click the statement add button$/) do on(ItemPage).add_statement end When(/^I click the statement cancel button$/) do on(ItemPage).cancel_statement end When(/^I click the statement save button$/) do on(ItemPage) do |page| page.save_statement page.ajax_wait page.wait_for_statement_request_finished end end When(/^I select the claim property (.+)$/) do |handle| on(ItemPage) do |page| page.select_claim_property(@properties[handle]['label']) page.wait_for_claim_value_box end end When(/^I select the snak property (.+)$/) do |handle| on(ItemPage) do |page| page.select_snak_property(@properties[handle]['label']) page.wait_for_snak_value_box end end When(/^I enter (.+) in the claim property input field$/) do |value| on(ItemPage) do |page| page.claim_entity_selector_input_element.when_visible.click page.claim_entity_selector_input = value page.ajax_wait end end When(/^I enter (.+) in the claim value input field$/) do |value| on(ItemPage) do |page| page.claim_value_input_field_element.when_visible.click page.claim_value_input_field = value page.ajax_wait end end When(/^I enter (.+) in the InputExtender input field$/) do |value| on(ItemPage) do |page| page.inputextender_input_element.when_visible.click page.inputextender_input = value page.ajax_wait end end When(/^I click the InputExtender dropdown first element$/) do on(ItemPage).inputextender_dropdown_first_element.when_visible.click on(ItemPage).ajax_wait end When(/^I enter (.+) as string snak value$/) do |value| on(ItemPage) do |page| page.snak_value_input_field_wd.clear page.snak_value_input_field_wd.send_keys value page.ajax_wait end end When(/^I enter the label of item (.+) as claim value$/) do |handle| step "I enter #{@items[handle]['label']} in the claim value input field" end When(/^I enter a too long string as claim value$/) do step 'I enter looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong in the claim value input field' end When(/^I enter the label of item (.+) as snak value$/) do |handle| step "I enter #{@items[handle]['label']} as string snak value" end When(/^I enter a too long string as snak value$/) do step 'I enter looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong as string snak value' end When(/^I press the ESC key in the claim value input field$/) do on(ItemPage).claim_value_input_field_element.send_keys :escape end +When(/^I press the ARROWDOWN key in the claim value input field$/) do + on(ItemPage).claim_value_input_field_element.send_keys :arrow_down +end + When(/^I press the ESC key in the snak value input field$/) do on(ItemPage).snak_value_input_field_wd.send_keys :escape end When(/^I press the RETURN key in the claim value input field$/) do on(ItemPage) do |page| page.claim_value_input_field_element.send_keys :enter page.ajax_wait page.wait_for_statement_request_finished end end When(/^I press the RETURN key in the snak value input field$/) do on(ItemPage) do |page| page.snak_value_input_field_wd.send_keys :enter page.ajax_wait page.wait_for_statement_request_finished end end When(/^I wait for the statement save button$/) do on(ItemPage).wait_for_statement_save_button end When(/^I edit claim (\d+) in group (\d+)$/) do |claim_index, group_index| on(ItemPage) do |page| page.edit_claim_element(group_index, claim_index).when_visible.click page.ajax_wait end end +When(/^I memorize the value of the the claim value input field$/) do + @memorized_label = on(ItemPage).claim_value_input_field_element.value +end + Then(/^Statements heading should be there$/) do expect(on(ItemPage).statements_heading?).to be true end Then(/^Statements heading should not be there$/) do expect(on(ItemPage).statements_heading?).to be false end Then(/^Statement help field should be there$/) do expect(on(ItemPage).statement_help_field?).to be true end Then(/^Statement add button should be there$/) do expect(on(ItemPage).add_statement?).to be true end Then(/^Statement add button should not be there$/) do expect(on(ItemPage).add_statement?).to be false end Then(/^Statement add button should be disabled$/) do on(ItemPage) do |page| expect(page.add_statement?).to be false expect(page.add_statement_disabled?).to be true end end Then(/^Statement edit button for claim (.+) in group (.+) should be there$/) do |claim_index, group_index| expect(on(ItemPage).edit_claim_element(group_index, claim_index).when_present).to be_present end Then(/^Statement add button for group (.+) should be there$/) do |group_index| expect(on(ItemPage).add_claim_element(group_index).when_present).to be_present end Then(/^Statement save button should be there$/) do expect(on(ItemPage).save_statement?).to be true end Then(/^Statement save button should not be there$/) do expect(on(ItemPage).save_statement?).to be false end Then(/^Statement save button should be disabled$/) do on(ItemPage) do |page| expect(page.save_statement?).to be false expect(page.save_statement_disabled?).to be true end end Then(/^Statement cancel button should be there$/) do expect(on(ItemPage).cancel_statement?).to be true end Then(/^Statement cancel button should not be there$/) do expect(on(ItemPage).cancel_statement?).to be false end Then(/^Claim value input element should be there$/) do expect(on(ItemPage).claim_value_input_field?).to be true end Then(/^Claim value input element should not be there$/) do expect(on(ItemPage).claim_value_input_field?).to be false end Then(/^Snak value input element should be there$/) do expect(on(ItemPage).snak_value_input_field.present?).to be true end Then(/^Snak value input element should not be there$/) do expect(on(ItemPage).snak_value_input_field.present?).to be false end Then(/^Statement name of group (.+) should be the label of (.+)$/) do |group_index, handle| expect(on(ItemPage).statement_name_element(group_index).when_visible.text).to eq @properties[handle]['label'] end Then(/^Statement string value of claim (.+) in group (.+) should be (.+)$/) do |claim_index, group_index, value| expect(on(ItemPage).claim_value_string(group_index, claim_index).when_visible.text).to eq value end Then(/^Statement value of claim (.+) in group (.+) should be the label of item (.+)$/) do |claim_index, group_index, handle| expect(on(ItemPage).claim_value_link(group_index, claim_index).when_visible.text).to eq @items[handle]['label'] end +Then(/^Statement value of claim (.+) in group (.+) should be what I memorized$/) do |claim_index, group_index| + expect(on(ItemPage).claim_value_link(group_index, claim_index).when_visible.text).to eq @memorized_label +end + Then(/^Snaktype (.+) should be shown for claim (\d+) in group (\d+)$/) do |snaktype, claim_index, group_index| expect(on(ItemPage).claim_snaktype(group_index, claim_index, snaktype).when_present).to be_present end Then(/^Statement link element of claim (.+) in group (.+) should be there$/) do |claim_index, group_index| expect(on(ItemPage).claim_value_link(group_index, claim_index).when_present).to be_present end Then(/^Statement link text of claim (.+) in group (.+) should be (.+)$/) do |claim_index, group_index, value| expect(on(ItemPage).claim_value_link(group_index, claim_index).when_visible.text).to eq value end Then(/^Statement link url of claim (.+) in group (.+) should be (.+)$/) do |claim_index, group_index, value| expect(on(ItemPage).claim_value_link(group_index, claim_index).when_visible.attribute('href')).to eq value end When(/^I click the InputExtender toggler link$/) do on(ItemPage).inputextender_toggler_element.when_visible.click end Then(/^(.*) should be displayed in the InputExtender preview$/) do |preview| expect(on(ItemPage).inputextender_preview_element.when_present.text).to eq preview end Then(/^(.*) should be the time precision setting$/) do |precision| expect(on(ItemPage).time_precision_element.when_present.text).to eq precision end Then(/^(.*) should be the time calendar setting$/) do |calendar| expect(on(ItemPage).time_calendar_element.when_present.text).to eq calendar end Then(/^Time precision chooser should be there$/) do expect(on(ItemPage).time_precision_element.when_visible).to be_visible end Then(/^Time calendar chooser should be there$/) do expect(on(ItemPage).time_calendar_element.when_visible).to be_visible end Then(/^InputExtender preview should be there$/) do expect(on(ItemPage).inputextender_preview_element.when_visible).to be_visible end Then(/^InputExtender input should be there$/) do expect(on(ItemPage).inputextender_input_element.when_visible).to be_visible end Then(/^Geo precision chooser should be there$/) do expect(on(ItemPage).geo_precision_element.when_visible).to be_visible end Then(/^(.*) should be the geo precision setting$/) do |precision| expect(on(ItemPage).geo_precision_element.when_present.text).to eq precision end Then(/^InputExtender dropdown should be there$/) do expect(on(ItemPage).inputextender_dropdown_element.when_visible).to be_visible end