Skip to content

Commit

Permalink
ChinmayCorrections
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaymudholkar1 committed Jun 27, 2024
1 parent 9e896a1 commit b7ae7d2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ __pycache__/
screenshots/
.env
venv/
.venv/
allure-results/
allure-report/
.js
Expand Down
38 changes: 23 additions & 15 deletions helpers/datetimeHelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta


class BaseDatetimeHelper:
@staticmethod
def current_datetime():
Expand All @@ -24,27 +25,29 @@ def subtract_days(dt, days):
@staticmethod
def format_date(date, browser):
try:
parsed_date = datetime.strptime(date, '%d/%m/%Y')
parsed_date = datetime.strptime(date, "%d/%m/%Y")
if browser == "safari" or browser == "mobile":
return parsed_date.strftime('%m/%d/%Y')
return parsed_date.strftime("%m/%d/%Y")
else:
return parsed_date.strftime('%d/%m/%Y')
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
try:
parsed_date = datetime.strptime(date, '%Y-%m-%d')
parsed_date = datetime.strptime(date, "%Y-%m-%d")
if browser == "safari" or browser == "mobile":
return parsed_date.strftime('%m/%d/%Y')
return parsed_date.strftime("%m/%d/%Y")
else:
return parsed_date.strftime('%d/%m/%Y')
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
try:
parsed_date = datetime.strptime(date, '%Y.%m.%d')
parsed_date = datetime.strptime(date, "%Y.%m.%d")
if browser == "safari" or browser == "mobile":
return parsed_date.strftime('%m/%d/%Y')
return parsed_date.strftime("%m/%d/%Y")
else:
return parsed_date.strftime('%d/%m/%Y')
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
raise ValueError("Invalid date format. Date should be in the format dd/mm/yyyy, yyyy-mm-dd, or yyyy.%m.%d.")
raise ValueError(
"Invalid date format. Date should be in the format dd/mm/yyyy, yyyy-mm-dd, or yyyy.%m.%d."
)

@staticmethod
def get_date_value(date):
Expand All @@ -53,8 +56,10 @@ def get_date_value(date):
parts = date.split("-")
elif "+" in date.lower():
parts = date.split("+")
else:
parts = date.lower()

if len(parts) > 1:
if len(parts) != 5:
offset = int(parts[1].strip())
else:
offset = 0
Expand All @@ -63,25 +68,28 @@ def get_date_value(date):
return (datetime.today() - timedelta(days=offset)).date()
elif "+" in date.lower():
return (datetime.today() + timedelta(days=offset)).date()
else:
return datetime.today().date()
else:
return datetime.strptime(date, "%Y-%m-%d").date()

@staticmethod
def standardize_date_format(date_str):
try:
# Try parsing the date as '%d/%m/%Y'
parsed_date = datetime.strptime(date_str, '%d/%m/%Y')
return parsed_date.strftime('%d/%m/%Y')
parsed_date = datetime.strptime(date_str, "%d/%m/%Y")
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
try:
# If parsing fails, try parsing as '%m/%d/%Y'
parsed_date = datetime.strptime(date_str, '%m/%d/%Y')
parsed_date = datetime.strptime(date_str, "%m/%d/%Y")
# Format the parsed date to '%d/%m/%Y'
return parsed_date.strftime('%d/%m/%Y')
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
# If parsing as both formats fails, return the original string
return date_str


class DatetimeHelper(BaseDatetimeHelper):
def __init__(self):
super().__init__()
21 changes: 14 additions & 7 deletions pages/site_vaccine_batches_confirm_page.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
from init_helpers import *

CONFIRM_BUTTON = ("//button[text()='Confirm']")
ERROR_BATCH_ALREADY_EXISTS = ("//p[text()='Error! One or more vaccine batches aleady exist at a site.']")
CONFIRM_BUTTON = "//button[text()='Confirm']"
ERROR_BATCH_ALREADY_EXISTS = "//p[text()='Error! One or more vaccine batches already exist at a site.']"


def check_site_name_is_displayed(sitename):
element = (f"//div[text()='{sitename}']")
element = f"//div[text()='{sitename}']"
return check_element_exists(element, True)


def check_vaccine_is_displayed(vaccine):
element = (f"//b[text()='{vaccine}']")
element = f"//b[text()='{vaccine}']"
return check_element_exists(element, True)


def check_vaccinetype_is_displayed(vaccineType):
element = (f"//div[text()='{vaccineType}']")
element = f"//div[text()='{vaccineType}']"
return check_element_exists(element, True)


def check_batchNumber_is_displayed(batchnumber):
element = (f"//div[text()='{batchnumber}']")
element = f"//div[text()='{batchnumber}']"
return check_element_exists(element, True)


def check_date_is_displayed(date):
element = (f"//div[text()='{date}']")
element = f"//div[text()='{date}']"
return check_element_exists(element, True)


def check_batch_already_exists_error_is_displayed():
return check_element_exists(ERROR_BATCH_ALREADY_EXISTS, False)


def click_confirm_button():
find_element_and_perform_action(CONFIRM_BUTTON, "click")
41 changes: 28 additions & 13 deletions tests/test_add_vaccine_batches_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,52 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@pytest.fixture(scope='function')

@pytest.fixture(scope="function")
def shared_data():
return {}

@scenario(f'{features_directory}/add_batches.feature', 'Add vaccine batches page should launch')

@scenario(f"{features_directory}/add_batches.feature", "Add vaccine batches page should launch")
def test_add_vaccine_batches_page_should_launch(site, care_model, navigate_and_login):
pass

@scenario(f'{features_directory}/add_batches.feature', 'Add batch to vaccine')

@scenario(f"{features_directory}/add_batches.feature", "Add batch to vaccine")
def test_batch_already_added_to_site_warning_should_appear():
pass


@given("I am logged into the RAVS app")
def logged_into_ravs_app(site, care_model):
set_vaccinator_location(site, care_model)


@given("I am on the RAVS home page")
def logged_into_homepage(login_and_navigate_to_homepage):
pass


@when("I am on the vaccine settings page")
def i_am_on_settings_page():
if config["browser"] == "mobile":
if check_navlink_bar_toggle_exists():
if check_navlink_bar_toggle_exists():
click_navlinkbar_toggler()
click_settings_nav_link()
Click_vaccines_settings()


@when("I click add batches button")
def i_click_add_batches():
Click_add_batches_button()

@then('the add vaccine batches page should be launched')

@then("the add vaccine batches page should be launched")
def the_add_vaccine_batches_page_should_launch():
attach_screenshot("add_vaccine_batches_page_should_launch")
assert check_add_batch_button_exists() == True


@when(parse("I select {site}, {vaccine}, {vaccinetype} and enter {batchprefix}, {batchsuffix}"))
def i_select_site_vaccine_and_vaccinetype_for_batch(site, vaccine, vaccinetype, batchprefix, batchsuffix, shared_data):
click_site_radio_button(site)
Expand All @@ -62,47 +71,53 @@ def i_select_site_vaccine_and_vaccinetype_for_batch(site, vaccine, vaccinetype,
elif "flu" in vaccine.lower():
click_flu_vaccine_radiobutton()
click_flu_vaccine_type_radiobutton_on_add_batches_page(vaccinetype)
shared_data['site'] = site
shared_data['vaccine'] = vaccine
shared_data['vaccinetype'] = vaccinetype
if "covid" in shared_data['vaccine'].lower():
shared_data["site"] = site
shared_data["vaccine"] = vaccine
shared_data["vaccinetype"] = vaccinetype
if "covid" in shared_data["vaccine"].lower():
enter_covid_batch_number_prefix(batchprefix)
enter_covid_batch_number_suffix(batchsuffix)
elif "flu" in shared_data['vaccine'].lower():
elif "flu" in shared_data["vaccine"].lower():
enter_flu_batch_number(batchprefix)
attach_screenshot("entered_batch_number")


@when(parse("I enter {batchprefix}, {batchsuffix}"))
def i_enter_batchprefix_and_batchsuffix(batchprefix, batchsuffix, shared_data):
if "covid" in shared_data['vaccine'].lower():
if "covid" in shared_data["vaccine"].lower():
enter_covid_batch_number_prefix(batchprefix)
enter_covid_batch_number_suffix(batchsuffix)
elif "flu" in shared_data['vaccine'].lower():
elif "flu" in shared_data["vaccine"].lower():
enter_flu_batch_number(batchprefix)
attach_screenshot("entered_batch_number")


@when(parse("I enter {expirydate}"))
def i_enter_expiryDate(expirydate, shared_data):
expirydate = format_date(str(get_date_value(expirydate)), config["browser"])
enter_expiry_date(expirydate)
shared_data['expiryDate'] = expirydate
shared_data["expiryDate"] = expirydate
attach_screenshot("entered_expiry_date")


@when("I click Add batch button")
def i_click_add_batch_button():
Click_add_batch_button()
attach_screenshot("clicked_add_batch_button")


@when("I click confirm choices button")
def i_click_confirm_choices_button():
click_confirm_vaccine_batch_choices_button()
attach_screenshot("clicked_confirm_choices_button")


@when("I click confirm button")
def i_click_confirm_button():
click_confirm_button()
attach_screenshot("clicked_confirm_choices_button")


@then("the batch is already added to site warning should appear")
def batch_already_added_warning_should_exist(shared_data):
attach_screenshot("batch_already_added_warning_message_exists")
Expand Down

0 comments on commit b7ae7d2

Please sign in to comment.