|
7 | 7 | from os import remove
|
8 | 8 | from random import shuffle
|
9 | 9 | from typing import List, Literal, Union
|
| 10 | +from urllib.parse import urlparse, urlunparse |
10 | 11 |
|
11 | 12 | from faker import Faker
|
12 | 13 | from faker.providers import internet, misc
|
@@ -370,21 +371,15 @@ def assert_json_value(self, json_data, jsonpath_expr, expected_value):
|
370 | 371 | f"Expected {expected_value}, but got {match[0].value}",
|
371 | 372 | )
|
372 | 373 |
|
373 |
| - def trim_url_to_last_slash(self, url: str): |
| 374 | + def get_domain_from_url(self, url: str) -> str: |
374 | 375 | """
|
375 |
| - Given a URL, it will create a copy and trim it to the first slash. It does not include the last / after trimming. |
376 |
| - """ |
377 |
| - # Find the position of the last slash |
378 |
| - last_slash_index = url.rfind("/") |
379 |
| - |
380 |
| - # Slice the string up to and including the last slash |
381 |
| - if last_slash_index != -1: |
382 |
| - trimmed_url = url[:last_slash_index] |
383 |
| - else: |
384 |
| - logging.warn("Couldn't find the last instance of a /.") |
385 |
| - trimmed_url = url |
| 376 | + Given a URL, it will extract the domain of the URL. |
386 | 377 |
|
387 |
| - return trimmed_url |
| 378 | + For example, "https://www.example.com/path/to/page?query=123#fragment" will product "https://www.example.com" |
| 379 | + """ |
| 380 | + parsed_url = urlparse(url) |
| 381 | + domain_parsed_url = parsed_url._replace(path="") |
| 382 | + return urlunparse(domain_parsed_url) |
388 | 383 |
|
389 | 384 |
|
390 | 385 | class BrowserActions:
|
|
0 commit comments