jenkins-bot has submitted this change and it was merged.
Change subject: Add browser tests for external surveys
......................................................................
Add browser tests for external surveys
Tests assume that there are only the two existing surveys. The
assumption is useful when we want to control which survey to
display so that we can dismiss the other one.
Hat tip to Jon for refactoring and making the tests more readable.
Bug: T110225
Change-Id: I8a605f7c6ef99f5624a81bf54bdd46e0f692809f
---
M tests/browser/LocalSettings.php
A tests/browser/features/external_survey.feature
M tests/browser/features/internal_survey.feature
M tests/browser/features/support/pages/article_page.rb
M tests/browser/features/support/step_definitions/common_steps.rb
A tests/browser/features/support/step_definitions/external_survey_steps.rb
M tests/browser/features/support/step_definitions/internal_survey_steps.rb
7 files changed, 133 insertions(+), 36 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/browser/LocalSettings.php b/tests/browser/LocalSettings.php
index 4ffc204..7ac103d 100644
--- a/tests/browser/LocalSettings.php
+++ b/tests/browser/LocalSettings.php
@@ -18,4 +18,18 @@
"mobile" => array( "stable", "beta", "alpha" ),
),
),
+ array(
+ 'name' => 'external example survey',
+ 'type' => 'external',
+ "question" =>
"ext-quicksurveys-example-external-survey-question",
+ "description" =>
"ext-quicksurveys-example-external-survey-description",
+ "link" => "ext-quicksurveys-example-external-survey-link",
+ "privacyPolicy" =>
"ext-quicksurveys-example-external-survey-privacy-policy",
+ 'coverage' => .5,
+ 'enabled' => true,
+ 'platform' => array(
+ 'desktop' => array( 'stable' ),
+ 'mobile' => array( 'stable', 'beta', 'alpha' ),
+ ),
+ )
);
diff --git a/tests/browser/features/external_survey.feature
b/tests/browser/features/external_survey.feature
new file mode 100644
index 0000000..ef8f529
--- /dev/null
+++ b/tests/browser/features/external_survey.feature
@@ -0,0 +1,35 @@
+@chrome @en.m.wikipedia.beta.wmflabs.org @firefox @test2.m.wikipedia.org
@vagrant @integration
+Feature: External surveys
+ Background:
+ Given the quick survey test pages are installed
+ And I have dismissed survey "internal-example-survey"
+
+ Scenario: External survey is visible with flag
+ And I am on the "Quick survey test page stub" page with the external quick
survey flag enabled
+ Then I should see the survey
+
+ Scenario: External survey is not present without flag when not bucketed
+ And I am not bucketed for "external-example-survey"
+ And I am on the "Quick survey test page stub" page
+ And the page has fully loaded
+ Then I should not see the survey
+
+ Scenario: External survey is visible when bucketed
+ And I am bucketed for "external-example-survey"
+ And I am on the "Quick survey test page stub" page
+ And the page has fully loaded
+ Then I should see the survey
+
+ Scenario: External survey is not present when dismissed
+ And I have dismissed survey "external-example-survey"
+ And I am on the "Quick survey test page stub" page
+ And the page has fully loaded
+ Then I should not see the survey
+
+ Scenario: User can participate in external survey
+ And I am on the "Quick survey test page stub" page with the external quick
survey flag enabled
+ And the page has fully loaded
+ And I see the external survey
+ When I answer the external survey in the negative
+ Then I get thanks for my external survey feedback
+
diff --git a/tests/browser/features/internal_survey.feature
b/tests/browser/features/internal_survey.feature
index 99bde0a..2951ba0 100644
--- a/tests/browser/features/internal_survey.feature
+++ b/tests/browser/features/internal_survey.feature
@@ -2,30 +2,31 @@
Feature: Internal surveys
Background:
Given the quick survey test pages are installed
+ And I have dismissed survey "external-example-survey"
Scenario: Internal survey is visible with flag
- And I am on the "Quick survey test page stub" page with the quick survey
flag enabled
+ And I am on the "Quick survey test page stub" page with the internal quick
survey flag enabled
Then I should see the survey
Scenario: Internal survey is not present without flag
- And I'm not bucketed with storage key
"ext-quicksurvey-internal-example-survey"
- And I am on the "Quick survey test page stub" page
- And the page has fully loaded
+ And I am not bucketed for "internal-example-survey"
+ And I am on the "Quick survey test page stub" page
+ And the page has fully loaded
Then I should not see the survey
Scenario: Internal survey is visible when bucketed
- And I'm bucketed with storage key "ext-quicksurvey-internal-example-survey"
- And I am on the "Quick survey test page stub" page
+ And I am bucketed for "internal-example-survey"
+ And I am on the "Quick survey test page stub" page
Then I should see the survey
Scenario: Internal survey is not present when dismissed
- And I've dismissed the storage key
"ext-quicksurvey-internal-example-survey"
- And I am on the "Quick survey test page stub" page
- And the page has fully loaded
+ And I have dismissed survey "internal-example-survey"
+ And I am on the "Quick survey test page stub" page
+ And the page has fully loaded
Then I should not see the survey
Scenario: User can participate in internal survey
- And I am on the "Quick survey test page stub" page with the quick survey
flag enabled
- And I see the survey
- When I answer the survey in the positive
- Then I get thanks for my feedback
+ And I am on the "Quick survey test page stub" page with the internal quick
survey flag enabled
+ And I see the internal survey
+ When I answer the internal survey in the positive
+ Then I get thanks for my internal survey feedback
diff --git a/tests/browser/features/support/pages/article_page.rb
b/tests/browser/features/support/pages/article_page.rb
index e970410..a4b67b0 100644
--- a/tests/browser/features/support/pages/article_page.rb
+++ b/tests/browser/features/support/pages/article_page.rb
@@ -3,10 +3,14 @@
include PageObject
page_url '<%= URI.encode(params[:article_name]) %>'\
- '<%=params[:query_string]%><%= params[:hash] %>'
+ '<%= URI.encode(params[:query_string]) if params[:query_string] %>'\
+ '<%= params[:hash] %>'
div(:survey, css: '.panel')
a(:survey_yes,
css: '.panel .oo-ui-buttonSelectWidget .oo-ui-buttonElement-button',
index: 0)
+ a(:external_survey_no,
+ css: '.panel .oo-ui-buttonWidget .oo-ui-buttonElement-button',
+ index: 1)
div(:survey_complete, css: '.panel .completed')
end
diff --git a/tests/browser/features/support/step_definitions/common_steps.rb
b/tests/browser/features/support/step_definitions/common_steps.rb
index e89c086..d696c20 100644
--- a/tests/browser/features/support/step_definitions/common_steps.rb
+++ b/tests/browser/features/support/step_definitions/common_steps.rb
@@ -23,6 +23,28 @@
using_params: { article_name: arg1, query_string: '?quicksurvey=true'
})
end
+Given(/^I am on the "(.*?)" page with the internal quick survey flag
enabled$/)\
+ do |arg1|
+ visit(
+ ArticlePage,
+ using_params: {
+ article_name: arg1,
+ query_string: '?quicksurvey=internal-survey-internal example survey'
+ }
+ )
+ end
+
+Given(/^I am on the "(.*?)" page with the external quick survey flag
enabled$/)\
+ do |arg1|
+ visit(
+ ArticlePage,
+ using_params: {
+ article_name: arg1,
+ query_string: '?quicksurvey=external-survey-external example survey'
+ }
+ )
+ end
+
Given(/^I am on the "(.*?)" page$/) do |arg1|
visit(ArticlePage, using_params: { article_name: arg1 })
end
@@ -35,7 +57,7 @@
on(ArticlePage) do |page|
page.wait_until do
# Wait for async JS to hijack standard link
- script = 'return mw && '\
+ script = 'return mw && mw.loader && '\
'mw.loader.getState("ext.quicksurveys.init") === "ready";'
page.execute_script(script)
end
@@ -46,26 +68,36 @@
expect(on(ArticlePage).survey_element).to_not be_visible
end
-Then(/^I'm bucketed with storage key "(.*?)"$/) do |arg1|
- # localStorage is undefined without visiting a page
- visit(ArticlePage,
- using_params: { article_name: 'Quick survey test page stub' })
- # token 2c0cdc37f48b1b0e is bucketed with 50% coverage
- browser.execute_script("localStorage.setItem('#{arg1}','2c0cdc37f48b1b0e');")
+Given(/^I have dismissed survey "(.*?)"$/) do |arg1|
+ step 'I am on the "Main Page" page'
+ browser.execute_script(
+ 'localStorage.setItem("ext-quicksurvey-' + arg1 + '", "~");')
end
-Then(/^I'm not bucketed with storage key "(.*?)"$/) do |arg1|
- # localStorage is undefined without visiting a page
- visit(ArticlePage,
- using_params: { article_name: 'Quick survey test page stub' })
- # token 63e9d6d760750eaa is not bucketed with 50% coverage
- browser.execute_script("localStorage.setItem('#{arg1}','63e9d6d760750eaa');")
+Given(/^I am not bucketed for "(.*?)"$/) do |arg1|
+ step 'I am on the "Main Page" page'
+ case arg1
+ when 'internal-example-survey'
+ key = '63e9d6d760750eaa'
+ when 'external-example-survey'
+ key = '2c0cdc37f48b1b0e'
+ else
+ key = ''
+ end
+ browser.execute_script(
+ 'localStorage.setItem("ext-quicksurvey-' + arg1 + '", "' + key + '")')
end
-Then(/^I've dismissed the storage key "(.*?)"$/) do |arg1|
- # localStorage is undefined without visiting a page
- visit(ArticlePage,
- using_params: { article_name: 'Quick survey test page stub' })
- # Setting value for the storage key to "~" marks the survey as dismissed
- browser.execute_script("localStorage.setItem('#{arg1}','~');")
+Given(/^I am bucketed for "(.*?)"$/) do |arg1|
+ step 'I am on the "Main Page" page'
+ case arg1
+ when 'internal-example-survey'
+ key = '2c0cdc37f48b1b0e'
+ when 'external-example-survey'
+ key = '63e9d6d760750eaa'
+ else
+ key = ''
+ end
+ browser.execute_script(
+ 'localStorage.setItem("ext-quicksurvey-' + arg1 + '", "' + key + '")')
end
diff --git
a/tests/browser/features/support/step_definitions/external_survey_steps.rb
b/tests/browser/features/support/step_definitions/external_survey_steps.rb
new file mode 100644
index 0000000..290ca86
--- /dev/null
+++ b/tests/browser/features/support/step_definitions/external_survey_steps.rb
@@ -0,0 +1,11 @@
+Given(/^I see the external survey$/) do
+ expect(on(ArticlePage).survey_element.when_present).to be_visible
+end
+
+Given(/^I answer the external survey in the negative$/) do
+ on(ArticlePage).external_survey_no_element.when_present.click
+end
+
+Then(/^I get thanks for my external survey feedback$/) do
+ expect(on(ArticlePage).survey_complete_element.when_present).to be_visible
+end
diff --git
a/tests/browser/features/support/step_definitions/internal_survey_steps.rb
b/tests/browser/features/support/step_definitions/internal_survey_steps.rb
index 1e375b2..ad53038 100644
--- a/tests/browser/features/support/step_definitions/internal_survey_steps.rb
+++ b/tests/browser/features/support/step_definitions/internal_survey_steps.rb
@@ -1,11 +1,11 @@
-Given(/^I see the survey$/) do
+Given(/^I see the internal survey$/) do
expect(on(ArticlePage).survey_element.when_present).to be_visible
end
-Given(/^I answer the survey in the positive$/) do
+Given(/^I answer the internal survey in the positive$/) do
on(ArticlePage).survey_yes_element.when_present.click
end
-Then(/^I get thanks for my feedback$/) do
+Then(/^I get thanks for my internal survey feedback$/) do
expect(on(ArticlePage).survey_complete_element.when_present).to be_visible
end
--
To view, visit https://gerrit.wikimedia.org/r/233933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8a605f7c6ef99f5624a81bf54bdd46e0f692809f
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: dev
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: Robmoen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits