Page MenuHomePhabricator

Make it possible to execute tests as a specific (new) MediaWiki user on beta cluster
Closed, ResolvedPublic

Description

The Reading web team had to disable a browser test on the beta cluster because the default Selenium_user is not fit to test the use case we have (we have a test that expects the user to be new).

Our test checks if a user is new and has no edits the interface behaves a certain way.
When we run @integration tests on a per commit basis this is not a problem as new users are created for every scenario.

Could we make it possible to run some tests as a user that meets certain criteria, e.g. a user that doesn't have any edits, has a certain amount of edits.

Event Timeline

Jdlrobson renamed this task from Make it possible to execute tests as a specific MediaWiki user on beta cluster to Make it possible to execute tests as a specific (new) MediaWiki user on beta cluster.Dec 5 2016, 6:44 PM
Jdlrobson updated the task description. (Show Details)

Every test should create environment it needs (users, pages...) and not assume they will be available at the target wiki. The easiest way to ensure that an user is configured correctly is to create a new user and configure it. It is easy to do at mediawiki-vagrant and in Jenkins, since the target wiki does not have CAPTCHA enabled. The problem with creating users at beta is that it has CAPTCHA enabled.

There is a way to bypass CAPTCHA (from GettingStarted):

Usage (registration_page.rb):

on(RegistrationPage).register_user "Test Account #{@random_string}"

Implementation (registration_page.rb):

class RegistrationPage
  include PageObject

  text_field(:username, id: 'wpName2')
  text_field(:password, id: 'wpPassword2')
  text_field(:password_confirmation, id: 'wpRetype')
  button(:register, id: 'wpCreateaccount')
  a(:return_to, css: '#mw-returnto a')

  def register_user(username)
    self.username = username
    password = Random.new.rand.to_s
    self.password = password
    self.password_confirmation = password

    if env.lookup(:mediawiki_captcha_bypass_password, default: nil)
      bypass_script = <<-END
        var $bypass = $( '<input>' ).attr( {
          type: 'hidden',
          name: 'captchabypass',
          value: '#{env[:mediawiki_captcha_bypass_password]}'
        } );
        $( '#userlogin2' ).append( $bypass );
      END
      execute_script(bypass_script)
    end
    register_element.click
  end
end

Might want to read T104842 which mentions captcha.

Note well that the CAPTCHA bypass in GettingStarted is currently broken (tracked in T155797: GettingStarted failing on Jenkins due to CAPTCHA bypass), which has caused a long chain of build failures for the extension.

Selenium user can create accounts via the API at beta cluster without captcha:

$ pry

[1] pry(main)> require "mediawiki_api"
=> true

[2] pry(main)> client = MediawikiApi::Client.new "https://en.wikipedia.beta.wmflabs.org/w/api.php"
=> #<MediawikiApi::Client:0x007f98cb3c2768
...

[3] pry(main)> client.create_account "user7777", "test7777"
MediawikiApi::CreateAccountError: Incorrect or missing CAPTCHA.
from /usr/local/lib/ruby/gems/2.4.0/gems/mediawiki_api-0.7.1/lib/mediawiki_api/client.rb:78:in `create_account_new'

[4] pry(main)> client.log_in "Selenium user", not-the-real-one
=> {"result"=>"Success", "lguserid"=>820, "lgusername"=>"Selenium user"}

[5] pry(main)> client.create_account "user7777", "test7777"
=> {"status"=>"PASS", "username"=>"User7777"}

Change 337040 had a related patch set uploaded (by Zfilipin):
WIP Revert "Logged in user tests do not work on beta cluster"

https://gerrit.wikimedia.org/r/337040

Change 337040 abandoned by Zfilipin:
WIP Revert "Logged in user tests do not work on beta cluster"

https://gerrit.wikimedia.org/r/337040

After some testing, looks like it is already supported.

Feature:

Scenario: Create account via the API
  Given I have created account via the API
  When I log in as the new user
  Then I am logged in

Steps:

Given(/^I have created account via the API$/) do
  require 'securerandom'
  @user = SecureRandom.hex(20).capitalize
  @password = SecureRandom.hex(20)
  api.create_account @user, @password
end

When(/^I log in as the new user$/) do
  visit(LoginPage).login_with(@user, @password)
end

Change 338146 had a related patch set uploaded (by Zfilipin):
WIP Make it possible to execute tests as a specific (new) MediaWiki user on beta cluster

https://gerrit.wikimedia.org/r/338146

338146 is an example patch. Test it with:

$ git review -d 338146

$ MEDIAWIKI_ENVIRONMENT=beta MEDIAWIKI_PASSWORD=not-the-real-one bundle exec cucumber tests/browser/features/create_account.feature:19

@chrome @firefox @vagrant
Feature: Create account

  Scenario: Create account via the API       # tests/browser/features/create_account.feature:19
    Given I have created account via the API # tests/browser/features/step_definitions/create_account_steps.rb:5
    When I log in as the new user            # tests/browser/features/step_definitions/create_account_steps.rb:16
    Then I am logged in                      # /Users/z/Documents/gerrit/mediawiki/selenium/lib/mediawiki_selenium/step_definitions/login_steps.rb:1

1 scenario (1 passed)
3 steps (3 passed)
0m26.232s
zeljkofilipin subscribed.

As far as I can see, all you need is already implemented. Let me know if I have missed something.

Change 338146 abandoned by Zfilipin:
WIP Make it possible to execute tests as a specific (new) MediaWiki user on beta cluster

https://gerrit.wikimedia.org/r/338146

zeljkofilipin claimed this task.
zeljkofilipin lowered the priority of this task from Medium to Low.

As far as I can see, this is resolved. Please reopen if needed.