{"id":19934981,"url":"https://github.com/harsh-valecha/testing_framework_selenium_pytest","last_synced_at":"2025-03-01T12:17:17.548Z","repository":{"id":247441476,"uuid":"825857400","full_name":"harsh-valecha/Testing_Framework_Selenium_Pytest","owner":"harsh-valecha","description":"This Framework is a boiler template that can be used for testing of webapps using selenium and pytest","archived":false,"fork":false,"pushed_at":"2024-08-29T14:28:09.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T02:09:42.210Z","etag":null,"topics":["pytest","pytest-html","python","selenium"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harsh-valecha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-08T16:28:22.000Z","updated_at":"2024-08-29T14:28:12.000Z","dependencies_parsed_at":"2024-08-07T09:30:42.552Z","dependency_job_id":null,"html_url":"https://github.com/harsh-valecha/Testing_Framework_Selenium_Pytest","commit_stats":null,"previous_names":["harsh-valecha/testing_framework_selenium_pytest"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harsh-valecha%2FTesting_Framework_Selenium_Pytest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harsh-valecha%2FTesting_Framework_Selenium_Pytest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harsh-valecha%2FTesting_Framework_Selenium_Pytest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harsh-valecha%2FTesting_Framework_Selenium_Pytest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harsh-valecha","download_url":"https://codeload.github.com/harsh-valecha/Testing_Framework_Selenium_Pytest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241361444,"owners_count":19950381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytest","pytest-html","python","selenium"],"created_at":"2024-11-12T23:18:21.171Z","updated_at":"2025-03-01T12:17:17.527Z","avatar_url":"https://github.com/harsh-valecha.png","language":"Python","readme":"## Automation Framework for testing using selenium and pytest \n\n### Project Structure\n```\n.\n├── tests/\n│   ├── __init__.py\n│   ├── test_login.py\n│   ├── conftest.py\n├── pages/\n│   ├── __init__.py\n│   ├── login_page.py\n├── utils/\n│   ├── __init__.py\n│   ├── config.py\n│   ├── driver_factory.py\n├── reports/\n│   ├── report.html\n├── screenshots/\n├── requirements.txt\n├── pytest.ini\n```\n\n### requirements.txt\nThis file lists all the dependencies required for the project. \n\n```plaintext\nselenium\npytest\npytest-html\n```\n\n- **selenium**: Used for browser automation.\n- **pytest**: The testing framework.\n- **pytest-html**: A plugin for pytest that generates HTML reports.\n\n### pytest.ini\nThis configuration file is used to customize pytest behavior.\n\n```ini\n[pytest]\naddopts = --html=reports/report.html --self-contained-html\n```\n\n- `addopts`: Command line options to be added by default. Here, it generates an HTML report at `reports/report.html`.\n\n### conftest.py\nThis file contains fixtures that are shared across multiple test files.\n\n```python\nimport pytest\nfrom selenium import webdriver\nfrom utils.driver_factory import get_driver\n\n@pytest.fixture(scope='session')\ndef driver():\n    driver = get_driver()\n    yield driver\n    driver.quit()\n```\n\n- **driver()**: A fixture that sets up the Selenium WebDriver and tears it down after the test session is completed. The scope is set to 'session' to reuse the browser instance across all tests.\n\n### utils/config.py\nThis file contains configuration settings used throughout the framework.\n\n```python\nclass Config:\n    BASE_URL = 'http://example.com'\n    BROWSER = 'chrome'\n```\n\n- **Config**: A class holding configuration values such as the base URL of the application and the browser to be used.\n\n### utils/driver_factory.py\nThis file handles the creation of browser drivers.\n\n```python\nfrom selenium import webdriver\nfrom utils.config import Config\n\ndef get_driver():\n    if Config.BROWSER == 'chrome':\n        return webdriver.Chrome()\n    elif Config.BROWSER == 'firefox':\n        return webdriver.Firefox()\n    else:\n        raise Exception(f\"Browser {Config.BROWSER} is not supported.\")\n```\n\n- **get_driver()**: A function that returns a WebDriver instance based on the browser specified in the Config class.\n\n### pages/login_page.py\nThis file follows the Page Object Model (POM) pattern and encapsulates the login page functionality.\n\n```python\nfrom selenium.webdriver.common.by import By\n\nclass LoginPage:\n    def __init__(self, driver):\n        self.driver = driver\n        self.username_input = (By.ID, 'username')\n        self.password_input = (By.ID, 'password')\n        self.login_button = (By.ID, 'login')\n\n    def enter_username(self, username):\n        self.driver.find_element(*self.username_input).send_keys(username)\n\n    def enter_password(self, password):\n        self.driver.find_element(*self.password_input).send_keys(password)\n\n    def click_login(self):\n        self.driver.find_element(*self.login_button).click()\n```\n\n- **LoginPage**: A class representing the login page.\n    - **__init__(self, driver)**: Initializes the page with the WebDriver instance.\n    - **enter_username(self, username)**: Enters the username in the username field.\n    - **enter_password(self, password)**: Enters the password in the password field.\n    - **click_login(self)**: Clicks the login button.\n\n### tests/test_login.py\nThis file contains test cases for the login functionality.\n\n```python\nimport pytest\nfrom utils.config import Config\nfrom pages.login_page import LoginPage\n\ndef test_login(driver):\n    driver.get(Config.BASE_URL)\n    \n    login_page = LoginPage(driver)\n    login_page.enter_username('testuser')\n    login_page.enter_password('password')\n    login_page.click_login()\n\n    assert \"Dashboard\" in driver.title\n```\n\n- **test_login(driver)**: A test function that performs the login test.\n    - **driver.get(Config.BASE_URL)**: Navigates to the base URL of the application.\n    - **LoginPage(driver)**: Initializes the login page object.\n    - **enter_username('testuser')**: Enters the username.\n    - **enter_password('password')**: Enters the password.\n    - **click_login()**: Clicks the login button.\n    - **assert \"Dashboard\" in driver.title**: Asserts that the title of the page contains \"Dashboard\" to verify a successful login.\n\n### `__init__.py`\nEmpty `__init__.py` files are used to mark directories as Python packages. These can be empty or contain initialization code for the package.\n\n### reports/report.html\nThis is the output HTML report generated by pytest-html. It contains the results of the test execution in an easy-to-read format.\n\n### Running the Tests\nTo run the tests and generate an HTML report, use the following command:\n```bash\npytest\n```\n\nThis command will execute all the tests in the `tests` directory and generate an HTML report at `reports/report.html`.\n\nBy following this structure, you have a modular, maintainable, and scalable test automation framework. You can extend it by adding more page objects, utilities, and test cases as needed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharsh-valecha%2Ftesting_framework_selenium_pytest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharsh-valecha%2Ftesting_framework_selenium_pytest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharsh-valecha%2Ftesting_framework_selenium_pytest/lists"}