Commit graph

33 commits

Author SHA1 Message Date
Petr Pchelko
ff4e6f59dc Add selenium tests for page protection
Change-Id: I31349f747dc1fa22c3bfbb3fe02386686aeb2cf1
2021-06-07 11:35:02 -07:00
Kosta Harlan
3244a9e367 selenium: Disable flaky undoable page test
Bug: T276783
Change-Id: Ic3f9dbd38511ffb503ffd341f8af4a32405ad1ed
2021-03-11 11:55:07 +01:00
Željko Filipin
5015a623d6 selenium: Remove ChromeDriver dependency
Since WebdriverIO v5, Puppeteer is available as a Chromedriver
alternative.

Puppeteer and Chromedriver behave almost the same, but there were a few
minor failures that needed to be fixed.

Puppeteer is bundled with WebdriverIO. Chromedriver needs to be installed
(and started/stopped) separately. Getting rid of Chromedriver simplifies
our documentation, among other things.

The commit updates tests/selenium/wdio.conf.js to use Puppeteer.
It also fixes a few minor problems in tests/selenium/specs/page.js
introduced by the change.

Bug: T269566
Change-Id: I143c44304461980a2be98eb60741184fa7671343
2021-03-07 02:31:06 +00:00
Ed Sanders
8b720e9bd6 eslint: Update to eslint-config-wikimedia 0.16.0
* valid-jsdoc replaced with jsdoc plugin
* New /selenium config

Change-Id: I471eebac0312cb25c539c3f6a3ecfc7cfd4ed8d6
2020-06-02 21:32:56 +01:00
Timo Tijhof
22d149c3f7 selenium: Fix more inefficient MWBot use and simplify wdio-mediawiki Api
This does the same for the other specs, as previously done to the
page.js spec in 058d5b7cd8.

* rollkback: From 6 api logins to 4 api logins.
  Before (2x3): admin for edit, admin for createaccount, vandal for edit.
  After (2x2): admin for edit + createaccount, vandal for edit.

* recentchanges spec: No difference, but updated pattern for consistency
  so that if it is extended in the future, it will be natural to re-use
  the bot object instead of creating a new one.

* watchlist spec: From 3 api logins to 1 api login.
  Before: admin for createaccount, admin for edit, admin for edit.
  After: admin (re-used)

* user spec: From 2 to 1 api login.

Also:

* Remove the now-unused Api.edit() and Api.delete() anti-pattern
  methods, as these are nothing but one-line shortcuts to the
  already one-line invocation of bot.edit() and bot.delete(),
  except that they bypassed the current bot object, causing
  inefficient repeat logins in way that was non-obvious.
  Migration is simple and won't be required until other repos
  upgrade to the next wdio-mediawiki version (not yet released).

* Make 'bot' a mandatory parameter for the createAccount, block,
  and unblock convenience wrapper methods.

* Move the vandalizePage() method from HistoryPage to rollback spec,
  as it had no connection with that page object or the action=history
  interface, and document why it can't (yet) re-use its bot object.

Bug: T234002
Change-Id: Id6e995916566f7dd7b618892295198b897fbee2e
2019-10-04 18:16:28 +01:00
Timo Tijhof
46586a243c selenium: Replace ES5 one-var assignments with const/let per line
The one-var rule only applies to 'var' where it matters that we
don't let the engine implicitly hoist variables leading to
confusing code that may be unsafe to refactor in a straight-forward
manner.

This doesn't apply to ES6 const and let. While I updated the
rule in 1955a8aa5 to allow ES6, I did not enforce it. Fixed now.
When assigning a value, each assignment should be its own
statement (disallow awkward comma separated assignments).
When not assigning a value, and the lines are next to each other,
they should be in one statement. This makes sense for this small
directory and might make sense to propose for the wikimedia preset
at some point.

Note that the rule I added was not required to make the build
pass. The changes I made are allowed by default by the wikimedia
preset for es6+. The rule I added disallows the previous way.

Change-Id: I26cda095a8a4589084e36273038877f2dd1fc50b
2019-10-01 02:18:19 +00:00
Kosta Harlan
640b0b4943 Selenium: Hide VE welcome and beta dialogs
Remove uses of setLocalStorage (incompatible with chromedriver >= 75)
and also requires slightly fewer requests since BlankPage.open()
doesn't need to be invoked.

Bug: T234002
Change-Id: I4cfb4fe17a3c99bfcb7ff39ac6db60f5c5e8a687
2019-09-30 21:57:23 +02:00
Timo Tijhof
058d5b7cd8 selenium: Fix inefficient use of MWBot in specs/page.js
This test previously took 4 minutes to run locally and ended up
running the MWBot.login process 9 times.

After this, the specs/page tests only log-in once.

Bug: T234002
Change-Id: I374620a01f49d4da559070d0982bdbe4c1269e2e
2019-09-30 14:47:00 +01:00
Timo Tijhof
1955a8aa56 selenium: Upgrade from webdriver v4 to v5
* Options no longer needed or no longer exist in wdio v5:
  - coloredLogs: Now always on. The underlying 'chalk' library can still
    be influenced via the FORCE_COLOR environment variable.
  - screenshotPath: Removed. Was already disabled in our config.
  - deprecationWarnings: Meh.
  - 'sync: true' – On by default when `@wdio/sync` is installed.
    The wdio v5 config generator doesn't recommend setting manually.

* The selenium.sh script was removed. It existed to start and stop
  chromedriver for local use by developers. This is now done by
  the wdio-chromedriver-service. In WMF CI, Quibble starts its own
  chromedriver (as optimisation, reused across gated repos),
  which is why the 'selenium-test' entry points remains and skips
  this.

* The wdio-mediawiki package now requires wdio v5 and Node 10.
  This doesn't affect extension repos because versions are pinned.
  Upgrade may happen at the earliest convenience.

* Several WDIO methods changed names or signature. Full list at:
  <https://github.com/webdriverio/webdriverio/blob/v5.13.2/CHANGELOG.md#v500-2018-12-20>
  Highlights:
  - browser.element() is now browser.findElement() with "$()" as alias.
  - browser.localStorage replaced by browser.setLocalStorage.
  - browser.deleteCookie() requires `name` param. To delete all at once,
    there is a new method browser.deleteAllCookies().
  - Commands that return data no longer wrapped in `{ value: … }`.
    Values are now returned directly.
  - Custom config keys are now under browser.config instead of browser.options.
    Renamed our username/password keys to be mw-prefixed, to avoid clashes
    and reduce confusion with similar config keys.
  - browser.click(selector) and browser.getText(selector) no longer exist.
    Use $(selector).click() or .getText() instead.

* Fix "no such alert" warning from specs/page.js by removing the apparently
  redundant code.

Bug: T234002
Bug: T213268
Change-Id: I908997569ca8457997af30cb29e98ac41fae3b64
2019-09-29 02:59:44 +01:00
jenkins-bot
dfec83932f Merge "Selenium: replace UserLoginPage with BlankPage where possible" 2019-07-08 17:00:13 +00:00
Željko Filipin
97c13ffeb8 Selenium: replace UserLoginPage with BlankPage where possible
When using local storage, any page has to be open. UserLoginPage is usually used.
BlankPage should be slightly faster to load. It also makes it more clear than
any page would do the job.

Change-Id: I50b23993065ad6b093a6cc951d00b0bf7a3d5e68
2019-07-08 13:44:32 +00:00
Ed Sanders
689d07b81d build: Update eslint-config-wikimedia to 0.13.0
Change-Id: I7df5840bc97f8bbcd8cfc875c2b48b3061ef2c9e
2019-07-05 13:32:26 -07:00
Cormac Parle
a45f0e4613 selenium: Replace regex matching with includes()
Bug: T217544
Change-Id: Iedcbb1f7e21fc768069346ac346c2e499a689556
2019-04-15 17:09:12 +00:00
Cormac Parle
d653232b22 Selenium: fix 'Page should be editable' test
The test is broken only when and targeting beta cluster, because an
extension adds text to page. Instead of checking the entire body of
the page, test just checks if expected string is there.

Bug: T217544
Change-Id: Ibd67790c1df2cd8556b9c71d872d52cfc18f5ebd
2019-04-11 16:37:58 +00:00
jdlrobson
063cce733e History page is now using pseudo elements for presentation
|, ( and ) separators are now added via CSS rather than being
made part of the HTML.

Bug: T205581
Change-Id: I272770418ee544b22f8f94312daf07010b7a2273
2019-03-26 00:15:21 +00:00
Tim Eulitz
341320457c Show confirmation prompt on rollback links
Bug: T215020
Change-Id: Ic831888e30808a20a04397912498fe2ca04f80ba
2019-03-21 10:13:22 +00:00
Thiemo Kreuz
3b03ea9bdc Add browser test for preview functionality to MediaWiki core
The basic functionality of being able to preview an edit is currently
not covered by a test, as far as I can see.

The assertion for a wpTextbox2 that should *not* be there is a result of
the issue documented at T209012, where the EditPage::isConflict flag was
accidentially set. This assertion makes sure accidential conflicts can't
happen again, no matter which extension might cause it.

Bug: T210758
Change-Id: Iae723430b3a88079ad3499429e65c29817eca67e
2018-12-07 16:27:45 +01:00
Željko Filipin
e552e95f71 Selenium: Daily Jenkins job targeting beta cluster should run only tests that pass
Selenium tests run fine when targeting MediaWiki installation in
MediaWiki-Vagrant and in Jenkins, but fail when targeting beta cluster.
Until tests are refactored to run without failure for beta cluster, let's disable
failing tests.

Bug: T185011
Change-Id: I12da893e7d624d4ebe478bccf0706aa07c965796
2018-09-04 12:47:07 +02:00
Pablo Grass
32c36f0e73 selenium: undo page
Add basic undo page object and test showing a previous edit can be
undone.

Bug: T201901
Change-Id: Idc1b3889abc6e655032bc1576f1b9d591abd6c8d
2018-08-14 16:27:31 +02:00
Jakob Warkotsch
d96ca0d6a9 Browser tests: extract commonly used getTestString function
Extracting this function into a Util module reduces redundancy for
existing and future tests in core and extensions.

Change-Id: I5c5e9b22af5406f347636b22e68657b2674db6c9
2018-06-20 13:06:45 +02:00
WMDE-Fisch
3ad98462e7 Use more diverse unicode chars in basic browser tests
See comment in I3423011c467b0a6426cfa0dad522435618f24bd0
and https://mathiasbynens.be/notes/javascript-unicode#poo-test

Decided on using something more positive than a pile of poo though.

Change-Id: Ic34d0d78044cede71fd1cd8742214c117ed2e99f
2018-06-13 14:59:46 +02:00
addshore
8602e489e1 selenium, page spec, make "should be editable" actually edit
This was using the same content for the edit before this
patch, so no edit was actually made, (just a null edit).

Change-Id: I945090647226e82f22b5b10a414a2a0bf9f2bc19
2018-06-13 11:56:29 +00:00
addshore
09536c527d selenium: page spec, make it easier to see where strings come from
Having randomly generated strings is great, but sometimes
it can help to allow a human to easily see where the string
is actually being generated in code, so add an optional suffix
to the string being generated.

Change-Id: Ibfe45f74b4880a70a76c01223a787dabcd43607e
2018-06-13 11:56:23 +00:00
Ed Sanders
4ffbfabf16 Selenium tests: Use assert.strictEqual instead of assert.equal
assert.equal is deprecated

Change-Id: I2f83d596db2ad475de5e005baa849782261d433e
2018-06-06 11:53:29 +01:00
Timo Tijhof
16a4d9da7b selenium: Initial version of wdio-mediawiki package
This is new package will be reusable by other repositories for
their browser tests, without having to reference the internal
selenium/pageobjects/ directory from MediaWiki core.

In addition to not requiring direct imports, it will also avoid
problems in the future by allowing the package to be versioned
and iterated upon without forcing an atomic global upgrade
(or broken master builds), everytime we change something.

See wdio-mediawiki/README for details.

Within MediaWiki core itself, the package is used using the
'file' specifier in its package.json, so that we always test
and develop using its working copy, which makes drafting and
testing changes easier.

Also misc changes to make wdio.conf easier to understand.

Bug: T193088
Change-Id: I547a7899e7a97693a93567dd763784e637433d55
2018-05-09 14:43:30 +00:00
Timo Tijhof
2729bf4653 selenium: Minor clean-up in preparation for packaging
This is functionally a no-op, purely refactoring (mostly style).

* Consistently require packages at the top of a file.
  (e.g. MWBot in edit.page.js).

* Remove unused .call(this) from mwbot interaction closures,
  which didn't use 'this'.

* Use Node.js regular Promise chaining with then(), instead of
  complex bluebird.coroutine generator function yields, which
  are intended to emulate async-await, but the syntax is quite
  error-prone for inexperienced developers and hard to debug.
  Once we require Node 7+ for the selenium tests, we can use
  async-await here natively, but until then, might as well use
  regular then() syntax, which we already use elsewhere in the
  tests, and is also what MWBot documentation uses.

* Also applied some minor whitespace changes for consistency
  among these files and other MediaWiki JS. E.g. no empty line
  before the first statement of a function. Add a new line between
  different methods, and between the end of a class and the
  export statement.

* Remove 'use strict' from test files. The patterns that would expose
  the bad non-strict behaviour are mostly already forbidden by ESLint,
  and the run-time optimisation to disable non-strict can't be noticed
  in tests (more useful in prod where e.g. the same process would run
  a function 1 million times). Main reason here is to keep things
  simple for new-comers and reduce boilerplate, given that these tests
  will mainly be worked on by browser-JS developers, not Node.js devs,
  and we don't currently use strict mode in our front-end code, either.

* Remove unused bluebird dependency.

Bug: T193088
Change-Id: I59f9211299e8e884c28c7733bcee3b7b28542610
2018-05-08 14:42:59 +00:00
addshore
817baf7e91 selenium: add re-creatable page test to page spec
Change-Id: I61c452246c29bd22000a06844901dfe8ca06fadd
2018-01-20 10:47:59 +00:00
addshore
9c7d876341 selenium, add restoration test to page spec
Change-Id: Ied06915f982e693b00edab14b8c29c978a5d6dff
2018-01-20 10:45:16 +00:00
addshore
52c7dc56df selenium: add deletion test to page spec
Change-Id: Ia17b52958778a09378eeb10c9f24ebe9229bd9f5
2018-01-20 10:41:41 +00:00
addshore
877c2e0a58 selenium, update page spec to include more chars
Bug: T184749
Change-Id: I3423011c467b0a6426cfa0dad522435618f24bd0
2018-01-15 10:36:34 +00:00
Željko Filipin
fedebb1834 Disable VisualEditor welcome dialog when running Selenium tests
Bug: T164721
Change-Id: I7b5f73c6fbaaa221ac1b689344f9015fb903220f
2017-07-07 11:54:46 +02:00
Željko Filipin
853cba1deb Create users and pages for Selenium tests using action API
This will make tests slightly more robust.

Bug: T164721
Bug: T167502
Change-Id: I9b2fea77b28af4f7f521490a0105e7d04730bc87
2017-07-07 04:59:14 +00:00
Željko Filipin
7aee98758a Selenium tests in Node.js using WebdriverIO
Introduce the WebdriverIO browser testing framework driven by Node.js.
The overall intents are:
* have MediaWiki core to provide a platform to run tests that is shared
  between core and the extensions.
* phase out ruby driven browser tests eventually.

Code is namespaced in sub directory /tests/selenium
The 'pages' sub directory provides helper representing a MediaWiki page
such as Special:Login and human friendly helpers to interact with the
elements.

Add Grunt task webdriver:test.

Provide a npm script to easily spawn/dispose chromedriver and run above
grunt task.

wdio.conf.js provides all the configuration. It defaults to point to a
MediaWiki-Vagrant installation on http://127.0.0.1:8080. Can be
overriden with environment settings as needed.

glob patterns (specs) are made absolute paths from MediaWiki root path
that let us run the tests either from the root path (eg the npm
wrapper or from the tests/selenium directory when invoking wdio
directly. wdio assumes they are relative to the current working
directory, hence the normalization.

wdio.conf.jenkins.js extends the configuration and is used solely for
Jenkins.  The switch is done from the Gruntfile.js whenever JENKINS_HOME
is set.  Specially we want junit reports to be generated.

Provide a more specific eslint configuration.

References:

* MALU https://phabricator.wikimedia.org/source/malu/
* T151442 Research WebdriverIO
* T151443 Research Nightwatch.js

Bug: T139740
Signed-off-by: Antoine Musso <hashar@free.fr>
Change-Id: Ibe7a004a120e82af637ab3e31b725de743134c99
2017-03-14 12:20:32 +01:00