Skip to content

Commit a42e1ea

Browse files
authored
Merge pull request #6344 from emilghittasv/playwright-expand-group-coverage
Playwright expand coverage to group pages
2 parents 80a6b2a + 854fa46 commit a42e1ea

File tree

12 files changed

+747
-23
lines changed

12 files changed

+747
-23
lines changed

.github/workflows/playwright.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ on:
3838
- kbDashboard
3939
- exploreByTopics
4040
- searchTests
41+
- userGroupsTests
4142

4243
env:
4344
TEST_ACCOUNT_12: ${{secrets.AUTOMATION_TEST_ACCOUNT_12}}
@@ -103,7 +104,7 @@ jobs:
103104
if: success() || failure() && steps.create-sessions.outcome == 'success'
104105
run: |
105106
declare dispatch_test_suite="${{inputs.TestSuite}}"
106-
declare all_test_suites=("homePageTests" "topNavbarTests" "footerSectionTests" "contributePagesTests" "messagingSystem" "messagingSystemCleanup" "userContributionTests" "userProfile" "userSettings" "editUserProfileTests" "userQuestions" "contactSupportPage" "productSolutionsPage" "productSupportPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics", "searchTests")
107+
declare all_test_suites=("homePageTests" "topNavbarTests" "footerSectionTests" "contributePagesTests" "messagingSystem" "messagingSystemCleanup" "userContributionTests" "userProfile" "userSettings" "editUserProfileTests" "userQuestions" "contactSupportPage" "productSolutionsPage" "productSupportPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics", "searchTests", "userGroupsTests")
107108
if [ "$dispatch_test_suite" == "All" ] || [ "${{ github.event_name}}" == "schedule" ] ; then
108109
for test in "${all_test_suites[@]}"; do
109110
if ! poetry run pytest -m ${test} --numprocesses 4 --browser ${{ env.BROWSER }} --reruns 1; then

playwright_tests/core/utilities.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import re
66
import json
77
import random
8+
from PIL import Image
9+
from PIL import ImageChops
810
from typing import Any, Union
911
from datetime import datetime
1012
from nltk import SnowballStemmer, WordNetLemmatizer
11-
from playwright.sync_api import Page
13+
from playwright.sync_api import Page, Locator
1214
from playwright_tests.messages.homepage_messages import HomepageMessages
1315
from requests.exceptions import HTTPError
1416
from playwright_tests.pages.top_navbar import TopNavbar
@@ -192,6 +194,42 @@ def navigate_to_link(self, link: str):
192194
if response.status >= 400:
193195
self.refresh_page()
194196

197+
def upload_file(self, element: str, path_to_file: str):
198+
"""This helper function uploads the test-image.png file to a given file element chooser.
199+
200+
Args:
201+
element (str): The element file chooser locator's xpath.
202+
path_to_file (str): The path to the file to be uploaded.
203+
"""
204+
with self.page.expect_file_chooser() as file_chooser:
205+
self.page.locator(element).click()
206+
file_chooser_value = file_chooser.value
207+
file_chooser_value.set_files(os.path.abspath(path_to_file))
208+
209+
def screenshot_the_locator(self, locator: Locator, path_to_save: str):
210+
"""
211+
This helper function takes a screenshot of a given locator.
212+
213+
Args:
214+
locator (Locator): The locator of the targeted element.
215+
path_to_save (str): The path where to save the screenshot.
216+
"""
217+
locator.screenshot(path=path_to_save)
218+
219+
def are_images_different(self, image1_path: str, image2_path: str) -> tuple:
220+
"""
221+
This helper function compares two images and returns the bounding box of the difference.
222+
If there is no difference this helper function will return None.
223+
224+
Args:
225+
image1_path (str): The path of the first image
226+
image2_path (str): The path of the second image
227+
"""
228+
first_image = Image.open(image1_path).convert('RGB')
229+
second_image = Image.open(image2_path).convert('RGB')
230+
231+
return ImageChops.difference(first_image, second_image).getbbox()
232+
195233
def set_extra_http_headers(self, headers):
196234
"""
197235
This helper function sets some extra headers to the request.
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
11
class UserGroupMessages:
2-
def get_user_added_success_message(self, username: str) -> str:
2+
DELETE_AVATAR_PAGE_INFO = ("You are about to permanently delete the avatar. "
3+
"This cannot be undone! You can always upload another avatar to "
4+
"replace the current one.")
5+
GROUP_INFORMATION_UPDATE_NOTIFICATION = "Group information updated successfully!"
6+
7+
def get_user_added_success_message(username: str) -> str:
8+
"""Get the user added success message.
9+
10+
Args:
11+
username (str): The username of the user added to the group
12+
"""
313
return f"{username} added to the group successfully!"
14+
15+
def get_user_removed_success_message(username: str) -> str:
16+
"""Get the user removed success message.
17+
18+
Args:
19+
username (str): The username of the user removed from the group
20+
"""
21+
return f"{username} removed from the group successfully!"
22+
23+
def get_change_avatar_page_header(user_group: str) -> str:
24+
"""Get the change avatar page header.
25+
26+
Args:
27+
user_group (str): The group name.
28+
"""
29+
return f"Change {user_group} group avatar"
30+
31+
def get_change_uploaded_avatar_page_header(user_group: str) -> str:
32+
"""Get the change uploaded avatar page header.
33+
34+
Args:
35+
user_group (str): The group name.
36+
"""
37+
return f"Change {user_group} group avatar"
38+
39+
def get_delete_uploaded_avatar_page_header(user_group: str) -> str:
40+
"""Get the delete uploaded avatar page header.
41+
42+
Args:
43+
user_group (str): The group name.
44+
"""
45+
return f"Are you sure you want to delete the {user_group} group avatar?"
46+
47+
def get_delete_user_header(username: str, group: str) -> str:
48+
"""Get the delete user page header.
49+
50+
Args:
51+
username (str): The username of the user to delete.
52+
group (str): The group name.
53+
"""
54+
return f"Are you sure you want to remove {username} from {group}?"
55+
56+
def get_edit_profile_information_page_header(group_name: str) -> str:
57+
"""Get the edit profile information page header.
58+
59+
Args:
60+
group_name (str): The group name.
61+
"""
62+
return f"Edit {group_name} profile information"

0 commit comments

Comments
 (0)