jenkins-bot has submitted this change and it was merged.

Change subject: Use WikibaseAPI to create new entities for selenium tests
......................................................................


Use WikibaseAPI to create new entities for selenium tests

Change-Id: Iea0982751c61236408479741c8e2fc08878ca541
---
M selenium_cuc/Gemfile
M selenium_cuc/Gemfile.lock
M selenium_cuc/features/steps/label_steps.rb
M selenium_cuc/features/support/env.rb
M selenium_cuc/features/support/modules/url_module.rb
M selenium_cuc/features/support/pages/item_page.rb
M selenium_cuc/features/support/utils/utils.rb
7 files changed, 68 insertions(+), 11 deletions(-)

Approvals:
  Zfilipin: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/selenium_cuc/Gemfile b/selenium_cuc/Gemfile
index 33c4b3b..6bb1726 100644
--- a/selenium_cuc/Gemfile
+++ b/selenium_cuc/Gemfile
@@ -9,4 +9,5 @@
 gem 'syntax'
 gem 'parallel_tests'
 gem 'cucumber'
-gem 'json', '~> 1.7.7'
+gem 'json'
+gem 'activesupport'
diff --git a/selenium_cuc/Gemfile.lock b/selenium_cuc/Gemfile.lock
index fee6607..52d094c 100644
--- a/selenium_cuc/Gemfile.lock
+++ b/selenium_cuc/Gemfile.lock
@@ -1,6 +1,13 @@
 GEM
   remote: https://rubygems.org/
   specs:
+    activesupport (4.0.0)
+      i18n (~> 0.6, >= 0.6.4)
+      minitest (~> 4.2)
+      multi_json (~> 1.3)
+      thread_safe (~> 0.1)
+      tzinfo (~> 0.3.37)
+    atomic (1.1.13)
     builder (3.2.0)
     childprocess (0.3.9)
       ffi (~> 1.0, >= 1.0.11)
@@ -20,6 +27,7 @@
       multi_json (~> 1.3)
     i18n (0.6.4)
     json (1.7.7)
+    minitest (4.3.2)
     multi_json (1.7.3)
     page-object (0.8.10)
       page_navigation (>= 0.8)
@@ -48,6 +56,9 @@
       rubyzip
       websocket (~> 1.0.4)
     syntax (1.0.0)
+    thread_safe (0.1.2)
+      atomic
+    tzinfo (0.3.37)
     watir-webdriver (0.6.4)
       selenium-webdriver (>= 2.18.0)
     websocket (1.0.7)
@@ -57,8 +68,9 @@
   x86-mingw32
 
 DEPENDENCIES
+  activesupport
   cucumber
-  json (~> 1.7.7)
+  json
   page-object
   parallel_tests
   rake
diff --git a/selenium_cuc/features/steps/label_steps.rb 
b/selenium_cuc/features/steps/label_steps.rb
index e9cb1a4..738fa33 100644
--- a/selenium_cuc/features/steps/label_steps.rb
+++ b/selenium_cuc/features/steps/label_steps.rb
@@ -9,7 +9,9 @@
 label = generate_random_string(8)
 
 Given /^I am on an entity page$/ do
-  visit(CreateItemPage).create_new_item(label, generate_random_string(20))
+  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
diff --git a/selenium_cuc/features/support/env.rb 
b/selenium_cuc/features/support/env.rb
index 0afa83d..1b11a33 100644
--- a/selenium_cuc/features/support/env.rb
+++ b/selenium_cuc/features/support/env.rb
@@ -14,6 +14,8 @@
 require 'page-object/page_factory'
 require 'watir-webdriver'
 require 'yaml'
+require 'net/http'
+require 'active_support/all'
 require 'require_all'
 
 config = YAML.load_file('config/config.yml')
diff --git a/selenium_cuc/features/support/modules/url_module.rb 
b/selenium_cuc/features/support/modules/url_module.rb
index 69ba144..9fcaecf 100644
--- a/selenium_cuc/features/support/modules/url_module.rb
+++ b/selenium_cuc/features/support/modules/url_module.rb
@@ -11,19 +11,28 @@
 module URL
   def self.client_url(name)
     if ENV['WIKIDATA_CLIENT_URL']
-      wikidata_url = ENV['WIKIDATA_CLIENT_URL']
+      url = ENV['WIKIDATA_CLIENT_URL']
     else
-      wikidata_url = WIKIDATA_CLIENT_URL
+      url = WIKIDATA_CLIENT_URL
     end
-    "#{wikidata_url}#{name}"
+    "#{url}#{name}"
   end
 
   def self.repo_url(name)
     if ENV['WIKIDATA_REPO_URL']
-      wikidata_url = ENV['WIKIDATA_REPO_URL']
+      url = ENV['WIKIDATA_REPO_URL']
     else
-      wikidata_url = WIKIDATA_REPO_URL
+      url = WIKIDATA_REPO_URL
     end
-    "#{wikidata_url}#{name}"
+    "#{url}#{name}"
+  end
+
+  def self.repo_api()
+    if ENV['WIKIDATA_REPO_URL']
+      url = ENV['WIKIDATA_REPO_API']
+    else
+      url = WIKIDATA_REPO_API
+    end
+    "#{url}"
   end
 end
diff --git a/selenium_cuc/features/support/pages/item_page.rb 
b/selenium_cuc/features/support/pages/item_page.rb
index b6d2764..51fb6e6 100644
--- a/selenium_cuc/features/support/pages/item_page.rb
+++ b/selenium_cuc/features/support/pages/item_page.rb
@@ -14,8 +14,9 @@
 
   # ***** METHODS *****
   # item url navigation
-  def navigate_to_item
-    navigate_to @@item_url
+  def navigate_to_item url
+    navigate_to url
+    wait_for_entity_to_load
   end
 
   def navigate_to_item_en
diff --git a/selenium_cuc/features/support/utils/utils.rb 
b/selenium_cuc/features/support/utils/utils.rb
index be21639..7065aa8 100644
--- a/selenium_cuc/features/support/utils/utils.rb
+++ b/selenium_cuc/features/support/utils/utils.rb
@@ -6,10 +6,40 @@
 #
 # common used methods
 
+include URL
+
 # creates a random string
 def generate_random_string(length=8)
   chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
   string = ''
   length.times { string << chars[rand(chars.size)] }
   return string
+end
+
+# creates a new entity via the API
+def create_new_entity(data, type = 'item')
+  uri = URI(URL.repo_api)
+
+  request = Net::HTTP::Post.new(uri.to_s)
+  request.set_form_data(
+    'action' => 'wbeditentity',
+    'token' => '+\\',
+    'new' => type,
+    'data' => data,
+    'format' => 'json',
+    'summary' => 'entity created by selenium test'
+  )
+
+  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
+    http.request(request)
+  end
+  resp = ActiveSupport::JSON.decode(response.body)
+
+  if resp["success"] != 1
+    abort("Failed to create new entity: API error")
+  end
+
+  id = resp["entity"]["id"]
+  url = URL.repo_url(id)
+  return {"id" => id, "url" => url}
 end
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iea0982751c61236408479741c8e2fc08878ca541
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: Zfilipin <zfili...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to