Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test starlette client #1326

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anisjellazi
Copy link

Pull Request Title:

Add StarletteClient to Splinter's list of supported drivers for FastAPI applications and update the imports


Description:

This pull request introduces the StarletteClient driver to the Splinter library, enabling users to perform browser-like tests on FastAPI applications using the TestClient from Starlette.


Key Changes:

1. Introduction of the StarletteClient Driver:

  • What: Added a new driver, StarletteClient, to Splinter. This driver utilizes Starlette's TestClient to simulate browser requests in FastAPI applications.
  • Why: This allows users to test FastAPI routes and perform assertions on the response, making it easier for developers working with FastAPI to write tests in the same style as other Splinter drivers (like Selenium).
  • How: The StarletteClient interacts with FastAPI applications by using Starlette’s TestClient, providing the ability to perform HTTP requests and parse responses as if they were browser interactions.

2. Updated Import Statements:

  • What: Modified the import section to include StarletteClient among the list of available drivers.
  • Why: This update allows developers to import and use the StarletteClient just like the other existing drivers (e.g., ChromeDriver, FirefoxDriver, FlaskClient), providing consistency across different testing frameworks.
  • How: By adding StarletteClient to the import block, it enables seamless integration with Splinter’s current import structure.

Updated import block:

from splinter.driver.webdriver.chrome import WebDriver as ChromeDriver
from splinter.driver.webdriver.firefox import WebDriver as FirefoxDriver
from splinter.driver.webdriver.edge import WebDriver as EdgeDriver
from splinter.driver.djangoclient import DjangoClient
from splinter.driver.flaskclient import FlaskClient
from splinter.driver.zopetestbrowser import ZopeTestBrowser
from splinter.driver.starletteclient import StarletteClient  # Added StarletteClient for FastAPI testing

3. Why Web Drivers Were Included:

Consistency and Compatibility: By adding StarletteClient to the same import section as other web drivers like ChromeDriver, FirefoxDriver, and EdgeDriver, we ensure that Splinter remains compatible with its existing structure, making it easy for developers to transition between different types of web frameworks.
Unified Testing Interface: Users familiar with Splinter’s testing style (via Selenium or other drivers) can now write tests for FastAPI applications using the same approach, without needing to learn a new API.
Broad Framework Support: Supporting FastAPI in Splinter expands the utility of the library, catering to the growing demand for FastAPI, which is becoming one of the most popular frameworks for building modern web applications.

Conclusion:

With this update, Splinter now supports testing FastAPI applications using the StarletteClient driver. This allows developers to write tests for API-based apps in a simple, uniform manner. The addition of StarletteClient to Splinter ensures that the library continues to stay relevant by supporting more modern and popular frameworks, keeping it a versatile tool for web application testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant