Last active
May 30, 2025 06:51
-
-
Save cb109/f480e6890b543d4a6614f8776a9b8a9a to your computer and use it in GitHub Desktop.
Passing information from pytest to cypress for e2e tests using an env var and a test-specific view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def e2e_my_test(db): | |
| my_object = ... | |
| os.environ["MY_DYNAMIC_URL"] = my_object.url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('Test against a dynamic URL', () => { | |
| it('should visit the dynamic URL', () => { | |
| const envLookupURL = Cypress.env('apiBaseUrl') + 'e2e/env' + '?env_var=MY_DYNAMIC_URL'; | |
| cy.request({ | |
| method: 'GET', | |
| url: envLookupURL, | |
| }) | |
| .then((response) => { | |
| const dynamicURL = response.body; | |
| cy.visit(dynamicURL); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| # Enable this lookup only during test runs. | |
| if os.environ["IS_TEST_RUN"]: | |
| urlpatterns.extend( | |
| [ | |
| # This view takes an env_var GET parameter and returns its value from os.environ. | |
| re_path(r"^e2e/env$", client_views.e2e_env_lookup), | |
| ] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment