vigilant-kit 1.3.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vigilant-kit might be problematic. Click here for more details.

@@ -10,17 +10,9 @@ def set_env_variables_from_yaml(yaml_path):
10
10
  with open(yaml_path, 'r') as file:
11
11
  configs = yaml.safe_load(file)
12
12
 
13
- selenium_config = configs.get('selenium-configuration', {})
13
+ selenium_config = configs.get('vgl-configuration', {})
14
14
  set_env_variables_from_dict(selenium_config)
15
15
 
16
- # Handle credentials
17
- creds_file_path = configs.get('test-credentials', {}).get('file')
18
- if creds_file_path and Path(creds_file_path).exists():
19
- with open(creds_file_path, 'r') as creds_file:
20
- credentials = yaml.safe_load(creds_file)
21
- set_env_variables_from_dict(credentials)
22
- else:
23
- print(f"Credentials file '{creds_file_path}' not found.")
24
16
 
25
17
  CONFIG_YAML_FILE = 'vgl_config.yaml'
26
18
 
@@ -7,57 +7,19 @@ from vigilant.logger import logger as log
7
7
 
8
8
 
9
9
  class VigilantDriver(VigilantActions):
10
- """
11
- VigilantDriver class provide methods for running WebDriver instance from scratch using configuration
12
- from .vigilant.env file
13
-
14
- .vigilant.env configuration items:
15
- ----------------------------------
16
- SELENIUM_HOST - is used as command_executor, it is Selenium Server URI;
17
-
18
- SELENIUM_BROWSER - used as entity that show which browser options to use FirefoxOptions(),
19
- ChromeOptions, etc. (DesiredCapabilities is now deprecated, we should use Options() class).
20
-
21
- BASE_URL - the root URL of the application under test
22
-
23
- WAIT_TIMEOUT - configuration for the default amount of time (in seconds) that a
24
- test will wait while trying to interact with web element.
25
-
26
- LOGGER_LEVEL - level of verbosity that will be printed in to the console;
27
- """
28
-
29
- def __init__(self, browser_options=None):
30
- """
31
- `driver` - if you want access native Selenium WebDriver methods;
32
- VigilantActions - allow you to use custom methods for interaction with browser directly from VigilantDriver
33
- class instance;
34
-
35
- Examples:
36
- How to use VigilantActions methods;
37
-
38
- act = VigilantDriver()
39
- act.get_page('/')
40
- act.assertions.see_text('Some Text')
41
-
42
- How to access native Selenium WebDriver methods;
43
-
44
- act = VigilantDriver()
45
- act.driver.get('https://python.org') // Here we use Selenium WebDriver get() method
46
- """
47
- self.driver = self.create_remote_driver_session(browser_options)
48
- VigilantActions.__init__(self, self.driver)
49
10
 
50
11
  SELENIUM_HOST = os.environ.get("SELENIUM_HOST")
51
12
  SELENIUM_BROWSER = os.environ.get("SELENIUM_BROWSER")
52
13
 
53
- def default_browser_options(self):
54
- """
55
- Set browser options according to browser name provided in .vigilant.env file.
56
- It can be overwritten when user create new Selenium session by providing options as argument.
14
+ def __init__(self):
15
+ browser_options = self.default_browser_options()
16
+ if self.SELENIUM_HOST in ["local", None, ""]:
17
+ self.driver = self.create_local_driver_session(browser_options)
18
+ else:
19
+ self.driver = self.create_remote_driver_session(browser_options)
20
+ VigilantActions.__init__(self, self.driver)
57
21
 
58
- Returns:
59
- Options: return default browser options according to value from SELENIUM_BROWSER variable.
60
- """
22
+ def default_browser_options(self):
61
23
  options = None
62
24
  if self.SELENIUM_BROWSER.lower() == "firefox":
63
25
  options = webdriver.FirefoxOptions()
@@ -66,22 +28,18 @@ class VigilantDriver(VigilantActions):
66
28
  log.info(f"Setting default browser options: {self.SELENIUM_BROWSER}")
67
29
  return options
68
30
 
69
- def create_remote_driver_session(self, browser_options=None):
70
- """
71
- Create a new WebDriver instance that will issue commands using the wire protocol.
72
-
73
- Args:
74
- browser_options: browser options instance is required as it determines which browser will be used
75
-
76
- Returns:
77
- Remote: remote driver session based on configuration from .vigilant.env file
78
- """
31
+ def create_remote_driver_session(self, browser_options):
79
32
  log.info("Creating remote session.\n"
80
33
  f"Command executor: {self.SELENIUM_HOST}\n"
81
34
  f"Browser: {self.SELENIUM_BROWSER}")
82
-
83
- if browser_options is None:
84
- browser_options = self.default_browser_options()
85
-
86
35
  return webdriver.Remote(command_executor=self.SELENIUM_HOST,
87
36
  options=browser_options)
37
+
38
+ def create_local_driver_session(self, browser_options):
39
+ log.info("Creating local session.\n"
40
+ f"Browser: {self.SELENIUM_BROWSER}")
41
+ if self.SELENIUM_BROWSER.lower() == "firefox":
42
+ return webdriver.Firefox(options=browser_options)
43
+ elif self.SELENIUM_BROWSER.lower() == "chrome":
44
+ return webdriver.Chrome(options=browser_options)
45
+ raise ValueError("Unsupported browser specified")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vigilant_kit
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: Library that makes functional testing with Selenium WebDriver fast and easy.
5
5
  Project-URL: Homepage, https://github.com/ivpel/vigilant
6
6
  Project-URL: Bug Tracker, https://github.com/ivpel/vigilant/issues
@@ -8,7 +8,6 @@ Author-email: Pelykh Ivan <ivan.pelykh@protonmail.com>
8
8
  License-File: LICENSE
9
9
  Keywords: bdd,functional,functional-testing,pytest,selenium,tdd,testing,unittest,webdriver
10
10
  Requires-Python: >=3.7
11
- Requires-Dist: click
12
11
  Requires-Dist: psutil
13
12
  Requires-Dist: python-dotenv
14
13
  Requires-Dist: pyyaml
@@ -60,11 +59,6 @@ conditions, and adaptive waiting mechanisms to accommodate different states and
60
59
  And much more! Check list of all available - [Actions](docs/actions.md)
61
60
 
62
61
 
63
- Also, CLI scripts included, to make your life easier!
64
-
65
- Use `vgl --help` to see all available commands.
66
-
67
-
68
62
  ## Extending Functionality
69
63
  If you need something that is not covered in this library, you still have access to all native `Selenium WebDriver`
70
64
  methods. You can create your own methods or use native `WebDriver` methods and share them on one browser session.
@@ -75,8 +69,6 @@ pip install vigilant-kit
75
69
  ```
76
70
 
77
71
  ## Docs
78
- ### Install
79
- - [How to install Selenium server & browser drivers](docs/selenium_install.md)
80
72
 
81
73
  ### Configuration
82
74
  - [Vigilant configuration](docs/configuration.md)
@@ -0,0 +1,13 @@
1
+ vigilant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ vigilant/logger.py,sha256=euYrqEDMEWNo9Eak31_4eTQEVzLZBwR8YiArhOtI9uQ,191
3
+ vigilant/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ vigilant/actions/assertions.py,sha256=OF81tGjl7qrjKuV7613owsmNHTXqa_pbpZVF7jZp6ms,6201
5
+ vigilant/actions/finder.py,sha256=Ibo1ltv2wzQ2Ol2pc_Lt2etKC08fjH3YSq1xhH0W8vg,2585
6
+ vigilant/actions/vigilant_actions.py,sha256=3XdXLIKN82aovLEWc6ed_LBy0CJgAzl6UDO3QzDkneU,13552
7
+ vigilant/actions/waiter.py,sha256=7S4BtffDR9jyue8lCw0_QsBfEERdXAVjkE-uepXffic,5064
8
+ vigilant/driver/__init__.py,sha256=NfSrz8wAYadeee2hzGty10eN6pa3CZxOD-6AZ6WqBlI,795
9
+ vigilant/driver/vigilant_driver.py,sha256=3iAdgcqut_q-IpBWIEuck8LhGbeMwCb8FSpmARZrXLA,1827
10
+ vigilant_kit-1.4.0.dist-info/METADATA,sha256=p3nlT8ShmkZKU3DIgIowTCHx_r_-IfqMbnbm29ECdZw,3118
11
+ vigilant_kit-1.4.0.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
12
+ vigilant_kit-1.4.0.dist-info/licenses/LICENSE,sha256=VQoL58PKrdEeZx2K4hXS7O6w4O_DMBB0XFE-GjK1CMo,35125
13
+ vigilant_kit-1.4.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.18.0
2
+ Generator: hatchling 1.21.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,14 +0,0 @@
1
- import click
2
- from .install_webdriver_command import check_version_and_download_driver
3
- from .install_standalone_command import check_req_and_install_selenium_server
4
-
5
-
6
- @click.command(name='install:dev-kit', help="Install local development kit (Webdriver, Selenium Server, etc)")
7
- @click.option('-b', '--browser', type=click.Choice(['chrome', 'firefox', 'edge']), required=True)
8
- def install_dev_kit(browser):
9
- check_req_and_install_selenium_server()
10
- check_version_and_download_driver(browser)
11
-
12
-
13
- if __name__ == "__main__":
14
- install_dev_kit()
@@ -1,44 +0,0 @@
1
- import click
2
- import os
3
- import requests
4
-
5
- SELENIUM_SERVER_URL = "https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar"
6
- SELENIUM_SERVER_FILE = "selenium-server/selenium-server-standalone.jar"
7
-
8
-
9
- def check_selenium_requirements():
10
- java_path = os.popen("which java").read().strip()
11
- if not java_path:
12
- click.secho("Java is not installed on this machine.", fg="red")
13
- return False
14
-
15
- java_version = os.popen("java -version 2>&1 | awk -F '\"' '/version/ {print $2}'").read().strip()
16
- major_version = java_version.split('.')[0]
17
- if int(major_version) < 9:
18
- click.secho(f"Java version {java_version} is not supported. Please install Java 9 or higher.", fg="red")
19
- return False
20
-
21
- return True
22
-
23
-
24
- def download_selenium_server():
25
- response = requests.get(SELENIUM_SERVER_URL)
26
- os.makedirs("selenium-server", exist_ok=True)
27
- with open(SELENIUM_SERVER_FILE, "wb") as f:
28
- f.write(response.content)
29
-
30
-
31
- def check_req_and_install_selenium_server():
32
- if check_selenium_requirements():
33
- click.secho("Downloading Selenium Standalone server ...", nl=False)
34
- download_selenium_server()
35
- click.secho("OK", fg="green")
36
-
37
-
38
- @click.command(name="install:standalone", help="Install Selenium Standalone server.")
39
- def install_selenium_standalone():
40
- check_req_and_install_selenium_server()
41
-
42
-
43
- if __name__ == "__main__":
44
- install_selenium_standalone()
@@ -1,111 +0,0 @@
1
- import click
2
- import os
3
- import platform
4
- import requests
5
- import tarfile
6
- import zipfile
7
-
8
- BROWSER_VERSIONS = {
9
- "chrome": "https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
10
- "firefox": "https://api.github.com/repos/mozilla/geckodriver/releases/latest",
11
- "edge": "https://msedgedriver.azureedge.net/LATEST_RELEASE"
12
- }
13
-
14
-
15
- def get_browser_version(browser):
16
- if browser == "chrome":
17
- # Get the latest version of Chrome from the output of the "google-chrome --version" command
18
- chrome_version = os.popen("google-chrome --version").read().strip().split()[-1]
19
- return chrome_version
20
- elif browser == "firefox":
21
- # Get the latest version of Firefox from the output of the "firefox --version" command
22
- firefox_version = os.popen("firefox --version").read().strip().split()[-1]
23
- return firefox_version.split('.')[0]
24
- elif browser == "edge":
25
- try:
26
- # Get the latest version of Edge from the output of the "msedge --version" command
27
- edge_version = os.popen("msedge --version").read().strip().split()[-1]
28
- return edge_version.split('.')[0]
29
- except IndexError:
30
- click.echo(f"Failed to get {browser} version")
31
- return None
32
- else:
33
- click.echo(f"{browser} is not a supported browser")
34
- return None
35
-
36
-
37
- def download_driver(browser, version):
38
- download_url = None
39
- if browser in BROWSER_VERSIONS:
40
- if browser == "chrome":
41
- # Get the major version of the Chrome browser installed on the machine
42
- chrome_version = get_browser_version(browser)
43
- if chrome_version is None:
44
- click.secho(f"{browser} is not installed on this machine.", fg="red")
45
- return
46
- # Use the ChromeDriver API to get the latest version of the ChromeDriver that is compatible with the installed Chrome browser
47
- response = requests.get(f"https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{chrome_version.split('.')[0]}")
48
- if response.status_code == 200:
49
- latest_version = response.text
50
- download_url = f"https://chromedriver.storage.googleapis.com/{latest_version}/chromedriver_{platform.system().lower()}64.zip"
51
- else:
52
- click.secho(f"Could not find latest {browser} driver version.", fg="red")
53
- elif browser == "firefox":
54
- r = requests.get(BROWSER_VERSIONS[browser])
55
- release_info = r.json()
56
- for asset in release_info["assets"]:
57
- if platform.system().lower() in asset["name"] and "tar.gz" in asset["name"]:
58
- download_url = asset["browser_download_url"]
59
- break
60
- else:
61
- click.secho(f"Could not find latest {browser} driver version... Fail", fg="red")
62
- elif browser == "edge":
63
- download_url = f"https://msedgedriver.azureedge.net/{version}/edgedriver_{platform.system().lower()}.zip"
64
- else:
65
- click.secho(f"Invalid browser name '{browser}'", fg="red")
66
- return
67
- else:
68
- click.secho(f"Could not find browser '{browser}'.", fg="red")
69
- return
70
-
71
- if download_url is not None:
72
- response = requests.get(download_url)
73
- if download_url.endswith(".zip"):
74
- with open(f"selenium-server/{browser}_driver.zip", "wb") as f:
75
- f.write(response.content)
76
- with zipfile.ZipFile(f"selenium-server/{browser}_driver.zip", 'r') as zip_ref:
77
- for member in zip_ref.namelist():
78
- zip_ref.extract(member, f"selenium-server/")
79
- elif download_url.endswith(".tar.gz"):
80
- with open(f"selenium-server/{browser}_driver.tar.gz", "wb") as f:
81
- f.write(response.content)
82
- with tarfile.open(f"selenium-server/{browser}_driver.tar.gz", 'r:gz') as tar_ref:
83
- tar_ref.extractall(f"selenium-server/")
84
- else:
85
- click.secho(f"Could not find download URL for {browser} driver.", fg="red")
86
-
87
-
88
- def check_version_and_download_driver(browser):
89
- version = get_browser_version(browser)
90
- if version is None:
91
- click.secho(f"{browser} is not installed on this machine", fg="red")
92
- else:
93
- click.secho(f"Found: {browser} browser, version {version}.", fg="cyan")
94
- # Download the driver for the browser
95
- click.echo(f"Downloading driver for {browser} browser ... ", nl=False)
96
- download_driver(browser, version)
97
- click.secho("OK", fg="green")
98
-
99
-
100
- @click.command(name='install:webdriver', help="Install the webdriver for a chosen browser.")
101
- @click.option('-b', '--browser', type=click.Choice(['chrome', 'firefox', 'edge']), required=True)
102
- def install_webdriver(browser):
103
- # Create the selenium-server directory if it doesn't exist
104
- os.makedirs("selenium-server", exist_ok=True)
105
-
106
- # Check if the browser is installed and get its version
107
- check_version_and_download_driver(browser)
108
-
109
-
110
- if __name__ == "__main__":
111
- install_webdriver()
@@ -1,47 +0,0 @@
1
- import subprocess
2
- import click
3
- import psutil
4
-
5
- SELENIUM_SERVER_JAR = "selenium-server/selenium-server-standalone.jar"
6
-
7
-
8
- def find_selenium_server_process():
9
- for process in psutil.process_iter(['pid', 'name', 'cmdline']):
10
- if process.info['name'] == 'java' and SELENIUM_SERVER_JAR in process.info['cmdline']:
11
- return process
12
- return None
13
-
14
-
15
- @click.command(name='server:run', help="Run Selenium Server JAR file")
16
- @click.option('--port', '-p', type=int, default=4444, help="Port number for the server")
17
- @click.option('--driver', '-D', multiple=True,
18
- help="Specify driver options (e.g. -Dwebdriver.chrome.driver=chromedriver)")
19
- @click.option('--daemon', '-d', is_flag=True, help="Run the server as a daemon")
20
- def run_selenium_server(port, driver, daemon):
21
- driver_options = " ".join(driver)
22
- cmd = ["java", "-jar", SELENIUM_SERVER_JAR, "-port", str(port)]
23
- cmd.extend(driver_options.split())
24
-
25
- click.echo(f"Running Selenium Server with command:\n {' '.join(cmd)}")
26
-
27
- if daemon:
28
- # Start the process in the background (daemon mode) using subprocess.Popen
29
- process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
30
- click.echo(f"Selenium Server is running in daemon mode with PID: {process.pid}")
31
- else:
32
- # Start the process in the foreground and wait for it to finish using subprocess.run
33
- subprocess.run(cmd)
34
-
35
-
36
- @click.command(name='server:stop', help="Stop the running Selenium Server")
37
- def stop_selenium_server():
38
- selenium_server_process = find_selenium_server_process()
39
- if selenium_server_process:
40
- pid = selenium_server_process.info['pid']
41
- try:
42
- selenium_server_process.terminate()
43
- click.echo(f"Selenium Server with PID {pid} has been stopped.")
44
- except psutil.NoSuchProcess:
45
- click.echo(f"Failed to stop Selenium Server. Process with PID {pid} does not exist.")
46
- else:
47
- click.echo("Selenium Server is not running in daemon mode.")
vgl_cli/vgl.py DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- import click
4
- from .install_webdriver_command import install_webdriver
5
- from .install_standalone_command import install_selenium_standalone
6
- from .install_dev_kit_command import install_dev_kit
7
-
8
- from .selenium_commands import run_selenium_server, stop_selenium_server
9
-
10
-
11
- @click.group(name="vgl.py")
12
- def vgl():
13
- pass
14
-
15
-
16
- vgl.add_command(run_selenium_server)
17
- vgl.add_command(stop_selenium_server)
18
-
19
-
20
- vgl.add_command(install_webdriver)
21
- vgl.add_command(install_selenium_standalone)
22
- vgl.add_command(install_dev_kit)
23
-
24
-
25
- if __name__ == '__main__':
26
- vgl()
@@ -1,19 +0,0 @@
1
- vgl_cli/install_dev_kit_command.py,sha256=wVcUa0lHpu18zYMm0jO_ahuFEhmNwo9iVIKiMjH7j1Y,547
2
- vgl_cli/install_standalone_command.py,sha256=3E3WX2nqdGHz343dJGkBbboDl-JFzZsa56lna7kLwsU,1447
3
- vgl_cli/install_webdriver_command.py,sha256=xOljxceAVN1ZRkbyQNq55FbHXdKad2B4mNRBiS0fLHY,5032
4
- vgl_cli/selenium_commands.py,sha256=z-FfRAn95q5JeJmATBp8yknMGP_WVoBt7gzSBmoKMLY,2029
5
- vgl_cli/vgl.py,sha256=Ve-Z4d7zqzyGo88e7EpWEDYmRiOdxHsConmBMJ4F9YA,569
6
- vigilant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- vigilant/logger.py,sha256=euYrqEDMEWNo9Eak31_4eTQEVzLZBwR8YiArhOtI9uQ,191
8
- vigilant/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- vigilant/actions/assertions.py,sha256=OF81tGjl7qrjKuV7613owsmNHTXqa_pbpZVF7jZp6ms,6201
10
- vigilant/actions/finder.py,sha256=Ibo1ltv2wzQ2Ol2pc_Lt2etKC08fjH3YSq1xhH0W8vg,2585
11
- vigilant/actions/vigilant_actions.py,sha256=3XdXLIKN82aovLEWc6ed_LBy0CJgAzl6UDO3QzDkneU,13552
12
- vigilant/actions/waiter.py,sha256=7S4BtffDR9jyue8lCw0_QsBfEERdXAVjkE-uepXffic,5064
13
- vigilant/driver/__init__.py,sha256=KxjfR3hmAtjKtExNrXOPllEv30eJFF-LMNoKLr-YFyI,1187
14
- vigilant/driver/vigilant_driver.py,sha256=rw5CfWfBWOIFPgnkmxTi7cSbrrxLtDtRlxg2FMfyEVw,3398
15
- vigilant_kit-1.3.0.dist-info/METADATA,sha256=b0ZVWIsMRkNzAx-Gs-VI1CDRlz06glBfGfVEGnzZSUM,3335
16
- vigilant_kit-1.3.0.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
17
- vigilant_kit-1.3.0.dist-info/entry_points.txt,sha256=c_azSnuBSdtgwdPlioaG0n2gZOEhuPIzL9VQ8DeKTow,40
18
- vigilant_kit-1.3.0.dist-info/licenses/LICENSE,sha256=VQoL58PKrdEeZx2K4hXS7O6w4O_DMBB0XFE-GjK1CMo,35125
19
- vigilant_kit-1.3.0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- vgl = vgl_cli.vgl:vgl