示例#1
0
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 test__data_id(self, test_var: fixture) -> None:
        """Check the output of a data id Selector.

        :param test_var: A string for testing.
        """
        selector: Selector = Selectors.data_id(test_var)

        assert selector == ('css selector', f'[data-id="{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)
示例#5
0
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()