From 0a41aa53caad2f8d7ab408955447411517487200 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Wed, 28 Nov 2018 16:59:46 -0800 Subject: [PATCH] QA: Browser tests should limit write operations We use lots of write operations in Minerva browser tests. On the beta cluster many of these are redundant, as the page already has the content required or the page already exists Limit where we do our creation... the less write operations we make the more stable we can expect these browser tests to be. Change-Id: If88b878e14bf4a0424fcf23213653cfc2cf8d87b --- .../step_definitions/create_page_api_steps.rb | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/browser/features/step_definitions/create_page_api_steps.rb b/tests/browser/features/step_definitions/create_page_api_steps.rb index af849b2..68a4f49 100644 --- a/tests/browser/features/step_definitions/create_page_api_steps.rb +++ b/tests/browser/features/step_definitions/create_page_api_steps.rb @@ -1,3 +1,15 @@ +# on a shared environment there is no need to waste unnecessary API requests +# to edit a page which only needs to exist. This function limits write operations +# and speeds up browser tests. +def create_page_with_content(title, wikitext) + resp = api.get_wikitext title + if resp.status == 404 + api.create_page title, wikitext + elsif wikitext != resp.body + api.create_page title, wikitext + end +end + # export MEDIAWIKI_API_URL = http://en.wikipedia.beta.wmflabs.org/w/api.php Given(/^I go to a page that has references$/) do wikitext = "MinervaNeue is a MediaWiki skin. @@ -8,7 +20,7 @@ Given(/^I go to a page that has references$/) do " - api.create_page 'Selenium References test page', wikitext + create_page_with_content 'Selenium References test page', wikitext step 'I am on the "Selenium References test page" page' end @@ -23,7 +35,7 @@ Section 2A. Section 3. " - api.create_page 'Selenium section test page2', wikitext + create_page_with_content 'Selenium section test page2', wikitext step 'I am on the "Selenium section test page2" page' end @@ -41,17 +53,17 @@ Given(/^I am on a page which has cleanup templates$/) do END - api.create_page 'Selenium page issues test page', wikitext + create_page_with_content 'Selenium page issues test page', wikitext step 'I am on the "Selenium page issues test page" page' end Given(/^the page "(.*?)" exists$/) do |title| - api.create_page title, 'Test is used by Selenium web driver' + create_page_with_content title, 'Test is used by Selenium web driver' step 'I am on the "' + title + '" page' end Given(/^at least one article with geodata exists$/) do - api.create_page 'Selenium geo test page', <<-end + create_page_with_content 'Selenium geo test page', <<-end This page is used by Selenium to test geo related features. {{#coordinates:43|-75|primary}} @@ -66,10 +78,10 @@ Given(/^I am in a wiki that has categories$/) do [[Category:Selenium artifacts]] [[Category:Selenium hidden category]]' - api.create_page 'Category:Selenium artifacts', msg - api.create_page 'Category:Test category', msg - api.create_page 'Category:Selenium hidden category', '__HIDDENCAT__' + msg - api.create_page 'Selenium categories test page', wikitext + create_page_with_content 'Category:Selenium artifacts', msg + create_page_with_content 'Category:Test category', msg + create_page_with_content 'Category:Selenium hidden category', '__HIDDENCAT__' + msg + create_page_with_content 'Selenium categories test page', wikitext end Given(/^I go to a page that has languages$/) do @@ -77,26 +89,26 @@ Given(/^I go to a page that has languages$/) do [[es:Selenium language test page]]' - api.create_page 'Selenium language test page', wikitext + create_page_with_content 'Selenium language test page', wikitext step 'I am on the "Selenium language test page" page' end Given(/^I go to a page that does not have languages$/) do wikitext = 'This page is used by Selenium to test language related features.' - api.create_page 'Selenium language test page without languages', wikitext + create_page_with_content 'Selenium language test page without languages', wikitext step 'I am on the "Selenium language test page without languages" page' end Given(/^the wiki has a terms of use$/) do - api.create_page 'MediaWiki:mobile-frontend-terms-url', 'https://mobile.test/wiki/Terms_of_Use' - api.create_page 'MediaWiki:mobile-frontend-terms-text', 'Terms of use' + create_page_with_content 'MediaWiki:mobile-frontend-terms-url', 'https://mobile.test/wiki/Terms_of_Use' + create_page_with_content 'MediaWiki:mobile-frontend-terms-text', 'Terms of use' # force a visit to check its existence visit(ArticlePage, using_params: { article_name: 'MediaWiki:Mobile-frontend-terms-url?action=info' }) end Given(/^I visit a protected page$/) do - api.create_page 'Selenium protected test 2', 'Test is used by Selenium web driver' + create_page_with_content 'Selenium protected test 2', 'Test is used by Selenium web driver' step 'the "Selenium protected test 2" page is protected.' step 'I am on the "Selenium protected test 2" page' end