Skip to content

Commit

Permalink
Merge pull request #6344 from emilghittasv/playwright-expand-group-co…
Browse files Browse the repository at this point in the history
…verage

Playwright expand coverage to group pages
  • Loading branch information
emilghittasv authored Nov 12, 2024
2 parents 80a6b2a + 854fa46 commit a42e1ea
Show file tree
Hide file tree
Showing 12 changed files with 747 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ on:
- kbDashboard
- exploreByTopics
- searchTests
- userGroupsTests

env:
TEST_ACCOUNT_12: ${{secrets.AUTOMATION_TEST_ACCOUNT_12}}
Expand Down Expand Up @@ -103,7 +104,7 @@ jobs:
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
declare dispatch_test_suite="${{inputs.TestSuite}}"
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")
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")
if [ "$dispatch_test_suite" == "All" ] || [ "${{ github.event_name}}" == "schedule" ] ; then
for test in "${all_test_suites[@]}"; do
if ! poetry run pytest -m ${test} --numprocesses 4 --browser ${{ env.BROWSER }} --reruns 1; then
Expand Down
40 changes: 39 additions & 1 deletion playwright_tests/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import re
import json
import random
from PIL import Image
from PIL import ImageChops
from typing import Any, Union
from datetime import datetime
from nltk import SnowballStemmer, WordNetLemmatizer
from playwright.sync_api import Page
from playwright.sync_api import Page, Locator
from playwright_tests.messages.homepage_messages import HomepageMessages
from requests.exceptions import HTTPError
from playwright_tests.pages.top_navbar import TopNavbar
Expand Down Expand Up @@ -192,6 +194,42 @@ def navigate_to_link(self, link: str):
if response.status >= 400:
self.refresh_page()

def upload_file(self, element: str, path_to_file: str):
"""This helper function uploads the test-image.png file to a given file element chooser.
Args:
element (str): The element file chooser locator's xpath.
path_to_file (str): The path to the file to be uploaded.
"""
with self.page.expect_file_chooser() as file_chooser:
self.page.locator(element).click()
file_chooser_value = file_chooser.value
file_chooser_value.set_files(os.path.abspath(path_to_file))

def screenshot_the_locator(self, locator: Locator, path_to_save: str):
"""
This helper function takes a screenshot of a given locator.
Args:
locator (Locator): The locator of the targeted element.
path_to_save (str): The path where to save the screenshot.
"""
locator.screenshot(path=path_to_save)

def are_images_different(self, image1_path: str, image2_path: str) -> tuple:
"""
This helper function compares two images and returns the bounding box of the difference.
If there is no difference this helper function will return None.
Args:
image1_path (str): The path of the first image
image2_path (str): The path of the second image
"""
first_image = Image.open(image1_path).convert('RGB')
second_image = Image.open(image2_path).convert('RGB')

return ImageChops.difference(first_image, second_image).getbbox()

def set_extra_http_headers(self, headers):
"""
This helper function sets some extra headers to the request.
Expand Down
61 changes: 60 additions & 1 deletion playwright_tests/messages/user_groups_messages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
class UserGroupMessages:
def get_user_added_success_message(self, username: str) -> str:
DELETE_AVATAR_PAGE_INFO = ("You are about to permanently delete the avatar. "
"This cannot be undone! You can always upload another avatar to "
"replace the current one.")
GROUP_INFORMATION_UPDATE_NOTIFICATION = "Group information updated successfully!"

def get_user_added_success_message(username: str) -> str:
"""Get the user added success message.
Args:
username (str): The username of the user added to the group
"""
return f"{username} added to the group successfully!"

def get_user_removed_success_message(username: str) -> str:
"""Get the user removed success message.
Args:
username (str): The username of the user removed from the group
"""
return f"{username} removed from the group successfully!"

def get_change_avatar_page_header(user_group: str) -> str:
"""Get the change avatar page header.
Args:
user_group (str): The group name.
"""
return f"Change {user_group} group avatar"

def get_change_uploaded_avatar_page_header(user_group: str) -> str:
"""Get the change uploaded avatar page header.
Args:
user_group (str): The group name.
"""
return f"Change {user_group} group avatar"

def get_delete_uploaded_avatar_page_header(user_group: str) -> str:
"""Get the delete uploaded avatar page header.
Args:
user_group (str): The group name.
"""
return f"Are you sure you want to delete the {user_group} group avatar?"

def get_delete_user_header(username: str, group: str) -> str:
"""Get the delete user page header.
Args:
username (str): The username of the user to delete.
group (str): The group name.
"""
return f"Are you sure you want to remove {username} from {group}?"

def get_edit_profile_information_page_header(group_name: str) -> str:
"""Get the edit profile information page header.
Args:
group_name (str): The group name.
"""
return f"Edit {group_name} profile information"
Loading

0 comments on commit a42e1ea

Please sign in to comment.