-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stage to Master See merge request cometa/cometa!606
- Loading branch information
Showing
25 changed files
with
442 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import logging | ||
|
||
|
||
# setup logging | ||
logger = logging.getLogger("FeatureExecution") | ||
|
||
|
||
def is_step_conditional_statement(step): | ||
step_name :str = step.name | ||
conditional_steps = ("End If", "Else") | ||
return step_name.startswith(conditional_steps) | ||
|
||
def check_if_step_should_execute(context): | ||
step = context.CURRENT_STEP | ||
should_execute_step = True | ||
# Check if test flow is with in the condition | ||
if len(context.test_conditions_list) > 0: | ||
current_condition = context.test_conditions_list[-1] | ||
logger.debug(f"Current condition values : {current_condition}") | ||
# Check if current step is not conditional statement | ||
if not is_step_conditional_statement(step): | ||
logger.debug(f"Step {step.name} is with in the if condition") | ||
|
||
# When a condition is true and current step lies with in the If section then execute the current step | ||
if current_condition.is_condition_true() and not current_condition.is_else_section_active(): | ||
logger.debug(f"Step \"{step.name}\" will be executed with in the if section") | ||
should_execute_step = True | ||
# When a condition is false and current step lies with in the If section then skip the current step execution | ||
elif not current_condition.is_condition_true() and not current_condition.is_else_section_active(): | ||
logger.debug(f"Step \"{step.name}\" will be skipped with in the if section") | ||
should_execute_step = False | ||
|
||
# When condition is false and current step lies with in the else section then execute the current step | ||
elif not current_condition.is_condition_true() and current_condition.is_else_section_active(): | ||
logger.debug(f"Step \"{step.name}\" will be executed with in the else section") | ||
should_execute_step = True | ||
# When condition is true and current step lies with in the else condition then skip the current step execution | ||
elif current_condition.is_condition_true() and current_condition.is_else_section_active(): | ||
logger.debug(f"Step \"{step.name}\" will be skipped with in the else section") | ||
should_execute_step = False | ||
else: | ||
logger.debug("Executing step without any condition check") | ||
should_execute_step = True | ||
|
||
return should_execute_step | ||
|
||
class Condition: | ||
def __init__(self, index): | ||
self.index = index | ||
# if condition is True and not over if mean it is in the if section | ||
# if condition is False and not over it mean it is in the else section | ||
self._is_condition_true = True | ||
self._is_else_section_active = False | ||
self._is_condition_over = False | ||
self._sub_conditions: list[Condition] = [] | ||
|
||
def set_condition(self, condition_result): | ||
self._is_condition_true = condition_result | ||
|
||
def is_condition_true(self): | ||
return self._is_condition_true | ||
|
||
def close_condition(self): | ||
self._is_condition_over = True | ||
|
||
def is_flow_with_in_condition(self): | ||
return self._is_condition_over | ||
|
||
def activate_else_section(self): | ||
self._is_else_section_active = True | ||
|
||
def is_else_section_active(self): | ||
return self._is_else_section_active | ||
|
||
def __str__(self): | ||
return f"\n _is_condition_true : {self._is_condition_true}, \ | ||
\n is_else_section_active: {self._is_else_section_active}, \ | ||
\n is_condition_over: {self._is_condition_over}, \ | ||
\n count_of_sub_conditions: {len(self._sub_conditions)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from behave import * | ||
import time | ||
import sys | ||
import os | ||
import os.path | ||
import logging | ||
# import PIL | ||
# Import utilities | ||
sys.path.append(os.path.dirname(os.path.realpath(__file__))) | ||
from tools.common import * | ||
from tools.exceptions import * | ||
from tools.variables import * | ||
|
||
# pycrypto imports | ||
import base64 | ||
base64.encodestring = base64.encodebytes | ||
from hashlib import md5 | ||
from pathlib import Path | ||
from tools import expected_conditions as CEC | ||
import sys | ||
|
||
sys.path.append("/opt/code/behave_django") | ||
sys.path.append('/code/behave/cometa_itself/steps') | ||
|
||
from utility.functions import * | ||
from utility.configurations import ConfigurationManager | ||
from utility.common import * | ||
from utility.encryption import * | ||
from tools.common_functions import * | ||
|
||
SCREENSHOT_PREFIX = ConfigurationManager.get_configuration('COMETA_SCREENSHOT_PREFIX', '') | ||
ENCRYPTION_START = ConfigurationManager.get_configuration('COMETA_ENCRYPTION_START', '') | ||
|
||
# setup logging | ||
logger = logging.getLogger('FeatureExecution') | ||
|
||
|
||
@step(u'Validate if "{selector}" present in the browser in "{time}" seconds and save result in "{variable}"') | ||
@done(u'Validate if "{selector}" present in the browser in "{time}" seconds and save result in "{variable}"') | ||
def validate_element_presence(context, selector, time, variable): | ||
send_step_details(context, f"Validating if selector '{selector}' is present within {time} seconds") | ||
|
||
try: | ||
# Use waitSelector to get the element | ||
element = waitSelector(context, "css", selector, max_timeout=int(time)) | ||
if type(element) == list: | ||
element = element[0] | ||
|
||
result = element is not None # If element is returned, it's present | ||
send_step_details(context, f"Selector '{selector}' is present: {result}") | ||
except Exception as e: | ||
result = False # If an exception occurs, the element is not present | ||
logger.debug(f"Exception while checking presence of '{selector}': {e}") | ||
|
||
# Save the result to the variable | ||
addTestRuntimeVariable(context, variable, str(result)) | ||
send_step_details(context, f"Presence validation result for '{selector}' saved to variable '{variable}': {result}") | ||
|
||
|
||
@step(u'Validate if "{selector}" appeared in the browser in "{time}" seconds and save result in "{variable}"') | ||
@done(u'Validate if "{selector}" appeared in the browser in "{time}" seconds and save result in "{variable}"') | ||
def validate_element_visibility(context, selector, time, variable): | ||
send_step_details(context, f"Validating if selector '{selector}' appeared within {time} seconds") | ||
|
||
try: | ||
# Use waitSelector to get the element | ||
element = waitSelector(context, "css", selector, max_timeout=int(time)) | ||
if type(element) == list: | ||
element = element[0] | ||
result = element.is_displayed() # Check if the element is visible | ||
send_step_details(context, f"Selector '{selector}' appeared: {result}") | ||
except Exception as e: | ||
result = False # If an exception occurs, the element is not visible | ||
logger.debug(f"Exception while checking visibility of '{selector}': {e}") | ||
|
||
# Save the result to the variable | ||
addTestRuntimeVariable(context, variable, str(result)) | ||
send_step_details(context, f"Visibility validation result for '{selector}' saved to variable '{variable}': {result}") |
Oops, something went wrong.