File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,25 @@ def get_session(driver: webdriver) -> str:
2222 return driver .session_id
2323
2424
25+ def is_local (path : str ) -> str :
26+ """Return valid URL path for file
27+
28+ Args:
29+ path (str): normal path or URL
30+
31+ Returns:
32+ str: Modified file path if local file
33+ Returns path as it is if URL
34+ """
35+ import os
36+
37+ URL = path
38+ if os .path .exists (path ) or path .startswith ("file" ):
39+ if not URL .startswith ("file" ):
40+ URL = f"file://{ URL } "
41+ return URL
42+
43+
2544def visit (driver : webdriver , url : str ) -> None :
2645 """Visit given url
2746
@@ -32,7 +51,7 @@ def visit(driver: webdriver, url: str) -> None:
3251 Returns:
3352 None
3453 """
35- driver .get (url )
54+ driver .get (is_local ( url ) )
3655
3756
3857def page_source (driver : webdriver ) -> str :
Original file line number Diff line number Diff line change 1+ """
2+ Test related to utilities
3+ """
4+ import os
5+
6+ from s_tool .utils import is_local
7+
8+
9+ def test_local_path ():
10+ """test local file path or URL"""
11+ URL_PATH = "http://www.google.com"
12+ URL_PATH1 = "www.google.com"
13+ LOCAL_PATH = "tests/index.html"
14+
15+ assert URL_PATH == is_local (URL_PATH )
16+ assert "file" in is_local (os .path .abspath (LOCAL_PATH ))
17+ assert URL_PATH1 == is_local (URL_PATH1 )
You can’t perform that action at this time.
0 commit comments