diff --git a/.gitignore b/.gitignore index 5d000003..cc37a4f9 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ allure-report/* reports/screenshots/* /test_data/visualtesting/test/* /output/ +/test_data/files/* diff --git a/frontend/test_project/features/api/api_tests.feature b/frontend/test_project/features/api/api_tests.feature index 9d0f8c06..8a0b5ef4 100644 --- a/frontend/test_project/features/api/api_tests.feature +++ b/frontend/test_project/features/api/api_tests.feature @@ -21,7 +21,7 @@ Feature: Test HTTP methods for a REST API Given I set the GET endpoint to '/posts' for fetching posts When I send a GET HTTP request # Failing the test on purpose to see the failure in the report - Then I expect the HTTP response code of 'GET' to be '2000' + Then I expect the HTTP response code of 'GET' to be '200' And I expect the response body of 'GET' to be non-empty @api_smoke diff --git a/frontend/test_project/features/api/test_feature.py b/frontend/test_project/features/api/test_feature.py index 75678810..22e051a8 100644 --- a/frontend/test_project/features/api/test_feature.py +++ b/frontend/test_project/features/api/test_feature.py @@ -1,17 +1,23 @@ from os import environ -import pytest from main.backend.common.step_definitions.steps_common import * from assertpy import assert_that from openai import OpenAI +import pytest +from selenium import webdriver +from selenium.webdriver.common.by import By +from time import sleep + +from main.frontend.common.step_definitions import open_base_url, maximize, page_title + logger = structlog.get_logger(__name__) client = OpenAI(api_key=environ.get("OPEN_KEY")) - API_POST_CALL = "post_call" DELETE_ENDPOINT = "/posts/1" POST_ENDPOINT = "/posts" +chrome_driver = webdriver.Chrome() @pytest.mark.nondestructive @@ -26,7 +32,7 @@ def test_send_post_request(request, api_response_container): test_case_name=request.node.name, ) set_request_endpoint(request, request_name=API_POST_CALL, base_url='{%API_BASE_URL%}', endpoint=POST_ENDPOINT) - set_request_headers(request, request_name=API_POST_CALL,headers="./test_data/api/payloads/sample/headers.json") + set_request_headers(request, request_name=API_POST_CALL, headers="./test_data/api/payloads/sample/headers.json") add_json_payload(request, request_name=API_POST_CALL, json_payload="./test_data/api/payloads/post_payload_1.json") make_api_request(request, api_response_container, request_name=API_POST_CALL, request_type='POST') @@ -39,6 +45,37 @@ def test_send_post_request(request, api_response_container): ) +@pytest.mark.nondestructive +@pytest.mark.automated +@pytest.mark.hrmlogin +@pytest.mark.test_name("Login into OrangeHRM system and logout") +def test_login(): + logger.info( + "Scenario is started" + ) + chrome_driver.get('https://lambdatest.github.io/sample-todo-app/') + chrome_driver.maximize_window() + + title = chrome_driver.title + assert 'Sample page - lambdatest.com' in title + + first_checkbox = chrome_driver.find_element(By.XPATH, "//input[@name='li1']") + first_checkbox.click() + second_checkbox = chrome_driver.find_element(By.XPATH, "//input[@name='li2']") + second_checkbox.click() + field = chrome_driver.find_element(By.XPATH, "//input[@id='sampletodotext']") + field.send_keys("testing") + button = chrome_driver.find_element(By.XPATH, "//input[@id='addbutton']") + button.click() + result = chrome_driver.find_element(By.XPATH, "//li[6]/span[@class='done-false']").text + assert 'testing' in result + sleep(5) + chrome_driver.close() + logger.info( + "Scenario is completed successfully" + ) + + # A sample test to verify the open API call @pytest.mark.nondestructive @pytest.mark.automated diff --git a/frontend/test_project/features/web/web_tests.feature b/frontend/test_project/features/web/web_tests.feature index de961438..77ab83c2 100644 --- a/frontend/test_project/features/web/web_tests.feature +++ b/frontend/test_project/features/web/web_tests.feature @@ -176,6 +176,15 @@ Feature: OrangeHRM Login and Modus QA blog And I click item 'Yes' for element 'Modus_Site > Careers > protection_dropdown' - @email @automated - Scenario: Email verification - When I get email for 'moduspytestboilerplate@gmail.com' \ No newline at end of file + @email @automated @firefox + Scenario: Email Verification with email link + Given I set web base url '{%BASE_URL%}' + And Browser is maximized + And The title is 'OrangeHRM' + When The element 'OrangeHRM > username' is displayed + And I set text '{%HRM_USER_NAME%}' to field 'OrangeHRM > username' + And I set text '{%HRM_PASSWORD%}' to field 'OrangeHRM > password' + And I click on element 'OrangeHRM > login_button' + Then The title is 'OrangeHRM' + And The page url contains 'dashboard' + When I get link from email 'moduspytestboilerplate@gmail.com' \ No newline at end of file diff --git a/main/frontend/common/step_definitions/browser_navigation.py b/main/frontend/common/step_definitions/browser_navigation.py index 90c2f5c4..ed867f3d 100644 --- a/main/frontend/common/step_definitions/browser_navigation.py +++ b/main/frontend/common/step_definitions/browser_navigation.py @@ -22,7 +22,6 @@ # WEB context Predefined Step -# ID 101, 102 @given(parsers.re("The browser resolution is '(?P.*)' per '(?P.*)'"), converters=dict(width=data_manager.text_formatted, height=data_manager.text_formatted), ) @given(parsers.re("My screen resolution is '(?P.*)' by '(?P.*)' pixels"), @@ -36,7 +35,6 @@ def window_size(width: int, height: int, selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 103 @given("Browser is maximized") @when("Browser is maximized") def maximize(selenium_generics: SeleniumGenerics): @@ -44,7 +42,6 @@ def maximize(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 104 @given(parsers.re("I am on the (url|page|site) '(?P.*)'"), converters=dict(page_url=data_manager.text_formatted), ) @when(parsers.re("I am on the (url|page|site) '(?P.*)'"), @@ -60,7 +57,6 @@ def open_base_url(selenium_generics: SeleniumGenerics, base_url): # WEB context Predefined Step -# ID 105 @given(parsers.re("I navigate to external page '(?P.*)'"), converters=dict(url=data_manager.text_formatted), ) @when(parsers.re("I navigate to external page '(?P.*)'"), @@ -70,7 +66,6 @@ def navigate_to_external_page(selenium_generics: SeleniumGenerics, url: str): # WEB context Predefined Step -# ID 106 @given(parsers.re("I get current browser url and store it to '(?P.*)'")) @when(parsers.re("I get current browser url and store it to '(?P.*)'")) @then(parsers.re("I get current browser url and store it to '(?P.*)'")) @@ -121,7 +116,6 @@ def page_title_is_not(selenium_generics: SeleniumGenerics, soft_assert: str, tit # WEB context Predefined Step -# ID 110 @then(parsers.re("(With soft assertion '(?P.*)' )?I expect that the title contains '(?P.*)'"), converters=dict(title=data_manager.text_formatted), ) def check_title_contains(selenium_generics: SeleniumGenerics, soft_assert: str, title: str): @@ -133,7 +127,6 @@ def check_title_contains(selenium_generics: SeleniumGenerics, soft_assert: str, # WEB context Predefined Step -# ID 111 @then( parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that the title does not contain '(?P<title>.*)'"), converters=dict(title=data_manager.text_formatted), ) @@ -146,7 +139,6 @@ def check_title_not_contains(selenium_generics: SeleniumGenerics, soft_assert: s # WEB context Predefined Step -# ID 112 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is '(?P<url>.*)'"), converters=dict(url=data_manager.text_formatted), ) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is '(?P<url>.*)'"), @@ -162,7 +154,6 @@ def given_page_url_is(selenium_generics: SeleniumGenerics, soft_assert: str, url # WEB context Predefined Step -# ID 113 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is not '(?P<url>.*)'"), converters=dict(url=data_manager.text_formatted), ) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page url is not '(?P<url>.*)'"), @@ -178,7 +169,6 @@ def given_page_url_is_not(selenium_generics: SeleniumGenerics, soft_assert: str, # WEB context Predefined Step -# ID 114 @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The page (path is|url contains) '(?P<url>.*)'"), converters=dict(url=data_manager.text_formatted), ) def check_page_url_contains(selenium_generics: SeleniumGenerics, soft_assert: str, url: str): @@ -190,7 +180,6 @@ def check_page_url_contains(selenium_generics: SeleniumGenerics, soft_assert: st # WEB context Predefined Step -# ID 115 @then(parsers.re( "(With soft assertion '(?P<soft_assert>.*)' )?The page (path is not|url does not contain) '(?P<url>.*)'"), converters=dict(url=data_manager.text_formatted), ) @@ -203,7 +192,6 @@ def check_page_url_not_contains(selenium_generics: SeleniumGenerics, soft_assert # WEB context Predefined Step -# ID 116 @given(parsers.re("I refresh the current page")) @when(parsers.re("I refresh the current page")) def refresh_page(selenium_generics: SeleniumGenerics): @@ -211,7 +199,6 @@ def refresh_page(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 117 @given(parsers.re("There is just one (browser tab|window) open")) @when(parsers.re("There is just one (browser tab|window) open")) def close_all_but_first_tab(selenium_generics: SeleniumGenerics): @@ -223,7 +210,6 @@ def close_all_but_first_tab(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 118 @given(parsers.re("I open new tab with url '(?P<page_url>.*)'"), converters=dict(page_url=data_manager.text_formatted), ) @when(parsers.re("I open new tab with url '(?P<page_url>.*)'"), @@ -233,7 +219,6 @@ def open_specific_tab(selenium_generics: SeleniumGenerics, base_url: str, page_u # WEB context Predefined Step -# ID 119 @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The url '(?P<url>.*)' is opened in a new (tab|window)"), converters=dict(url=data_manager.text_formatted), ) def check_is_opened_in_new_window(selenium_generics: SeleniumGenerics, soft_assert: str, url: str): @@ -246,7 +231,6 @@ def check_is_opened_in_new_window(selenium_generics: SeleniumGenerics, soft_asse # WEB context Predefined Step -# ID 120 @given(parsers.re("I close the last opened window")) @given(parsers.re("I close the last opened tab")) @when(parsers.re("I close the last opened window")) @@ -266,7 +250,6 @@ def switch_to_last(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 122 @then(parsers.re( "(With soft assertion '(?P<soft_assert>.*)' )?There are '(?P<count>.*)' (tabs|windows) currently opened"), converters=dict(count=data_manager.text_formatted)) @@ -279,7 +262,6 @@ def check_number_of_tabs(selenium_generics: SeleniumGenerics, soft_assert: str, # WEB context Predefined Step -# ID 123 @given(parsers.re("I close the current opened tab")) @when(parsers.re("I close the current opened tab")) def close_current_opened_tab(selenium_generics: SeleniumGenerics): @@ -367,7 +349,6 @@ def disable_cache(driver, cache_option: str): # WEB context Predefined Step -# ID 132 @given(parsers.re("I attach file '(?P<file_path>.*)' to input field '(?P<locator_path>.*)'"), converters=dict(file_path=data_manager.text_formatted), ) @when(parsers.re("I attach file '(?P<file_path>.*)' to input field '(?P<locator_path>.*)'"), @@ -382,7 +363,6 @@ def attach_file(selenium_generics: SeleniumGenerics, file_path: str, locators: L # WEB context Predefined Step -# ID 133 @given(parsers.re( "(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' contains the value '(?P<value>.*)'"), converters=dict(value=data_manager.text_formatted)) @@ -401,7 +381,6 @@ def check_cookie_content(selenium_generics: SeleniumGenerics, soft_assert: str, # WEB context Predefined Step -# ID 134 @given(parsers.re( "(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not contain the value '(?P<value>.*)'"), converters=dict(value=data_manager.text_formatted)) @@ -420,7 +399,6 @@ def check_cookie_content_is_not(selenium_generics: SeleniumGenerics, soft_assert # WEB context Predefined Step -# ID 135 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists")) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists")) @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' exists")) @@ -433,7 +411,6 @@ def check_cookie_exists(selenium_generics: SeleniumGenerics, soft_assert: str, n # WEB context Predefined Step -# ID 136 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist")) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist")) @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The cookie '(?P<name>.*)' does not exist")) @@ -446,7 +423,6 @@ def check_cookie_does_not_exist(selenium_generics: SeleniumGenerics, soft_assert # WEB context Predefined Step -# ID 137 @given("I fetch existing cookies from the site") @when("I fetch existing cookies from the site") def fetch_cookies(selenium_generics: SeleniumGenerics): @@ -454,7 +430,6 @@ def fetch_cookies(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 138, 139 @given( parsers.re("I update the value of newly added cookie '(?P<name>.*)' with '(?P<value>.*)' for path '(?P<path>.*)'"), converters=dict(value=data_manager.text_formatted)) @@ -470,7 +445,6 @@ def check_cookie_content(selenium_generics: SeleniumGenerics, name, value: str, # WEB context Predefined Step -# ID 140 @given(parsers.re("I delete the cookie '(?P<name>.*)'")) @when(parsers.re("I delete the cookie '(?P<name>.*)'")) def delete_cookie(selenium_generics: SeleniumGenerics, name): @@ -478,7 +452,6 @@ def delete_cookie(selenium_generics: SeleniumGenerics, name): # WEB context Predefined Step -# ID 141 @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect the cookies to be present")) def check_cookies_presence(selenium_generics: SeleniumGenerics, soft_assert: str): if soft_assert is not None and soft_assert.lower() == 'true': @@ -489,7 +462,6 @@ def check_cookies_presence(selenium_generics: SeleniumGenerics, soft_assert: str # WEB context Predefined Step -# ID 142, 143 @then(parsers.re( "(With soft assertion '(?P<soft_assert>.*)' )?I expect cookie '(?P<name>.*)' with value '(?P<value>.*)' to be present"), converters=dict(value=data_manager.text_formatted)) @@ -505,7 +477,6 @@ def check_cookie_presence(selenium_generics: SeleniumGenerics, soft_assert: str, # WEB context Predefined Step -# ID 144 @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect cookie '(?P<name>.*)' to be deleted")) def check_cookie_delete(selenium_generics: SeleniumGenerics, soft_assert: str, name): if soft_assert is not None and soft_assert.lower() == 'true': @@ -516,7 +487,6 @@ def check_cookie_delete(selenium_generics: SeleniumGenerics, soft_assert: str, n # WEB context Predefined Step -# ID 145 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened")) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened")) @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is opened")) @@ -529,7 +499,6 @@ def step_presence_of_alert(selenium_generics: SeleniumGenerics, soft_assert: str # WEB context Predefined Step -# ID 146 @given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened")) @when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened")) @then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?A (alertbox|confirmbox|prompt) is not opened")) @@ -542,7 +511,6 @@ def check_modal_not_present(selenium_generics: SeleniumGenerics, soft_assert: st # WEB context Predefined Step -# ID 147 @given(parsers.re("I accept popup (prompt|alertbox|confirmbox)")) @when(parsers.re("I accept popup (prompt|alertbox|confirmbox)")) def accept_alert(selenium_generics: SeleniumGenerics): @@ -550,7 +518,6 @@ def accept_alert(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 148 @given(parsers.re("I dismiss popup (prompt|alertbox|confirmbox)")) @when(parsers.re("I dismiss popup (prompt|alertbox|confirmbox)")) def dismiss_modal(selenium_generics: SeleniumGenerics): @@ -558,7 +525,6 @@ def dismiss_modal(selenium_generics: SeleniumGenerics): # WEB context Predefined Step -# ID 149 @given(parsers.re("I enter '(?P<text>.*)' into popup (alertbox|confirmbox|prompt)"), converters=dict(text=data_manager.text_formatted), ) @when(parsers.re("I enter '(?P<text>.*)' into popup (alertbox|confirmbox|prompt)"), @@ -568,7 +534,6 @@ def check_modal(selenium_generics: SeleniumGenerics, text: str): # WEB context Predefined Step -# ID 150, 151 @given(parsers.re("I set the (locale|language) for locators to '(?P<locale>.*)'"), converters=dict(locale=data_manager.text_formatted), ) @when(parsers.re("I set the (locale|language) for locators to '(?P<locale>.*)'"), diff --git a/main/frontend/common/step_definitions/date_time.py b/main/frontend/common/step_definitions/date_time.py index 76557f16..91cbddea 100644 --- a/main/frontend/common/step_definitions/date_time.py +++ b/main/frontend/common/step_definitions/date_time.py @@ -20,7 +20,6 @@ # WEB context Predefined Step -# ID 1001 @given(parsers.re("I pause for '(?P<seconds>.*)' s"), converters=dict(seconds=int)) @when(parsers.re("I pause for '(?P<seconds>.*)' s"), converters=dict(seconds=int)) def pause_execution(seconds: int): @@ -28,7 +27,6 @@ def pause_execution(seconds: int): # WEB & MOBILE contexts Predefined Step -# ID 1002 @given(parsers.re(r"I add current date to '(?P<locator_path>.*)' with '(?P<date_format>MM/dd/yyyy|MM/dd/yy|dd/MM/yyyy|dd/MM/yy|dd MMM yyyy)'")) @when(parsers.re(r"I add current date to '(?P<locator_path>.*)' with '(?P<date_format>MM/dd/yyyy|MM/dd/yy|dd/MM/yyyy|dd/MM/yy|dd MMM yyyy)'")) def add_current_date_for_element(selenium_generics: SeleniumGenerics, locators: Locators, locator_path, date_format: str): @@ -52,7 +50,6 @@ def add_current_date_for_element(selenium_generics: SeleniumGenerics, locators: # WEB & MOBILE contexts Predefined Step -# ID 1003 @given(parsers.re(r"I add random '(?P<direction>future|past)' date to '(?P<locator_path>.*)' with '(?P<date_format>MM/dd/yyyy|MM/dd/yy|dd/MM/yyyy|dd/MM/yy|dd MMM yyyy)' format")) @when(parsers.re(r"I add random '(?P<direction>future|past)' date to '(?P<locator_path>.*)' with '(?P<date_format>MM/dd/yyyy|MM/dd/yy|dd/MM/yyyy|dd/MM/yy|dd MMM yyyy)' format")) def add_custom_date_for_element(selenium_generics: SeleniumGenerics, locators: Locators, locator_path, date_format: str, direction: str): @@ -85,7 +82,6 @@ def add_custom_date_for_element(selenium_generics: SeleniumGenerics, locators: L # WEB & MOBILE contexts Predefined Step -# ID 1004 @given(parsers.re(r"I add '(?P<direction>Past|Current|Future)' time to '(?P<locator_path>.*)' with '(?P<time_format>HH:MM:SS|HH:MM)' format(\s+)?((?:and clock format)\s+(?:')(?P<clock_format>\w+)(?:'))?(\s+)?((?:and delimiter)\s+(?:')(?P<delimiter>.*)(?:'))?$")) @when(parsers.re(r"I add '(?P<direction>Past|Current|Future)' time to '(?P<locator_path>.*)' with '(?P<time_format>HH:MM:SS|HH:MM)' format(\s+)?((?:and clock format)\s+(?:')(?P<clock_format>\w+)(?:'))?(\s+)?((?:and delimiter)\s+(?:')(?P<delimiter>.*)(?:'))?$")) def add_custom_time_for_element(selenium_generics: SeleniumGenerics, locators: Locators, locator_path, time_format: str, direction: str, delimiter: str, clock_format: str): diff --git a/main/frontend/common/step_definitions/email.py b/main/frontend/common/step_definitions/email.py index 0ce48fc3..9937aa2e 100644 --- a/main/frontend/common/step_definitions/email.py +++ b/main/frontend/common/step_definitions/email.py @@ -1,46 +1,47 @@ -import structlog - import base64 -import os, re +import json +import os +import re import time import pytest -import json - +import structlog from bs4 import BeautifulSoup +from main.frontend.common.step_definitions import store_env_variable_in_local_env from main.utils.email_reader import create_json +logger = structlog.get_logger(__name__) + PROJECT_DIR = os.getcwd() test_data_dir = os.path.join(PROJECT_DIR, "test_data/files/email_data.json") from pytest_bdd import parsers, when, then from main.frontend.common.helpers.selenium_generics import SeleniumGenerics -logger = structlog.get_logger(__name__) - -@when(parsers.re("I get email for '(?P<user_type>.*)'"), +@when(parsers.re("I get link from email '(?P<user_type>.*)'"), + converters=dict(user_type=str)) +@then(parsers.re("I get link from email '(?P<user_type>.*)'"), converters=dict(user_type=str)) def check_email(user_type, selenium_generics: SeleniumGenerics): - time.sleep(5) create_json() from datetime import date today = date.today() from datetime import timedelta - yesterday = today - timedelta(days=1) + thirty_days = today - timedelta(days=30) date_today = today.strftime("%d %b %Y") - date_yesterday = yesterday.strftime("%d %b %Y") + date_old = thirty_days.strftime("%d %b %Y") if '0' in date_today[0]: date_today = date_today[1:] f = open(test_data_dir) data = json.load(f) for i in data: value = i - if "Test Data" in value["Subject"] or "Test Data" in value["Subject"] and \ - "noreply@test.com" in value["From"] and date_today in value["Date"] or \ - date_yesterday in value["Date"] and user_type in value["To"]: + if "Test Project Data" in value["Subject"] or "Test Data" in value["Subject"] and \ + "tauqirsarwar1@gmail.com" in value["From"] and date_today in value["Date"] or \ + date_old in value["Date"] and user_type in value["To"]: decoded_data = base64.b64decode(value["Message"]) soup = BeautifulSoup(decoded_data, "lxml") email_body = str(soup.body()[0]) @@ -57,7 +58,7 @@ def check_email(user_type, selenium_generics: SeleniumGenerics): email_body) new_url = '' for j in url: - if 'Test Data' in j or 'Test Data' in j: + if 'Test Project Data' in j or 'Test Data' in j: new_url = j final_url = str(new_url).replace('amp;', '') pytest.globalDict['final_url'] = final_url diff --git a/main/frontend/common/step_definitions/excel_and_csv.py b/main/frontend/common/step_definitions/excel_and_csv.py index 94de1de9..be9002cc 100644 --- a/main/frontend/common/step_definitions/excel_and_csv.py +++ b/main/frontend/common/step_definitions/excel_and_csv.py @@ -12,7 +12,6 @@ logger = structlog.get_logger(__name__) -# ID 901 @given(parsers.re("Text inside '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' is equal to '(?P<expected_text>.+)'"), converters=dict(cell=data_manager.text_formatted, sheet_name=data_manager.text_formatted, expected_text=data_manager.text_formatted)) @when(parsers.re("Text inside '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' is equal to '(?P<expected_text>.+)'"), @@ -36,7 +35,6 @@ def cell_text_contains(cell:str, sheet_name: str, file_path: str, expected_text: assert_that(sheet[cell].value).contains(expected_text) -# ID 903 @given(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' does not contain any text"), converters=dict(cell=data_manager.text_formatted, sheet_name=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' does not contain any text"), @@ -48,7 +46,6 @@ def cell_text_is_empty(cell:str, sheet_name: str, file_path: str): assert_that(sheet[cell].value).is_none() -# ID 904 @given(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' text is equal with the text of the '(?P<locator_path>.+)'"), converters=dict(cell=data_manager.text_formatted, sheet_name=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' text is equal with the text of the '(?P<locator_path>.+)'"), @@ -60,7 +57,6 @@ def cell_text_equals_element_text(selenium_generics, locators, cell:str, sheet_n assert_that(sheet[cell].value).is_equal_to(selenium_generics.get_element_text(locators.parse_and_get(locator_path, selenium_generics))) -# ID 905 @given(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' is contained in the text of '(?P<locator_path>.+)'"), converters=dict(cell=data_manager.text_formatted, sheet_name=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.+)' on sheet '(?P<sheet_name>.+)' of excel file '(?P<file_path>.+)' is contained in the text of '(?P<locator_path>.+)'"), @@ -72,7 +68,6 @@ def element_text_contains_cell_text(selenium_generics, locators, cell:str, sheet assert_that(selenium_generics.get_element_text(locators.parse_and_get(locator_path, selenium_generics))).contains(sheet[cell].value) -# ID 906 @given(parsers.re("I delete '(?P<file_path>.*)' file")) @when(parsers.re("I delete '(?P<file_path>.*)' file")) def delete_file(file_path: str): @@ -91,7 +86,6 @@ def create_excel_file(file_name: str, file_path: str): openpyxl.Workbook().save(excel_file.as_posix()) -# ID 908 @given(parsers.re("I write '(?P<text>.*)' to '(?P<cell>.*)' on '(?P<sheet_name>.*)' of excel file '(?P<file_path>.*)'"), converters=dict(cell=data_manager.text_formatted, sheet_name=data_manager.text_formatted, text=data_manager.text_formatted)) @@ -105,7 +99,6 @@ def write_text_to_excel_file(text: str, cell: str, sheet_name: str, file_path: s wb.save(excel_file) -# ID 911 @given(parsers.re("Number of total rows on '(?P<sheet_name>.*)' of excel file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), converters=dict(row_count=data_manager.text_formatted, sheet_name=data_manager.text_formatted)) @when(parsers.re("Number of total rows on '(?P<sheet_name>.*)' of excel file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), @@ -121,7 +114,6 @@ def total_rows_number_with_data_is_equal_to(sheet_name: str, file_path: str, row assert_that(int(num_rows)).is_equal_to(int(row_count)) -# ID 912 @given(parsers.re("Number of rows containing '(?P<expected_text>.*)' on '(?P<sheet_name>.*)' of excel file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), converters=dict(row_count=data_manager.text_formatted, sheet_name=data_manager.text_formatted, text=data_manager.text_formatted)) @when(parsers.re("Number of rows containing '(?P<expected_text>.*)' on '(?P<sheet_name>.*)' of excel file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), @@ -137,7 +129,6 @@ def number_rows_with_text_is_equal_to(expected_text: str, sheet_name: str, file_ assert_that(int(num_rows)).is_equal_to(int(row_count)) -# ID 913 @given(parsers.re("Text inside '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' is equal to '(?P<expected_text>.+)'"), converters=dict(expected_text=data_manager.text_formatted, cell=data_manager.text_formatted)) @when(parsers.re("Text inside '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' is equal to '(?P<expected_text>.+)'"), @@ -161,7 +152,6 @@ def csv_cell_text_is_equal_to(cell: str, file_path: str, expected_text: str): assert_that(sheet[cell].value).is_equal_to(expected_text) -# ID 914 @given(parsers.re("Text inside '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' contains '(?P<expected_text>.+)'"), converters=dict(expected_text=data_manager.text_formatted, cell=data_manager.text_formatted)) @when(parsers.re("Text inside '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' contains '(?P<expected_text>.+)'"), @@ -185,7 +175,6 @@ def csv_cell_text_contains(cell: str, file_path: str, expected_text: str): assert_that(sheet[cell].value).contains(expected_text) -# ID 915 @given(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' text is equal with the text of the '(?P<locator_path>.+)'"), converters=dict(cell=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' text is equal with the text of the '(?P<locator_path>.+)'"), @@ -209,7 +198,6 @@ def csv_cell_text_equals_element_text(selenium_generics, locators, cell: str, fi assert_that(sheet[cell].value).is_equal_to(selenium_generics.get_element_text(locators.parse_and_get(locator_path, selenium_generics))) -# ID 916 @given(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' is contained in the text of '(?P<locator_path>.+)'"), converters=dict(cell=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' is contained in the text of '(?P<locator_path>.+)'"), @@ -234,7 +222,6 @@ def element_text_contains_csv_cell_text(selenium_generics, locators, cell: str, sheet[cell].value) -# ID 917 @given(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' does not contain any text"), converters=dict(cell=data_manager.text_formatted)) @when(parsers.re("The '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)' does not contain any text"), @@ -258,7 +245,6 @@ def csv_cell_text_is_empty(cell: str, file_path: str): assert_that(sheet[cell].value).is_empty() -# ID 918 @given(parsers.re("Number of rows containing '(?P<expected_text>.*)' of csv file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), converters=dict(expected_text=data_manager.text_formatted, row_count=data_manager.text_formatted)) @when(parsers.re("Number of rows containing '(?P<expected_text>.*)' of csv file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), @@ -287,7 +273,6 @@ def number_csv_rows_with_text_is_equal_to(expected_text: str, file_path: str, ro assert_that(int(num_rows)).is_equal_to(int(row_count)) -# ID 919 @given(parsers.re("Number of total rows of csv file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), converters=dict(row_count=data_manager.text_formatted)) @when(parsers.re("Number of total rows of csv file '(?P<file_path>.*)' is '(?P<row_count>.*)'"), @@ -316,7 +301,6 @@ def total_csv_rows_number_with_data_is_equal_to(file_path: str, row_count: str): assert_that(int(num_rows)).is_equal_to(int(row_count)) -# ID 921 @given(parsers.re("I Write '(?P<text>.+)' to '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)'"), converters=dict(cell=data_manager.text_formatted, text=data_manager.text_formatted)) @when(parsers.re("I Write '(?P<text>.+)' to '(?P<cell>.*)' cell of csv file '(?P<file_path>.*)'"), @@ -350,7 +334,6 @@ def write_text_to_csv_cell(text: str, cell: str, file_path: str): writer.writerow([cell.value for cell in row]) -# ID 922 @given(parsers.re("I create csv file '(?P<file_name>.*)' and save on '(?P<file_path>.+)'")) @when(parsers.re("I create csv file '(?P<file_name>.*)' and save on '(?P<file_path>.+)'")) def create_csv_file(file_name: str, file_path: str): diff --git a/main/frontend/common/step_definitions/mobile_device_actions.py b/main/frontend/common/step_definitions/mobile_device_actions.py index 833c6ee5..fe8c2576 100644 --- a/main/frontend/common/step_definitions/mobile_device_actions.py +++ b/main/frontend/common/step_definitions/mobile_device_actions.py @@ -12,7 +12,6 @@ # MOBILE Predefined Step -# ID 1202 @when("I reset the mobile app") @then("I reset the mobile app") def reset_app(selenium_generics: SeleniumGenerics): @@ -23,7 +22,6 @@ def reset_app(selenium_generics: SeleniumGenerics): # MOBILE Predefined Step -# 1203 @when(parsers.re("I put the mobile app in background for '(?P<seconds>.*)' seconds"), converters=dict(seconds=data_manager.text_formatted)) @then(parsers.re("I put the mobile app in background for '(?P<seconds>.*)' seconds"), diff --git a/main/frontend/common/step_definitions/text_assertion_editing.py b/main/frontend/common/step_definitions/text_assertion_editing.py index 666e47ee..1f85f5e7 100644 --- a/main/frontend/common/step_definitions/text_assertion_editing.py +++ b/main/frontend/common/step_definitions/text_assertion_editing.py @@ -324,7 +324,6 @@ def step_realistic_typing(selenium_generics: SeleniumGenerics, locators: Locator # WEB context Predefined Step -# ID 417 @given(parsers.re( "I add text '(?P<text>.*)' in input field whose attribute '(?P<attribute>.*)' is equal to '(?P<value>.*)'"), converters=dict(text=data_manager.text_formatted), ) @@ -342,7 +341,6 @@ def add_text_based_on_attribute(selenium_generics: SeleniumGenerics, locators, t # WEB & MOBILE contexts Predefined Step -# ID 418, 805 @given(parsers.re( r"I add random string of length (?:')(?P<length>.*)(?:') composed of (?:')(?P<character_type>alphabetic characters|numeric characters|alphabetic and numeric characters)(?:') to field (?:')(?P<locator_path>.*)(?:')(\s+)?((?:and save as)\s+(?:')(?P<storage_var>\w+)(?:') environment variable)?$")) @when(parsers.re( @@ -364,7 +362,6 @@ def set_random_element_value(selenium_generics: SeleniumGenerics, length: str, c # WEB & MOBILE contexts Predefined Step -# ID 419 @given( parsers.re(r"I add a random email to field '(?P<locator_path>.*)'((\s+)?with (?:')(?P<domain>.*)(?:') domain)?$"), converters=dict(domain=data_manager.text_formatted), ) diff --git a/main/plugin.py b/main/plugin.py index 1b3864b3..814930f6 100644 --- a/main/plugin.py +++ b/main/plugin.py @@ -10,7 +10,7 @@ from _pytest.fixtures import FixtureLookupError from py.xml import html -from collections import OrderedDict +from collections import OrderedDict, defaultdict from datetime import datetime from pathlib import Path from typing import List @@ -72,6 +72,7 @@ def pytest_configure(config: pytest_config.Config) -> None: """ config.option.keyword = "automated" config.option.markexpr = "not not_in_scope" + pytest.globalDict = defaultdict() is_driver = [arg for arg in config.invocation_params.args if "driver" in arg] if is_driver and not os.environ.get('BOILERPLATE_INSTALLATION'): config.pluginmanager.import_plugin("main.frontend.frontend_plugin") diff --git a/main/utils/cred.json b/main/utils/cred.json index 590a29e2..0a9d4929 100644 --- a/main/utils/cred.json +++ b/main/utils/cred.json @@ -1,12 +1,14 @@ { "installed": { - "client_id": "44392rcontent.com", + "client_id": "443927617801-42v66kpc5hup1umr1ea3s4a3h3s8itvu.apps.googleusercontent.com", "project_id": "modus-pytest", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", - "refresh_token": "1//0ewd1ANSvascVyJs2UBeQOY", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_secret": "MGS3sWe", - "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost", "http://localhost:8080", "http://127.0.0.1"] + "client_secret": "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", + "redirect_uris": [ + "http://localhost" + ], + "refresh_token": "1//03-ae1grOJ-2PCgYIARAAGAMSNwF-L9Irgoa_vZsrtTxD47PDd501_-4KySUmE6kHL7ZlAsmCGlbQFpUULBmwNcoCwG0uPoJTf7s" } } \ No newline at end of file diff --git a/main/utils/email_reader.py b/main/utils/email_reader.py index 023f50a4..b50d03c0 100644 --- a/main/utils/email_reader.py +++ b/main/utils/email_reader.py @@ -4,21 +4,20 @@ import pickle import os.path import json + SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'] PROJECT_DIR = os.getcwd() test_data_dir_utils = os.path.join(PROJECT_DIR, "main/utils") test_data_dir_email = os.path.join(PROJECT_DIR, "test_data/files") -# if 'utils' in PROJECT_DIRECTORY: -# PROJECT_DIR = PROJECT_DIRECTORY.replace("utils", "test_data") print(PROJECT_DIR) def get_email(): count = 0 creds = None - with open(test_data_dir_utils+'/token.pickle', 'rb') as token: + with open(test_data_dir_utils + '/token.pickle', 'rb') as token: creds = pickle.load(token) - with open(test_data_dir_utils+'/cred.json', 'r') as infile: + with open(test_data_dir_utils + '/cred.json', 'r') as infile: my_data = json.load(infile) if not creds.valid: @@ -31,13 +30,13 @@ def get_email(): if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: - flow = InstalledAppFlow.from_client_secrets_file(test_data_dir_utils+'/cred.json', SCOPES) - creds = flow.run_local_server(port=0) + flow = InstalledAppFlow.from_client_secrets_file(test_data_dir_utils + '/cred.json', SCOPES) + creds = flow.run_local_server(port=0, timeout_seconds=20) - with open(test_data_dir_utils+'/token.pickle', 'wb') as token: + with open(test_data_dir_utils + '/token.pickle', 'wb') as token: pickle.dump(creds, token) my_data['installed']['refresh_token'] = creds.refresh_token - with open(test_data_dir_utils+'/cred.json', 'w') as outfile: + with open(test_data_dir_utils + '/cred.json', 'w') as outfile: json.dump(my_data, outfile, indent=4) service = build('gmail', 'v1', credentials=creds) diff --git a/main/utils/token.pickle b/main/utils/token.pickle index 1bcbc657..89add9fe 100644 Binary files a/main/utils/token.pickle and b/main/utils/token.pickle differ