Skip to content

Commit 02c6390

Browse files
committed
Add automated tests to replace manual test suite
1 parent 9c1fd2c commit 02c6390

28 files changed

Lines changed: 871 additions & 181 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM nginx
22
ARG DAP_ENV='dev'
33
ENV DAP_ENV=${DAP_ENV}
4-
COPY test_site Universal-Federated-Analytics-Min.js Federated.js.map /usr/share/nginx/html/
4+
COPY test_site Universal-Federated-Analytics-Min.js Universal-Federated-Analytics.js Federated.js.map /usr/share/nginx/html/
55
COPY nginx-test.conf.template /etc/nginx/conf.d/
66
RUN envsubst '${DAP_ENV}' < /etc/nginx/conf.d/nginx-test.conf.template > /etc/nginx/conf.d/default.conf

features/404_tracking.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: DAP modifies page_location for 404 pages
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: Page title containing "404" sets page_location to a vpv404 path
8+
When I load the test page "404.html"
9+
Then DAP will set custom dimensions for the DAP property
10+
| page_location | http://dap-test-site.local/vpv404/404.html |
11+
12+
Scenario: Page title containing "not found" sets page_location to a vpv404 path
13+
When I load the test page "not-found.html"
14+
Then DAP will set custom dimensions for the DAP property
15+
| page_location | http://dap-test-site.local/vpv404/not-found.html |
16+
17+
Scenario: 404 page with a referrer appends the referrer to page_location
18+
When I load the test site
19+
And I click on link with href "/404.html" and wait for new page to load
20+
Then DAP will set custom dimensions for the DAP property
21+
| page_location | http://dap-test-site.local/vpv404/404.html/http://dap-test-site.local/ |

features/autotracker.feature

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# DAP's GA4 property is configured to disable most enhanced measurement events.
2+
# The DAP code takes over responsibility for tracking these events, rather than relying on gtag's implementation.
3+
# This test feature verifies DAP's alternative implementation of outbound click and file download tracking.
4+
Feature: Downloads and outbound link clicks are tracked when autotracking is enabled
5+
6+
Background:
7+
Given I load an empty browser
8+
And DAP is configured for agency "GSA"
9+
10+
Scenario: Clicking an email link fires email_click when autotracking is enabled
11+
Given DAP is configured with autotracking enabled
12+
When I load the test site
13+
And I click on element with selector "a[href='mailto:test@domain.com']"
14+
Then a "email_click" event is sent to DAP with parameters
15+
| link_text | mailto:[REDACTED_EMAIL] |
16+
| link_domain | domain.com |
17+
| outbound | true |
18+
| interaction_type | Mouse Click |
19+
20+
Scenario: Clicking an email link does not fire email_click when autotracking is disabled
21+
Given DAP is configured with autotracking disabled
22+
When I load the test site
23+
And I click on element with selector "a[href='mailto:test@domain.com']"
24+
Then no "email_click" event is sent to DAP
25+
26+
Scenario: Clicking a telephone link fires telephone_click when autotracking is enabled
27+
Given DAP is configured with autotracking enabled
28+
When I load the test site
29+
And I click on element with selector "a[href='tel:+1437-925-1855']"
30+
Then a "telephone_click" event is sent to DAP with parameters
31+
| link_text | Telephone [REDACTED_TEL] |
32+
| interaction_type | Mouse Click |
33+
34+
Scenario: Clicking a telephone link does not fire telephone_click when autotracking is disabled
35+
Given DAP is configured with autotracking disabled
36+
When I load the test site
37+
And I click on element with selector "a[href='tel:+1437-925-1855']"
38+
Then no "telephone_click" event is sent to DAP
39+
40+
Scenario: Clicking an outbound link sends a click event when autotracking is enabled
41+
Given DAP is configured with autotracking enabled
42+
When I load the test site
43+
And I click on element with selector "a[href='http://www.gsa.gov/travelpolicy']"
44+
Then a "click" event is sent to DAP with parameters
45+
| link_url | http://gsa.gov/travelpolicy |
46+
| link_domain | gsa.gov |
47+
| link_text | http://gsa.gov/travelpolicy |
48+
| outbound | true |
49+
| interaction_type | Mouse Click |
50+
51+
Scenario: Clicking an outbound link does not fire event when autotracking is disabled
52+
Given DAP is configured with autotracking disabled
53+
When I load the test site
54+
And I click on element with selector "a[href='http://www.gsa.gov/travelpolicy']"
55+
Then no "click" event is sent to DAP
56+
57+
Scenario: Clicking a file download link reports the download when autotracking is enabled
58+
When I load the test site
59+
And I click on a file to download it
60+
Then a "file_download" event is sent to DAP with parameters
61+
| file_name | /about.zip |
62+
| file_extension | zip |
63+
| link_text | /about.zip |
64+
| link_id | internalDownload |
65+
| link_url | http://dap-test-site.local/about.zip |
66+
| link_domain | dap-test-site.local |
67+
| interaction_type | Mouse Click |
68+
69+
Scenario: Pressing Enter on a file download link reports the download when autotracking is enabled
70+
When I load the test site
71+
And I highlight and press Enter on a file to download it
72+
Then a "file_download" event is sent to DAP with parameters
73+
| file_name | /about.zip |
74+
| file_extension | zip |
75+
| link_text | /about.zip |
76+
| link_id | internalDownload |
77+
| link_url | http://dap-test-site.local/about.zip |
78+
| link_domain | dap-test-site.local |
79+
| interaction_type | Enter Key Keystroke |
80+
81+
Scenario: File downloads are not tracked when autotracking is disabled
82+
Given DAP is configured with autotracking disabled
83+
When I load the test site
84+
And I click on a file to download it
85+
Then no "file_download" event is sent to DAP

features/autotracker_download.feature

Lines changed: 0 additions & 23 deletions
This file was deleted.

features/banner_tracker.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: DAP tracks clicks on any 'Official website of the US government' banner
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: Clicking the USA banner button fires official_usa_site_banner_click
8+
When I load the test site
9+
And I click on element with selector "#banner-button"
10+
Then a "official_usa_site_banner_click" event is sent to DAP with parameters
11+
| link_text | Here's how you know |
12+
| section | header |

features/basic_page_load.feature

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ Feature: Test the outgoing requests sent by a basic page with DAP code loaded
88
Scenario: Loading the page with the DAP code without further action
99
When I load the test site
1010
And I wait 5 seconds
11-
Then there is a GA4 request
12-
But there are no unexpected requests
11+
Then there are no unexpected requests
1312

1413
Scenario: Loading the page with the DAP code and clicking a button
1514
When I load the test site
1615
And I click on element with selector "#banner-button"
1716
And I wait 5 seconds
18-
Then there is a GA4 request
19-
But there are no unexpected requests
17+
Then there are no unexpected requests

features/configuration.feature

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ Feature: A site can load the DAP code with varying levels of customization
1919
Then DAP will set custom dimensions for the DAP property
2020
| agency | GSA |
2121
| site_topic | analytics |
22-
| site_platform | cloud.gov |
22+
| site_platform | cloud.gov |
23+
24+
Scenario: Load a DAP-enabled page and check the built-in customer dimensions
25+
Given DAP is configured for agency "GSA"
26+
When I load the test site
27+
Then DAP will set custom dimensions for the DAP property
28+
| protocol | http: |
29+
| hostname_dimension | dap-test-site.local |
30+
| using_parallel_tracker | no |
31+
And DAP will set the "script_source" dimension to a string matching "https?:\/\/.*\/universal-federated-analytics-min.js"
32+
And DAP will set the "version" dimension to a string matching "\d{8} v\d+\.\d+ - ga4"
33+
34+
Scenario: Load a DAP-enabled page with a custom cookie timeout
35+
Given DAP is configured for agency "GSA"
36+
And DAP is configured with cookie timeout of 1 months
37+
When I load the test site
38+
Then DAP will set custom dimensions for the DAP property
39+
| cookie_expires | 2628000 |

features/gas4_functions.feature

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Feature: gas4() custom event API
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: gas4() sends a virtual page_view event
8+
When I load the test site
9+
And I execute script "window.gas4('page_view', {page_location: '/virtual/page', page_title: 'Virtual Page'})"
10+
Then a "page_view" event is sent to DAP with parameters
11+
| page_location | http://dap-test-site.local/virtual/page |
12+
| page_title | Virtual Page |
13+
14+
Scenario: gas4() sends a virtual page_view event setting default page title
15+
When I load the test site
16+
And I execute script "window.gas4('page_view', {page_location: '/virtual/page'})"
17+
Then a "page_view" event is sent to DAP with parameters
18+
| page_location | http://dap-test-site.local/virtual/page |
19+
| page_title | DAP test site |
20+
21+
Scenario: gas4() sends a file_download event
22+
When I load the test site
23+
And I execute script "window.gas4('file_download', {file_name: '/test.pdf', file_extension: 'pdf', link_text: 'Download Test PDF', link_id: 'download-link', link_url: 'https://example.gov/test.pdf', link_domain: 'example.gov', interaction_type: 'Mouse Click'})"
24+
Then a "file_download" event is sent to DAP with parameters
25+
| file_name | /test.pdf |
26+
| file_extension | pdf |
27+
| link_text | Download Test PDF |
28+
| link_id | download-link |
29+
| link_url | https://example.gov/test.pdf |
30+
| link_domain | example.gov |
31+
| interaction_type | Mouse Click |
32+
33+
Scenario: gas4() sends a form_start event
34+
When I load the test site
35+
And I execute script "window.gas4('form_start', {form_id: 'contact-form', form_name: 'Contact Form', form_destination: '/thank-you', section: 'body'})"
36+
Then a "form_start" event is sent to DAP with parameters
37+
| form_id | contact-form |
38+
| form_name | Contact Form |
39+
| form_destination | /thank-you |
40+
| section | body |
41+
42+
Scenario: gas4() sends a form_progress event
43+
When I load the test site
44+
And I execute script "window.gas4('form_progress', {form_id: 'contact-form', percent_scrolled: '50'})"
45+
Then a "form_progress" event is sent to DAP with parameters
46+
| form_id | contact-form |
47+
| percent_scrolled | 50 |
48+
49+
Scenario: gas4() sends a form_submit event
50+
When I load the test site
51+
And I execute script "window.gas4('form_submit', {form_step: 3, form_submit_text: 'Submit'})"
52+
Then a "form_submit" event is sent to DAP with parameters
53+
| form_step | 3 |
54+
| form_submit_text | Submit |
55+
56+
Scenario: gas4() sends a content_view event
57+
When I load the test site
58+
And I execute script "window.gas4('content_view', {content_type: 'article', content_id: '123'})"
59+
Then a "content_view" event is sent to DAP with parameters
60+
| content_type | article |
61+
| content_id | 123 |
62+
63+
Scenario: gas4() sends a share event
64+
When I load the test site
65+
And I execute script "window.gas4('share', {method: 'twitter', content_type: 'page', item_id: '123'})"
66+
Then a "share" event is sent to DAP with parameters
67+
| method | twitter |
68+
| content_type | page |
69+
| item_id | 123 |
70+
71+
Scenario: gas4() sends a social_click event
72+
When I load the test site
73+
And I execute script "window.gas4('social_click', {link_url: 'https://twitter.com', social_network: 'twitter'})"
74+
Then a "social_click" event is sent to DAP with parameters
75+
| link_url | https://twitter.com |
76+
| social_network | twitter |
77+
78+
Scenario: gas4() sends an image_click event
79+
When I load the test site
80+
And I execute script "window.gas4('image_click', {link_id: 'hero-image', link_url: '/about'})"
81+
Then a "image_click" event is sent to DAP with parameters
82+
| link_id | hero-image |
83+
| link_url | /about |
84+
85+
Scenario: gas4() sends a cta_click event
86+
When I load the test site
87+
And I click on element with selector "::-p-text(Learn More)"
88+
Then a "cta_click" event is sent to DAP with parameters
89+
| link_text | <link_text> |
90+
| link_domain | <link_domain> |
91+
| link_url | <link_url> |
92+
| link_id | <link_id> |
93+
| link_classes | <link_classes> |
94+
| outbound | <outbound> |
95+
| section | <section> |
96+
97+
Scenario: gas4() sends a navigation_click event
98+
When I load the test site
99+
And I click on element with selector "a[href='#home']"
100+
Then a "navigation_click" event is sent to DAP with parameters
101+
| link_text | <link_text> |
102+
| link_domain | <link_domain> |
103+
| link_url | <link_url> |
104+
| link_id | <link_id> |
105+
| link_classes | <link_classes> |
106+
| outbound | <outbound> |
107+
| section | <section> |
108+
| menu_type | <menu_type> |
109+
110+
Scenario: gas4() sends a was_this_helpful_submit event
111+
When I load the test site
112+
And I execute script "window.gas4('was_this_helpful_submit', {selection: 'yes', section: 'footer'})"
113+
Then a "was_this_helpful_submit" event is sent to DAP with parameters
114+
| selection | yes |
115+
| section | footer |
116+
117+
Scenario: gas4() sends a faq_click event
118+
When I load the test site
119+
And I click on element with selector "button::-p-text(FAQ)"
120+
Then a "faq_click" event is sent to DAP with parameters
121+
| selection | selection 1 |
122+
| section | <section> |
123+
124+
Scenario: gas4() sends an accordion_click event
125+
When I load the test site
126+
And I click on element with selector "button::-p-text(Accordion)"
127+
Then a "accordion_click" event is sent to DAP with parameters
128+
| selection | selection 1 |
129+
| section | <section> |
130+
131+
Scenario: gas4() sends an error event
132+
When I load the test site
133+
And I execute script "window.gas4('error', {type: '404', url: '/missing-page'})"
134+
Then a "error" event is sent to DAP with parameters
135+
| type | 404 |
136+
| url | /missing-page |
137+
138+
Scenario: gas4() sends a filter event
139+
When I load the test site
140+
And I execute script "window.gas4('filter', {filter_selection: 'date', section: 'results'})"
141+
Then a "filter" event is sent to DAP with parameters
142+
| filter_selection | date |
143+
| section | results |
144+
145+
Scenario: gas4() sends a sort event
146+
When I load the test site
147+
And I execute script "window.gas4('sort', {sort_selection: 'newest', section: 'results'})"
148+
Then a "sort" event is sent to DAP with parameters
149+
| sort_selection | newest |
150+
| section | results |
151+
152+
Scenario: gas4() with an invalid event name falls back to dap_event
153+
When I load the test site
154+
And I execute script "window.gas4('not_a_valid_event', {some_param: 'value'})"
155+
Then a "dap_event" event is sent to DAP with parameters
156+
| some_param | value |

features/gas_functions.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: gas() custom event API
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: gas() sends a virtual pageview
8+
When I load the test site
9+
And I execute script "window.gas('send', 'pageview', '/virtual/page')"
10+
Then a "page_view" event is sent to DAP with parameters
11+
| page_location | http://dap-test-site.local/virtual/page |
12+
| page_title | DAP test site |
13+
14+
Scenario: gas() sends a virtual pageview with a custom title
15+
When I load the test site
16+
And I execute script "window.gas('send', 'pageview', '/virtual/page', 'My Custom Title')"
17+
Then a "page_view" event is sent to DAP with parameters
18+
| page_location | http://dap-test-site.local/virtual/page |
19+
| page_title | My Custom Title |
20+
21+
Scenario: gas() sends a custom event
22+
When I load the test site
23+
And I execute script "window.gas('send', 'event', 'test_category', 'test_action', 'test_label', 1)"
24+
Then a "dap_event" event is sent to DAP with parameters
25+
| event_category | test_category |
26+
| event_action | test_action |
27+
| event_label | test_label |
28+
| event_value | 1 |
29+
| non_interaction | false |
30+
31+
Scenario: gas() sends a custom event with only category and action
32+
When I load the test site
33+
And I execute script "window.gas('send', 'event', 'only_category', 'only_action')"
34+
Then a "dap_event" event is sent to DAP with parameters
35+
| event_category | only_category |
36+
| event_action | only_action |
37+
| event_label | |
38+
| event_value | 0 |
39+
| non_interaction | false |

0 commit comments

Comments
 (0)