class Vehicles(Resources): """Objects and methods for the Vehicles page. The vehicles page may be accessed by selecting the 'Vehicles' tab from the side navigation panel on the 'Resources' page. """ URL_PATH: str = f'{Resources.URL_PATH}/vehicles' ROOT_LOCATOR: Selector = Selectors.data_id('content-container') _fab_button: Selector = Selectors.data_id('new-button') @property def deletion_modal(self) -> DeletionModal: return DeletionModal(self) @property def fab_button(self) -> WebElement: return self.driver.find_element(*self._fab_button) @property def vehicle_form(self) -> VehicleForm: return VehicleForm(self) @property def vehicles_list(self) -> VehiclesList: return VehiclesList(self) def add_new_vehicle(self, vehicle: dict) -> None: """Add a new vehicle using the Vehicle Form component. :param vehicle: The vehicle yielded from a vehicle fixture. """ self.fab_button.click() self.vehicle_form.wait_for_component_to_be_present() self.vehicle_form.fill_form(vehicle) self.vehicle_form.save_button.click() self.driver.wait_until_not_present(*VehicleForm.ROOT_LOCATOR, wait_time=4) def delete_vehicle(self) -> object: """Delete an existing vehicle.""" self.vehicle_form.wait_for_component_to_be_visible() self.vehicle_form.delete_vehicle_button.click() return self.deletion_modal.wait_for_component_to_be_visible() def toggle_vehicle_operation(self) -> None: """Toggle an existing vehicle's operational slider.""" self.vehicle_form.operational_toggle.click() self.vehicle_form.operational_toggle.is_selected()
def is_text_not_visible(self, text: str) -> bool: """Boolean check for if a node with specific text does not exist and is not visible. :usage example: driver.is_text_not_visible('Forgot password?') :param text: The specific text within a node. """ try: (self.find_element(*Selectors.text(text)) and self.find_element(*Selectors.text(text)).is_displayed()) return False except NoSuchElementException: return True except ValueError: return True
def test__partial_link_text(self, test_var: fixture) -> None: """Check the output of a partial link text Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.partial_link_text(test_var) assert selector == ('partial link text', f'{test_var}')
def test__partial_href(self, test_var: fixture) -> None: """Check the output of a partial href Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.partial_href(test_var) assert selector == ('xpath', f'//a[contains(@href, "{test_var}")]')
def test__css_selector(self, test_var: fixture) -> None: """Check the output of a css selector Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.css_selector(test_var) assert selector == ('css selector', test_var)
def test__tag(self, test_var: fixture) -> None: """Check the output of a tag Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.tag(test_var) assert selector == ('css selector', f'{test_var}')
def test__placeholder(self, test_var: fixture) -> None: """Check the output of a placeholder Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.placeholder(test_var) assert selector == ('css selector', f'[placeholder="{test_var}"]')
def test__data_test_id(self, test_var: fixture) -> None: """Check the output of a data test id Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.data_test_id(test_var) assert selector == ('css selector', f'[data-test-id="{test_var}"]')
def test__class_name(self, test_var: fixture) -> None: """Check the output of a class name Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.class_name(test_var) assert selector == ('css selector', f'.{test_var}')
def test__value(self, test_var: fixture) -> None: """Check the output of a value Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.value(test_var) assert selector == ('css selector', f'[value="{test_var}"]')
def test__option_text(self, test_var: fixture) -> None: """Check the output of an option text Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.option_text(test_var) assert selector == ('xpath', f'//option[contains(text(), {test_var})]')
def test__option_value(self, test_var: fixture) -> None: """Check the output of an option value Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.option_value(test_var) assert selector == ('xpath', f'//option[value="{test_var}"]')
def test__href(self, test_var: fixture) -> None: """Check the output of a href Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.href(test_var) assert selector == ('css selector', f'[href="{test_var}"]')
def test__element_type(self, test_var: fixture) -> None: """Check the output of a element type Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.element_type(test_var) assert selector == ('css selector', f'[type="{test_var}"]')
def test__xpath(self, test_var: fixture) -> None: """Check the output of a xpath Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.xpath(test_var) assert selector == ('xpath', f'{test_var}')
def test__text(self, test_var: fixture) -> None: """Check the output of a text Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.text(test_var) assert selector == ('xpath', f'//*[contains(text(), "{test_var}")]')
def test__radio(self, test_var: fixture) -> None: """Check the output of a radio Selector. :param test_var: A string for testing. """ selector: Selector = Selectors.radio(test_var) assert selector == ('css selector', f'[type="radio"][value="{test_var}"]')
def test_type(self, test_var: fixture) -> None: """Check for whether the date type returned is a tuple. Type checking is removed on 'selector' to ensure that there is no confusion with what is being checked by this test. """ selector = Selectors.data_id(test_var) assert type(selector) is tuple
class DeletionModal(Component): """Objects and methods for the Deletion Modal component.""" ROOT_LOCATOR: Selector = Selectors.data_id('deletion-modal-container') _cancel_button: Selector = Selectors.data_id( 'deletion-modal-cancel-button') _confirm_button: Selector = Selectors.data_id( 'deletion-modal-confirm-button') _message: Selector = Selectors.data_id('deletion-modal-message') @property def cancel_button(self) -> WebElement: return self.container.find_element(*self._cancel_button) @property def confirm_button(self) -> WebElement: return self.container.find_element(*self._confirm_button) @property def message(self) -> WebElement: return self.container.find_element(*self._message)
def fill(self, value: str, input_text: Union[str, int]) -> None: """Fill out an input element with a value. :usage example: driver.fill('username', 'demodavid') :param value: The unique locator value for the element. :param input_text: The input text for the element. """ input_field: Union[WebElement, Element] = self.find_element(*Selectors.name(value)) self.execute_script("arguments[0].value = ''", input_field) input_field.send_keys(input_text)
def wait_until_text_visible(self, text: str, wait_time: int = None) -> Union[Element, None]: """Wait until a text string is visible, then return the element for further actions. :usage example: driver.wait_until_text_visible('Joe Schmo') :param text: The specific text string. :param wait_time: The amount of time until a TimeoutException occurs. """ _wait: int = wait_time if wait_time is not None else (self.wait_time // 2) try: return WebDriverWait(self, _wait).until( Conditions.VisibilityOfElementLocated( (Selectors.text(text)[0], Selectors.text(text)[1]), _wait, ), ) except WebDriverException: return None
def wait_until_text_not_visible(self, text: str, wait_time: int = None) -> bool: """Wait until a text string is not visible, then return a boolean value. :usage example: driver.find_element(*Selectors.data_id( 'ride-card-container')).wait_until_text_not_visible('Joe Schmo') :param text: The specific text string. :param wait_time: The amount of time until a TimeoutException occurs. """ _wait: int = wait_time if wait_time is not None else (self.wait_time // 2) try: return WebDriverWait(self, _wait).until_not( Conditions.VisibilityOfElementLocated( (Selectors.text(text)[0], Selectors.text(text)[1]), _wait, ), ) except WebDriverException: return False
def is_text_present(self, text: str) -> bool: """Boolean check for if a node with specific text exists. :usage example: driver.is_text_present('Forgot password?') :param text: The specific text within a node. """ try: self.find_element(*Selectors.text(text)) return True except NoSuchElementException: return False except ValueError: return False
def choose(self, value, value_attr) -> None: """Select a radio button based on parent input name and the radio button value attribute. :usage example: driver.choose('days-of-the-week', 'sunday') :param value: The unique locator value for the element. :param value_attr: The contents of the value attribute for an input field. """ input_fields: Union[List, ElementTuple] = self.find_elements( *Selectors.name(value)) input_list: list = [ field for field in input_fields if field.value == value_attr ] if not input_list: raise NoSuchElementException input_list[0].click()
def fill_picker_input(self, value: str, input_text: Union[str, int]) -> None: """Fill the value for a Material UI Pickers Keyboard Date or Time Picker. A value of int 1 is passed prior to filling as we use a Moment parser alongside the Material UI Pickers library. Since Moment cannot parse strings, we pass an int and then clear out the input field. This allows for normal text entry with a string. :usage example: driver.fill_picker_input('date', '05-22-2020') :param value: The unique locator value for the element. :param input_text: The input text for the element. """ input_field: Union[WebElement, Element] = self.find_element(*Selectors.name(value)) self.execute_script("arguments[0].value = ' '", input_field) input_field.send_keys(1) self.execute_script("arguments[0].value = ' '", input_field) input_field.send_keys(input_text)
class VehicleForm(Component): """Objects and methods for the Deletion Modal component.""" ROOT_LOCATOR: Selector = Selectors.data_id('vehicle-container') _call_name_field: Selector = Selectors.data_id('vehicle-call-name') _cancel_button: Selector = Selectors.data_id('cancel-button') _capacity_field: Selector = Selectors.data_id('ambulatory-capacity') _color_picker: Selector = Selectors.data_id('color') _delete_vehicle_button: Selector = Selectors.data_id('delete-vehicle-button') _operational_toggle: Selector = Selectors.name('enabled') _save_button: Selector = Selectors.data_id('save-vehicle-button') _wheelchair_capacity: Selector = Selectors.data_id('accessible-capacity') _wheelchair_impact: Selector = Selectors.data_id('capacity-impact') @property def assigned_services_list(self) -> AssignedServicesList: return AssignedServicesList(self) @property def call_name_field(self) -> WebElement: return self.container.find_element(*self._call_name_field) @property def cancel_button(self) -> WebElement: return self.container.find_element(*self._cancel_button) @property def capacity_field(self) -> WebElement: return self.container.find_element(*self._capacity_field) @property def color_picker(self) -> WebElement: return self.container.find_element(*self._color_picker) @property def delete_vehicle_button(self) -> WebElement: return self.container.find_element(*self._delete_vehicle_button) @property def operational_toggle(self) -> WebElement: return self.container.find_element(*self._operational_toggle) @property def save_button(self) -> WebElement: return self.container.find_element(*self._save_button) @property def wheelchair_capacity_field(self) -> WebElement: return self.container.find_element(*self._wheelchair_capacity) @property def wheelchair_impact_field(self) -> WebElement: return self.container.find_element(*self._wheelchair_impact) def fill_form(self, vehicle: dict) -> None: """Fill out a vehicle form, then submit the form. :param vehicle: The vehicle yielded from a vehicle fixture. """ self.call_name_field.fill(vehicle['call_name']) self.capacity_field.fill(vehicle['capacity']) self.wheelchair_capacity_field.fill(vehicle['wheelchair_capacity']) if vehicle['wheelchair_capacity'] >= 1: self.wheelchair_impact_field.fill(vehicle['wheelchair_impact']) self.operational_toggle.click()
def test_selectors_require_input(self) -> None: """Check that selectors require an input.""" with pytest.raises(TypeError): assert Selectors.name() # type: ignore