test/unit_tests/framework/web/mock_web_action.py
croy 82d417b9e6 New StarlingX Automation Framework
Fresh start for the StarlingX automation framework.

Change-Id: Ie265e0791024f45f71faad6315c2b91b022934d1
2024-11-29 16:01:57 -05:00

45 lines
1.3 KiB
Python

from typing import List
from framework.web.action.web_action import WebAction
from framework.web.condition.web_condition import WebCondition
class MockWebAction(WebAction):
"""
Class Mocking a Web Action
"""
def __init__(self, number_of_expected_fails: int = 0, web_conditions: List[WebCondition] = []):
"""
Constructor which will instantiate the driver object.
Args:
number_of_expected_fails: Number of times to throw and exception when perform_action is called.
"""
super().__init__(None, None, web_conditions=web_conditions)
self.number_of_expected_fails = number_of_expected_fails
self.timeout = 0.01 # For unit tests, 10ms is a long time in the loop.
def perform_action(self, web_element, *args):
"""
Override the parent's perform action with a mock action
Args:
web_element: Element.
*args: Unused arguments to follow the override signature.
Returns: Success as a string
"""
if self.number_of_expected_fails > 0:
self.number_of_expected_fails -= 1
raise Exception("Failed to Perform Mock Action")
return "Success"
def __str__(self):
"""
String representation of this action.
Returns:
"""
return "Mock Action"