Tobias Gritschacher has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337577 )
Change subject: Login when creating new items in browsertests
......................................................................
Login when creating new items in browsertests
Bug: T157050
Change-Id: I34412e37a5ccc8d5fc37dc657b195653e4c64543
---
M tests/browser/features/step_definitions/entity_steps.rb
M tests/browser/features/support/pages/item_page.rb
2 files changed, 106 insertions(+), 90 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/77/337577/1
diff --git a/tests/browser/features/step_definitions/entity_steps.rb
b/tests/browser/features/step_definitions/entity_steps.rb
index 80ebf6a..2b6ea05 100644
--- a/tests/browser/features/step_definitions/entity_steps.rb
+++ b/tests/browser/features/step_definitions/entity_steps.rb
@@ -7,124 +7,140 @@
# basic steps for entities
Given(/^I am logged in to the repo$/) do
- as_user(:b) do
- visit(RepoLoginPage).login_with(user(:b), password(:b))
- end
+ as_user(:b) do
+ visit(RepoLoginPage).login_with(user(:b), password(:b))
+ end
end
Given(/^I am not logged in to the repo$/) do
- visit(RepoLogoutPage)
+ 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'
+ 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) + '"'
+ 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 ""'
+ 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) + '"'
+ 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
+ (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 = visit(ItemPage).create_item(item_data)
+ item_data = '{"labels":{"en":{"language":"en","value":"' + label +
'"}},"descriptions":{"en":{"language":"en","value":"' + description + '"}}}'
+
+ wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ as_user(:b) do
+ wb_api.log_in(user(:b), password(:b))
+ end
+
+ @item_under_test = visit(ItemPage).create_item(item_data, wb_api)
end
Given(/^I am on the page of the item to test$/) do
- on(ItemPage).navigate_to_entity @item_under_test['url']
+ 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']
+ 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
- visit(ItemPage).navigate_to_entity entity_url
- @item_under_test = on(ItemPage).create_item_data_from_page
+ entity_url = URL.repo_url(ENV['ITEM_NAMESPACE'] + item_id) + '&debug='
+ debug_mode
+ visit(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
- visit(ItemPage).navigate_to_entity entity_url
- @item_under_test = on(ItemPage).create_item_data_from_page
+ entity_url = URL.repo_url(ENV['PROPERTY_NAMESPACE'] + property_id) +
'&debug=' + debug_mode
+ visit(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)
- visit(ItemPage).navigate_to_entity entity_url
- @item_under_test = on(ItemPage).create_item_data_from_page
+ entity_url = URL.repo_url(ENV['PROPERTY_NAMESPACE'] + property_id)
+ visit(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']
+ step 'I navigate to property id ' + @properties[handle]['id']
end
Given(/^I have the following properties with datatype:$/) do |props|
- property_data = on(PropertyPage).create_property_data(props)
- wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ property_data = on(PropertyPage).create_property_data(props)
- as_user(:b) do
- wb_api.log_in(user(:b), password(:b))
- end
+ wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ as_user(:b) do
+ wb_api.log_in(user(:b), password(:b))
+ end
- @properties = on(PropertyPage).create_properties(property_data, wb_api)
+ @properties = on(PropertyPage).create_properties(property_data, wb_api)
end
Given(/^I have the following items:$/) do |handles|
- @items = visit(ItemPage).create_items(handles)
+ wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ as_user(:b) do
+ wb_api.log_in(user(:b), password(:b))
+ end
+
+ @items = visit(ItemPage).create_items(handles, wb_api)
end
Given(/^I have the following empty items:$/) do |handles|
- @items = visit(ItemPage).create_items(handles, true)
+ wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ as_user(:b) do
+ wb_api.log_in(user(:b), password(:b))
+ end
+
+ @items = visit(ItemPage).create_items(handles, wb_api, true)
end
Given(/^The copyright warning has been dismissed$/) do
- on(ItemPage).set_copyright_ack_cookie
+ on(ItemPage).set_copyright_ack_cookie
end
Given(/^Anonymous edit warnings are disabled$/) do
- on(ItemPage).set_noanonymouseditwarning_cookie
+ 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'
+ 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 = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
- as_user(:b) do
- wb_api.log_in(user(:b), password(:b))
- end
+ as_user(:b) do
+ wb_api.log_in(user(:b), password(:b))
+ end
- 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
+ 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
+ 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
+ browser.refresh
+ on(ItemPage).wait_for_entity_to_load
end
diff --git a/tests/browser/features/support/pages/item_page.rb
b/tests/browser/features/support/pages/item_page.rb
index 4dc63e2..0566ac9 100644
--- a/tests/browser/features/support/pages/item_page.rb
+++ b/tests/browser/features/support/pages/item_page.rb
@@ -7,54 +7,54 @@
# page object for item page
class ItemPage
- include PageObject
- include EntityPage
+ include PageObject
+ include EntityPage
- def create_item_data(handles, empty = false)
- item_data = {}
- handles.raw.each do |handle|
- handle = handle[0]
- label = empty ? '' : generate_random_string(8)
- description = empty ? '' : generate_random_string(20)
- data = '{"labels":{"en":{"language":"en","value":"' + label +
- '"}},"descriptions":{"en":{"language":"en","value":"' +
description + '"}}}'
- item_data[handle] = data
- end
+ def create_item_data(handles, empty = false)
+ item_data = {}
+ handles.raw.each do |handle|
+ handle = handle[0]
+ label = empty ? '' : generate_random_string(8)
+ description = empty ? '' : generate_random_string(20)
+ data = '{"labels":{"en":{"language":"en","value":"' +
label +
+
'"}},"descriptions":{"en":{"language":"en","value":"' + description + '"}}}'
+ item_data[handle] = data
+ end
- item_data
- end
+ item_data
+ end
- def create_item(data)
- wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
- resp = wb_api.create_item(data)
+ def create_item(data, wb_api)
+ wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
+ resp = wb_api.create_item(data)
- id = resp['entity']['id']
+ id = resp['entity']['id']
- if resp['entity']['labels'].length > 0 && resp['entity']['labels']['en']
- label_en = resp['entity']['labels']['en']['value']
- else
- label_en = ''
- end
+ if resp['entity']['labels'].length > 0 &&
resp['entity']['labels']['en']
+ label_en = resp['entity']['labels']['en']['value']
+ else
+ label_en = ''
+ end
- if resp['entity']['descriptions'].length > 0 &&
resp['entity']['descriptions']['en']
- description_en = resp['entity']['descriptions']['en']['value']
- else
- description_en = ''
- end
+ if resp['entity']['descriptions'].length > 0 &&
resp['entity']['descriptions']['en']
+ description_en =
resp['entity']['descriptions']['en']['value']
+ else
+ description_en = ''
+ end
- url = URL.repo_url(ENV['ITEM_NAMESPACE'] + id)
+ url = URL.repo_url(ENV['ITEM_NAMESPACE'] + id)
- { 'id' => id, 'url' => url, 'label' => label_en, 'description' =>
description_en }
- end
+ { 'id' => id, 'url' => url, 'label' => label_en, 'description'
=> description_en }
+ end
- def create_items(handles, empty = false)
- item_data = create_item_data(handles, empty)
- items = {}
- item_data.each do |handle, data|
- item = create_item(data)
- items[handle] = item
- end
+ def create_items(handles, wb_api, empty = false)
+ item_data = create_item_data(handles, empty)
+ items = {}
+ item_data.each do |handle, data|
+ item = create_item(data, wb_api)
+ items[handle] = item
+ end
- items
- end
+ items
+ end
end
--
To view, visit https://gerrit.wikimedia.org/r/337577
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I34412e37a5ccc8d5fc37dc657b195653e4c64543
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