[Bug] fix no implicit conversion of String into Integer (TypeError) in browsertests
Closed, ResolvedPublic

Description

Fix no implicit conversion of String into Integer (TypeError) in browsertests.

First appeared in: https://integration.wikimedia.org/ci/view/BrowserTests/view/Wikidata/job/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/332/consoleFull
Also happens in chrome variant.

01:22:11 Feature: Edit aliases
01:22:11 
01:22:11   Background:                                    # features/aliases.feature:11
01:22:20     Given I am on an item page                   # features/step_definitions/entity_steps.rb:17
01:22:20       no implicit conversion of String into Integer (TypeError)
01:22:20       /mnt/jenkins-workspace/workspace/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/tests/browser/features/support/pages/item_page.rb:34:in `[]'
01:22:20       /mnt/jenkins-workspace/workspace/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/tests/browser/features/support/pages/item_page.rb:34:in `create_item'
01:22:20       /mnt/jenkins-workspace/workspace/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/tests/browser/features/step_definitions/entity_steps.rb:42:in `block in <top (required)>'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/step_match.rb:25:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/runtime/support_code.rb:60:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_world.rb:52:in `step'
01:22:20       /mnt/jenkins-workspace/workspace/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/tests/browser/features/step_definitions/entity_steps.rb:23:in `block in <top (required)>'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/step_match.rb:25:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/runtime/support_code.rb:60:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_world.rb:52:in `step'
01:22:20       /mnt/jenkins-workspace/workspace/browsertests-Wikidata-WikidataTests-linux-firefox-sauce/tests/browser/features/step_definitions/entity_steps.rb:18:in `block in <top (required)>'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/step_match.rb:25:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/step_invocation.rb:60:in `invoke'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/step_invocation.rb:38:in `accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:106:in `block in visit_step'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:105:in `visit_step'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/step_collection.rb:19:in `block in accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/step_collection.rb:18:in `each'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/step_collection.rb:18:in `accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:100:in `block in visit_steps'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:99:in `visit_steps'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/background.rb:44:in `block in accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/background.rb:54:in `block in with_visitor'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/background.rb:53:in `with_visitor'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/background.rb:41:in `accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:64:in `block in visit_background'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:63:in `visit_background'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/feature.rb:36:in `accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/features.rb:28:in `block in accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/features.rb:17:in `each'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/features.rb:17:in `each'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/features.rb:27:in `accept'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/runtime.rb:49:in `run!'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/lib/cucumber/cli/main.rb:47:in `execute!'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/gems/cucumber-1.3.20/bin/cucumber:13:in `<top (required)>'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/bin/cucumber:23:in `load'
01:22:20       /mnt/home/jenkins-deploy/.gem/2.0.0/bin/cucumber:23:in `<main>'
01:22:20       features/aliases.feature:12:in `Given I am on an item page'

I have managed to reproduce it locally, with this config.yml

# beta instance configuration
WIKIDATA_REPO_URL: "http://wikidata.beta.wmflabs.org/wiki/"
WIKIDATA_REPO_API: "http://wikidata.beta.wmflabs.org/w/api.php"
WB_REPO_USERNAME: "Selenium_user"
WB_REPO_PASSWORD: "not-the-real-one"

# the namespace of the data items (e.g. "Data:" or "" for main namespace)
ITEM_NAMESPACE: ""
PROPERTY_NAMESPACE: "Property:"
ITEM_ID_PREFIX: "Q"
PROPERTY_ID_PREFIX: "P"
LANGUAGE_CODE: "en"

# local browser configuration
BROWSER: "firefox"
$ bundle exec cucumber features/sitelinks.feature:123
# Wikidata UI tests
#
# Author:: Tobias Gritschacher (tobias.gritschacher@wikimedia.de)
# License:: GNU GPL v2+
#
# feature definition for item sitelinks tests
@chrome @firefox @internet_explorer_10 @internet_explorer_11 @local_config @wikidata.beta.wmflabs.org
Feature: Edit sitelinks

  Background:                                    # features/sitelinks.feature:11
    Given I am on an item page                   # features/step_definitions/entity_steps.rb:17
    And The copyright warning has been dismissed # features/step_definitions/entity_steps.rb:87
    And Anonymous edit warnings are disabled     # features/step_definitions/entity_steps.rb:91

  @modify_entity @save_sitelink @smoke
  Scenario Outline: Save sitelink                # features/sitelinks.feature:112
    Given The following sitelinks do not exist:  # features/step_definitions/entity_steps.rb:100
      | enwiki | Asia |
    When I click the sitelink edit button        # features/step_definitions/sitelinks_steps.rb:13
    And I type en into the 1. siteid input field # features/step_definitions/sitelinks_steps.rb:43
    And I type Asia into the 1. page input field # features/step_definitions/sitelinks_steps.rb:47
    And I <save>                                 # features/step_definitions/sitelinks_steps.rb:21
    Then There should be 1 sitelinks in the list # features/step_definitions/sitelinks_steps.rb:134

    Examples: 
      | save                           |
      | click the sitelink save button |
      no implicit conversion of String into Integer (TypeError)
      ./features/step_definitions/entity_steps.rb:104:in `block (2 levels) in <top (required)>'
      ./features/step_definitions/entity_steps.rb:103:in `each'
      ./features/step_definitions/entity_steps.rb:103:in `/^The following sitelinks do not exist:$/'
      features/sitelinks.feature:113:in `Given The following sitelinks do not exist:'

Failing Scenarios:
cucumber features/sitelinks.feature:112 # Scenario: Save sitelink

1 scenario (1 failed)
9 steps (1 failed, 5 skipped, 3 passed)
0m11.570s

This is the problem:

https://github.com/wmde/WikidataApiGem/blob/master/lib/mediawiki_api/wikidata/wikidata_client.rb#L38

def sitelink_exists?(site_id, title)
  resp = action(:wbgetentities, token_type: false, sites: [site_id], titles: [title] )
  !resp.data["entities"]["-1"]
end

!resp.data["entities"]["-1"] raises TypeError: no implicit conversion of String into Integer

[8] pry(#<MediawikiApi::Wikidata::WikidataClient>)> resp.data["entities"]
=> [{"pageid"=>139698,
  "ns"=>0,
  "title"=>"Q103069",
  "lastrevid"=>216899,
  "modified"=>"2015-08-25T15:33:00Z",
  "type"=>"item",
  "id"=>"Q103069",
  "labels"=>{"en"=>{"language"=>"en", "value"=>"gKjXdSKs"}},
  "descriptions"=>{"en"=>{"language"=>"en", "value"=>"FKXVeVVVXthAfwbyCgPZ"}},
  "aliases"=>{},
  "claims"=>{},
  "sitelinks"=>{"enwiki"=>{"site"=>"enwiki", "title"=>"Asia", "badges"=>["Q49447"]}}}]

[9] pry(#<MediawikiApi::Wikidata::WikidataClient>)> !resp.data["entities"]
=> false

[10] pry(#<MediawikiApi::Wikidata::WikidataClient>)> !resp.data["entities"]["-1"]
TypeError: no implicit conversion of String into Integer
from (pry):10:in `[]'
zeljkofilipin set Security to None.Sep 8 2015, 9:21 AM
zeljkofilipin added a subscriber: Tobi_WMDE_SW.

When sitelink exists (example: "enwiki", "Asia"), resp.data["entities"] returns

[{"pageid"=>139698, "ns"=>0, "title"=>"Q103069", "lastrevid"=>216899, "modified"=>"2015-08-25T15:33:00Z", "type"=>"item", "id"=>"Q103069", "labels"=>{"en"=>{"language"=>"en", "value"=>"gKjXdSKs"}}, "descriptions"=>{"en"=>{"language"=>"en", "value"=>"FKXVeVVVXthAfwbyCgPZ"}}, "aliases"=>{}, "claims"=>{}, "sitelinks"=>{"enwiki"=>{"site"=>"enwiki", "title"=>"Asia", "badges"=>["Q49447"]}}}]

and WikidataClient#sitelink_exists? raises no implicit conversion of String into Integer (TypeError).

When sitelink does not exist (example: "enwiki", "releng"), resp.data["entities"] returns

{"-1"=>{"site"=>"enwiki", "title"=>"releng", "missing"=>""}}

and WikidataClient#sitelink_exists? does not raise any exceptions.

The documentation for mediawiki_api-wikidata says:

wikidata_client.sitelink_exists? "enwiki", "Berlin" #returns true if enwiki/Berlin sitelink exists, false otherwise

An easy fix could be to check class of the object returned by resp.data["entities"], it is Array in the first case and Hash in the second.

JanZerebecki renamed this task from fix no implicit conversion of String into Integer (TypeError) in browsertests to [Bug] fix no implicit conversion of String into Integer (TypeError) in browsertests.Sep 10 2015, 1:14 PM
JanZerebecki moved this task from incoming to needs discussion or investigation on the Wikidata board.

I was not able to reproduce this. Sure this issue still exists?

Also, on the current version of Wikidata I'm getting back a Hash in both cases (if sitelink exists and if it does not exist). I guess something has changed with the return format.