# T_page_object 📦

> **A Python package for taking an object oriented approach
            when interacting with web pages and their elements .**

## 📑 Table of Contents
- [Overview](#overview)
- [Installation](#installation)
- [Usage Example](#usage-example)
- [API Documentation](#api-documentation)
- [License](#license)

## Overview
This package provides various modules and classes for creating portals, web pages and web elements.
            
There are also usable web elements that have commonly used methods built in.

## Installation
```bash
pip install t-page-object
```

## Usage Example
For detailed examples, please refer to our
            [quick start page](https://www.notion.so/thoughtfulautomation/T-Page-Object-126f43a78fa480e39a1af8f99f93affe).

### 
## API Documentation

---

## Base_app
### Module: `t_page_object.base_app`

_Module for BaseApp class._

- **Class:** `BaseApp`
  > Base class for application or portal objects and their configuration.
  - **Method:** `open_browser`
    > Open browser and set Selenium options.

---

## Base_element
### Module: `t_page_object.base_element`

_Contains the BaseElement class._

- **Class:** `BaseElement`
  > This is an Element used to build each Page.
  - **Method:** `format_xpath`
  - **Method:** `wait_element_load`

---

## Base_page
### Module: `t_page_object.base_page`

_Contains the BasePage class which is the parent class for all page objects in the project._

- **Class:** `BasePage`
  > Base page class for all page objects in the project.
  - **Method:** `get_element_from_shadow_roots`
    > Get element from nested shadow roots.

        Args:
            roots: The css locators of the shadow root elements, in hierarchal order.
            element_css: The css locator of the element to find.

        Returns:
            The WebElement of the element found.
        
  - **Method:** `visit`
    > Navigate to the base page URL.
  - **Method:** `wait_for_new_window_and_switch`
    > Function for waiting and switching to new window.

        Args:
            old_window_handles: The list of window handles before the new window is opened.

        Returns:
            The new window handle.
        
  - **Method:** `wait_page_load`
    > Wait for the page to load by waiting for the verification element to load.

        timeout: The maximum time to wait for the element to be present, in seconds.
        

---

## Bot_config
### Module: `t_page_object.bot_config`

_Congifuration module for the t_page_object package._

- **Class:** `BotConfig`
  > Class for configuration.

---

## Elements
### Module: `t_page_object.elements`

_Module for all base ui components._

### Module: `t_page_object.elements.button_element`

_Button element module._

- **Class:** `ButtonElement`
  > Standard button element.
  - **Method:** `click`
  - **Method:** `click_button`
  - **Method:** `click_button_if_visible`
  - **Method:** `click_button_when_visible`
  - **Method:** `click_element`
  - **Method:** `click_element_if_visible`
  - **Method:** `click_element_when_clickable`
  - **Method:** `click_element_when_visible`
### Module: `t_page_object.elements.checkox_element`

_Checkbox element module._

- **Class:** `CheckboxElement`
  > Checkbox element.
  - **Method:** `select`
### Module: `t_page_object.elements.container_element`

_Class for container elements._

- **Class:** `ContainerElement`
  > Container element. Used to hold multiple text elements.
  - **Method:** `get_text_values`
    > 
        Get text for each element with id matching class attribute.

        Args:
            cls (Type[TO]): The class to use for the object.

        Returns:
            Instance of input class with text values.
        
### Module: `t_page_object.elements.dropdown_element`

_Dropdown element module._

- **Class:** `DropdownElement`
  > Standard dropdown element.
  - **Method:** `click_and_select_option`
  - **Method:** `type_and_enter`
### Module: `t_page_object.elements.iframe_element`

_Frame element module._

- **Class:** `IFrameElement`
  > Class for frame element model.
  - **Method:** `select_iframe`
  - **Method:** `select_nested_iframe`
  - **Method:** `unselect_iframe`
### Module: `t_page_object.elements.image_element`

_Image element module._

- **Class:** `ImageElement`
  > Image element.
  - **Method:** `download_image`
### Module: `t_page_object.elements.input_element`

_Input element module._

- **Class:** `InputElement`
  > Input element.
  - **Method:** `click_and_input_text`
  - **Method:** `get_input_value`
  - **Method:** `input_text_and_check`
### Module: `t_page_object.elements.table_element`

_Table element module._

- **Class:** `TableElement`
  > Table element.
### Module: `t_page_object.elements.text_element`

_This module contains the TextElement class for the text element model._

- **Class:** `TextElement`
  > Input element.
  - **Method:** `get_clean_text`

---

## Selenium_manager
### Module: `t_page_object.selenium_manager`

_Create a singleton manager to ensure a single instance of Selenium._

- **Class:** `SeleniumManager`
  > Singleton manager to ensure a single instance of Selenium.

---

## T_requests
### Module: `t_page_object.t_requests`

_A wrapper module for making HTTP requests using httpx._

- **Class:** `Requests`
  > A wrapper class for making HTTP requests using httpx.

    This class provides methods to make HTTP GET, POST, PUT, and DELETE requests
    with support for setting headers, cookies, and user agent. It also includes
    error handling.

    Attributes:
        default_headers (dict): The default headers to include in the requests.
        cookies (dict): The cookies to include in the requests.
    
  - **Method:** `delete`
    > Sends a DELETE request to the specified URL with optional headers and cookies.

        Args:
            url: A string representing the request URL.
            headers: A dictionary containing the request headers. Defaults to an empty dictionary.
            cookies: A dictionary containing the request cookies. Defaults to an empty dictionary.

        Returns:
            The response content if the request is successful
        
  - **Method:** `get`
    > Sends a GET request to the specified URL with optional headers, cookies, and parameters.

        Args:
            url: A string representing the request URL.
            headers: A dictionary containing the request headers. Defaults to an empty dictionary.
            cookies: A dictionary containing the request cookies. Defaults to an empty dictionary.
            params: A dictionary containing the request parameters. Defaults to an empty dictionary.

        Returns:
            The response content if the request is successful.
        
  - **Method:** `get_response_data`
    > Get the response data.

        Args:
            url: A string representing the request URL.
            data: The data to send in the request body. Defaults to None.
            json: The JSON data to send in the request body. Defaults to None.
            headers: A dictionary containing the request headers. Defaults to an empty dictionary.
            cookies: A dictionary containing the request cookies. Defaults to an empty dictionary.
            params: A dictionary containing the request parameters. Defaults to an empty dictionary.
            method: A string representing the request method. Defaults to "GET".

        Returns:
            The response object.
        
  - **Method:** `post`
    > Sends a POST request to the specified URL with optional data, JSON, headers, and cookies.

        Args:
            url: A string representing the request URL.
            data: The data to send in the request body. Defaults to None.
            json: The JSON data to send in the request body. Defaults to None.
            headers: A dictionary containing the request headers. Defaults to an empty dictionary.
            cookies: A dictionary containing the request cookies. Defaults to an empty dictionary.

        Returns:
            The response content if the request is successful.
        
  - **Method:** `put`
    > Sends a PUT request to the specified URL with optional data, JSON, headers, and cookies.

        Args:
            url: A string representing the request URL.
            data: The data to send in the request body. Defaults to None.
            json: The JSON data to send in the request body. Defaults to None.
            headers: A dictionary containing the request headers. Defaults to an empty dictionary.
            cookies: A dictionary containing the request cookies. Defaults to an empty dictionary.

        Returns:
            The response content if the request is successful
        
  - **Method:** `remove_headers`
    > Removes the default headers.

        Args:
            key: The key to remove from the headers.
        
  - **Method:** `set_cookies`
    > Updates the cookies with the provided cookies.

        Args:
            cookies: A dictionary containing the cookies to update.
        
  - **Method:** `set_cookies_to_session`
    > Updates the cookies with the provided cookies.

        Args:
            cookies: A dictionary containing the cookies to update.
        
  - **Method:** `set_headers`
    > Updates the default headers with the provided headers.

        Args:
            headers: A dictionary containing the headers to update.
        
  - **Method:** `set_user_agent`
    > Sets the User-Agent header to the provided user agent string.

        Args:
            user_agent: A string representing the user agent to set.
        

---

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
