vigilant-kit 1.2.9__tar.gz → 1.4.0__tar.gz

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.

Files changed (35) hide show
  1. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/CHANGELOG.md +22 -0
  2. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/PKG-INFO +7 -14
  3. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/README.md +5 -12
  4. vigilant_kit-1.4.0/docs/configuration.md +58 -0
  5. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/pyproject.toml +4 -7
  6. vigilant_kit-1.4.0/src/vigilant/driver/__init__.py +24 -0
  7. vigilant_kit-1.4.0/src/vigilant/driver/vigilant_driver.py +45 -0
  8. vigilant_kit-1.4.0/vgl_config.yaml.example +8 -0
  9. vigilant_kit-1.2.9/.vigilant.env.example +0 -5
  10. vigilant_kit-1.2.9/docs/configuration.md +0 -76
  11. vigilant_kit-1.2.9/src/vgl_cli/install_dev_kit_command.py +0 -14
  12. vigilant_kit-1.2.9/src/vgl_cli/install_standalone_command.py +0 -44
  13. vigilant_kit-1.2.9/src/vgl_cli/install_webdriver_command.py +0 -111
  14. vigilant_kit-1.2.9/src/vgl_cli/selenium_commands.py +0 -47
  15. vigilant_kit-1.2.9/src/vgl_cli/vgl.py +0 -26
  16. vigilant_kit-1.2.9/src/vigilant/driver/__init__.py +0 -81
  17. vigilant_kit-1.2.9/src/vigilant/driver/vigilant_driver.py +0 -87
  18. vigilant_kit-1.2.9/vigilant.json.example +0 -7
  19. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/.gitignore +0 -0
  20. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/LICENSE +0 -0
  21. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/bin/doc_generator.py +0 -0
  22. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/actions.md +0 -0
  23. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/browser_options.md +0 -0
  24. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/native_selenium.md +0 -0
  25. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/selenium_install.md +0 -0
  26. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/tutorial_pytest.md +0 -0
  27. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/vigilant_pytest.md +0 -0
  28. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/docs/vigilant_unittest.md +0 -0
  29. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/__init__.py +0 -0
  30. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/actions/__init__.py +0 -0
  31. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/actions/assertions.py +0 -0
  32. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/actions/finder.py +0 -0
  33. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/actions/vigilant_actions.py +0 -0
  34. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/actions/waiter.py +0 -0
  35. {vigilant_kit-1.2.9 → vigilant_kit-1.4.0}/src/vigilant/logger.py +0 -0
@@ -1,4 +1,26 @@
1
1
  # Changelog for Vigilant Kit
2
+ ## Version 1.4.0
3
+
4
+ ### Code Refactoring
5
+ - Removed `vgl` CLI.
6
+ - Updated `VigilantDriver` class, now scripts can be run without Selenium server, only using local browser.
7
+ - Updated documentation related to new configuration.
8
+
9
+ ### Dependencies
10
+
11
+ - Removed pacakge: `click`.
12
+
13
+
14
+ ## Version 1.3.0
15
+
16
+ ### New Features
17
+
18
+ - Changed way of configuration for local development. Introduced `vgl_config.yaml` file.
19
+ - Updated documentation related to new configuration.
20
+
21
+ ### Dependencies
22
+
23
+ - Added new dependency: `pyyaml`.
2
24
 
3
25
  ## Version 1.2.9
4
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vigilant_kit
3
- Version: 1.2.9
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,9 +8,9 @@ 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
13
+ Requires-Dist: pyyaml
14
14
  Requires-Dist: requests
15
15
  Requires-Dist: selenium
16
16
  Description-Content-Type: text/markdown
@@ -22,17 +22,17 @@ Vigilant, you can start writing complex test cases in a minute.
22
22
  ## Why Vigilant?
23
23
  * **Easy to start & Fast To Write**: Vigilant provides you with methods that help you write functional tests quickly
24
24
  without spending time on writing boilerplate code every time you start a new project.
25
- * **Flexible Framework Usage**: Usage is not limited to a single testing framework; you can use Vigilant with unittest,
26
- pytest, or anything else.
27
- * **Stability**: We use Selenium WebDriver. It is a W3C Recommendation.
25
+ * **No limit in usage**: You are not limited to a single testing framework; you can use Vigilant with **unittest**,
26
+ **pytest**, or for **scrapping data**. It's just a tool, use it as you want.
27
+ * **Stability**: We use Selenium WebDriver. It is a **W3C standard**.
28
28
  - WebDriver drives a browser natively, as a user would, either locally or on a remote machine using the Selenium server.
29
29
  - WebDriver is designed as a simple and more concise programming interface.
30
30
  - WebDriver is a compact object-oriented API.
31
31
  - It drives the browser effectively.
32
32
 
33
33
  ## What it includes?
34
- Vigilant include methods for interacting with browser, for asserting conditions and also methods for waiting
35
- those conditions.
34
+ Vigilant provide a suite of methods designed for efficient browser interaction, robust assertion of various
35
+ conditions, and adaptive waiting mechanisms to accommodate different states and conditions.
36
36
 
37
37
  **Interacting with WebBrowser**
38
38
  - `click()`
@@ -59,11 +59,6 @@ those conditions.
59
59
  And much more! Check list of all available - [Actions](docs/actions.md)
60
60
 
61
61
 
62
- Also, CLI scripts included, to make your life easier!
63
-
64
- Use `vgl --help` to see all available commands.
65
-
66
-
67
62
  ## Extending Functionality
68
63
  If you need something that is not covered in this library, you still have access to all native `Selenium WebDriver`
69
64
  methods. You can create your own methods or use native `WebDriver` methods and share them on one browser session.
@@ -74,8 +69,6 @@ pip install vigilant-kit
74
69
  ```
75
70
 
76
71
  ## Docs
77
- ### Install
78
- - [How to install Selenium server & browser drivers](docs/selenium_install.md)
79
72
 
80
73
  ### Configuration
81
74
  - [Vigilant configuration](docs/configuration.md)
@@ -5,17 +5,17 @@ Vigilant, you can start writing complex test cases in a minute.
5
5
  ## Why Vigilant?
6
6
  * **Easy to start & Fast To Write**: Vigilant provides you with methods that help you write functional tests quickly
7
7
  without spending time on writing boilerplate code every time you start a new project.
8
- * **Flexible Framework Usage**: Usage is not limited to a single testing framework; you can use Vigilant with unittest,
9
- pytest, or anything else.
10
- * **Stability**: We use Selenium WebDriver. It is a W3C Recommendation.
8
+ * **No limit in usage**: You are not limited to a single testing framework; you can use Vigilant with **unittest**,
9
+ **pytest**, or for **scrapping data**. It's just a tool, use it as you want.
10
+ * **Stability**: We use Selenium WebDriver. It is a **W3C standard**.
11
11
  - WebDriver drives a browser natively, as a user would, either locally or on a remote machine using the Selenium server.
12
12
  - WebDriver is designed as a simple and more concise programming interface.
13
13
  - WebDriver is a compact object-oriented API.
14
14
  - It drives the browser effectively.
15
15
 
16
16
  ## What it includes?
17
- Vigilant include methods for interacting with browser, for asserting conditions and also methods for waiting
18
- those conditions.
17
+ Vigilant provide a suite of methods designed for efficient browser interaction, robust assertion of various
18
+ conditions, and adaptive waiting mechanisms to accommodate different states and conditions.
19
19
 
20
20
  **Interacting with WebBrowser**
21
21
  - `click()`
@@ -42,11 +42,6 @@ those conditions.
42
42
  And much more! Check list of all available - [Actions](docs/actions.md)
43
43
 
44
44
 
45
- Also, CLI scripts included, to make your life easier!
46
-
47
- Use `vgl --help` to see all available commands.
48
-
49
-
50
45
  ## Extending Functionality
51
46
  If you need something that is not covered in this library, you still have access to all native `Selenium WebDriver`
52
47
  methods. You can create your own methods or use native `WebDriver` methods and share them on one browser session.
@@ -57,8 +52,6 @@ pip install vigilant-kit
57
52
  ```
58
53
 
59
54
  ## Docs
60
- ### Install
61
- - [How to install Selenium server & browser drivers](docs/selenium_install.md)
62
55
 
63
56
  ### Configuration
64
57
  - [Vigilant configuration](docs/configuration.md)
@@ -0,0 +1,58 @@
1
+ # Vigilant Configuration
2
+
3
+ Vigilant is a Selenium-based library that allows you to automate web testing tasks. The configuration of Vigilant is
4
+ available through simple `vgl_config.yaml` file.
5
+
6
+ ## Configuration Options
7
+
8
+ Vigilant can be configured with the following options:
9
+
10
+ **BASE_URL**
11
+
12
+ - Description: The base URL of the website to be tested.
13
+ - YAML Path: selenium-configuration.BASE_URL
14
+ - Example: BASE_URL: http://www.python.org
15
+
16
+ **SELENIUM_HOST**
17
+
18
+ - Description: The Selenium server host URL.
19
+ - YAML Path: vgl-configuration.SELENIUM_HOST
20
+ - Example: SELENIUM_HOST: http://127.0.0.1:4444/wd/hub
21
+
22
+ When use **SELENIUM_HOST**: local - local installed browser will be used.
23
+
24
+ **SELENIUM_BROWSER**
25
+
26
+ - Description: The browser to be used for testing.
27
+ - YAML Path: selenium-configuration.SELENIUM_BROWSER
28
+ - Example: SELENIUM_BROWSER: firefox
29
+
30
+ **WAIT_TIMEOUT**
31
+
32
+ - Description: The timeout duration (in seconds) for wait operations.
33
+ - YAML Path: selenium-configuration.WAIT_TIMEOUT
34
+ - Example: WAIT_TIMEOUT: 10
35
+
36
+ **LOGGER_LEVEL**
37
+
38
+ - Description: The logging level for Vigilant.
39
+ - YAML Path: selenium-configuration.LOGGER_LEVEL
40
+ - Example: LOGGER_LEVEL: INFO
41
+
42
+ ## Configuration File
43
+
44
+ The configuration file `vgl_config.yaml` should be structured as follows:
45
+
46
+ ```yaml
47
+ vgl-configuration:
48
+ BASE_URL: http://www.python.org
49
+ SELENIUM_HOST: http://127.0.0.1:4444/wd/hub
50
+ SELENIUM_BROWSER: firefox
51
+ WAIT_TIMEOUT: 10
52
+ LOGGER_LEVEL: INFO
53
+ ```
54
+ You can modify the values in the YAML file to suit your specific configuration requirements.
55
+
56
+ ## Environment Variables
57
+ Vigilant will automatically load these settings as environment variables at runtime. There's no need to manually set
58
+ environment variables if they are defined in the `vgl_config.yaml` file.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "vigilant_kit"
7
- version = "1.2.9"
7
+ version = "1.4.0"
8
8
  authors = [
9
9
  { name="Pelykh Ivan", email="ivan.pelykh@protonmail.com" },
10
10
  ]
@@ -14,15 +14,15 @@ requires-python = ">=3.7"
14
14
  dependencies = [
15
15
  "selenium",
16
16
  "python-dotenv",
17
- "click",
18
17
  "requests",
19
- "psutil"
18
+ "psutil",
19
+ "pyyaml"
20
20
  ]
21
21
 
22
22
  keywords = ["testing", "selenium", "webdriver", "pytest", "unittest", "bdd", "tdd", "functional", "functional-testing"]
23
23
 
24
24
  [tool.hatch.build.targets.wheel]
25
- packages = ["src/vigilant", "src/vgl_cli"]
25
+ packages = ["src/vigilant"]
26
26
 
27
27
  classifiers = [
28
28
  "Programming Language :: Python :: 3",
@@ -33,6 +33,3 @@ classifiers = [
33
33
  [project.urls]
34
34
  "Homepage" = "https://github.com/ivpel/vigilant"
35
35
  "Bug Tracker" = "https://github.com/ivpel/vigilant/issues"
36
-
37
- [project.scripts]
38
- vgl = "vgl_cli.vgl:vgl"
@@ -0,0 +1,24 @@
1
+ import os
2
+ import yaml
3
+ from pathlib import Path
4
+
5
+ def set_env_variables_from_dict(data):
6
+ for key, value in data.items():
7
+ os.environ[key] = str(value)
8
+
9
+ def set_env_variables_from_yaml(yaml_path):
10
+ with open(yaml_path, 'r') as file:
11
+ configs = yaml.safe_load(file)
12
+
13
+ selenium_config = configs.get('vgl-configuration', {})
14
+ set_env_variables_from_dict(selenium_config)
15
+
16
+
17
+ CONFIG_YAML_FILE = 'vgl_config.yaml'
18
+
19
+ if Path(CONFIG_YAML_FILE).exists():
20
+ print(f"Setting configuration from {CONFIG_YAML_FILE} file.")
21
+ set_env_variables_from_yaml(CONFIG_YAML_FILE)
22
+ else:
23
+ print(f"Could not find `{CONFIG_YAML_FILE}` configuration file.")
24
+ print("If you don't want to use the yaml configuration file, ensure you provide all configuration data as environment variables.")
@@ -0,0 +1,45 @@
1
+ import os
2
+
3
+ from selenium import webdriver
4
+
5
+ from vigilant.actions.vigilant_actions import VigilantActions
6
+ from vigilant.logger import logger as log
7
+
8
+
9
+ class VigilantDriver(VigilantActions):
10
+
11
+ SELENIUM_HOST = os.environ.get("SELENIUM_HOST")
12
+ SELENIUM_BROWSER = os.environ.get("SELENIUM_BROWSER")
13
+
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)
21
+
22
+ def default_browser_options(self):
23
+ options = None
24
+ if self.SELENIUM_BROWSER.lower() == "firefox":
25
+ options = webdriver.FirefoxOptions()
26
+ elif self.SELENIUM_BROWSER.lower() == "chrome":
27
+ options = webdriver.ChromeOptions()
28
+ log.info(f"Setting default browser options: {self.SELENIUM_BROWSER}")
29
+ return options
30
+
31
+ def create_remote_driver_session(self, browser_options):
32
+ log.info("Creating remote session.\n"
33
+ f"Command executor: {self.SELENIUM_HOST}\n"
34
+ f"Browser: {self.SELENIUM_BROWSER}")
35
+ return webdriver.Remote(command_executor=self.SELENIUM_HOST,
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")
@@ -0,0 +1,8 @@
1
+ selenium-configuration:
2
+ BASE_URL: http://www.python.org
3
+ SELENIUM_HOST: local #http://127.0.0.1:4444/wd/hub
4
+ SELENIUM_BROWSER: firefox
5
+ WAIT_TIMEOUT: 10
6
+ LOGGER_LEVEL: INFO
7
+ test-credentials:
8
+ file: credentials.yaml
@@ -1,5 +0,0 @@
1
- BASE_URL=http://www.python.org
2
- SELENIUM_HOST=http://127.0.0.1:4444/wd/hub
3
- SELENIUM_BROWSER=firefox
4
- WAIT_TIMEOUT=10
5
- LOGGER_LEVEL=INFO
@@ -1,76 +0,0 @@
1
- # Vigilant Configuration
2
-
3
- Vigilant is a Selenium-based library that allows you to automate web testing tasks. The configuration of Vigilant can be
4
- customized using environment variables. You have the option to configure Vigilant using either a `.vigilant.env` file or
5
- a `vigilant.json` file. Alternatively, you can directly set the configuration using environment variables of your choice.
6
-
7
- ## Configuration Options
8
- **BASE_URL**
9
-
10
- Description: The base URL of the website to be tested.
11
- Environment Variable: BASE_URL
12
- Example: BASE_URL=http://www.python.org
13
-
14
- **SELENIUM_HOST**
15
-
16
- Description: The Selenium server host URL.
17
- Environment Variable: SELENIUM_HOST
18
- Example: SELENIUM_HOST=http://127.0.0.1:4444/wd/hub
19
-
20
- **SELENIUM_BROWSER**
21
-
22
- Description: The browser to be used for testing.
23
- Environment Variable: SELENIUM_BROWSER
24
- Example: SELENIUM_BROWSER=firefox
25
-
26
- **WAIT_TIMEOUT**
27
-
28
- Description: The timeout duration (in seconds) for wait operations.
29
- Environment Variable: WAIT_TIMEOUT
30
- Example: WAIT_TIMEOUT=10
31
-
32
- **LOGGER_LEVEL**
33
-
34
- Description: The logging level for Vigilant.
35
- Environment Variable: LOGGER_LEVEL
36
- Example: LOGGER_LEVEL=INFO
37
-
38
- ## Configuration Files
39
- **vigilant.json**
40
-
41
- The `vigilant.json` file allows you to define the configuration options in a JSON format. Here's an example of the
42
- `vigilant.json` file:
43
- ```json
44
- {
45
- "BASE_URL": "http://www.python.org",
46
- "SELENIUM_HOST": "http://127.0.0.1:4444/wd/hub",
47
- "SELENIUM_BROWSER": "firefox",
48
- "WAIT_TIMEOUT": 10,
49
- "LOGGER_LEVEL": "INFO"
50
- }
51
- ```
52
-
53
- You can modify the values in the JSON file to suit your specific configuration requirements.
54
- `.vigilant.env`
55
-
56
- The `.vigilant.env` file allows you to define the configuration options in a key-value format. Each configuration option
57
- is set as an environment variable. Here's an example of the `.vigilant.env` file:
58
- ```shell
59
- BASE_URL=http://www.python.org
60
- SELENIUM_HOST=http://127.0.0.1:4444/wd/hub
61
- SELENIUM_BROWSER=firefox
62
- WAIT_TIMEOUT=10
63
- LOGGER_LEVEL=INFO
64
-
65
- ```
66
- Each line represents a configuration option in the format **KEY=VALUE**.
67
-
68
- ## Environment Variables
69
-
70
- Alternatively, you can directly set the configuration options using environment variables of your choice. Simply set the desired environment variables with the appropriate values.
71
-
72
- ## Note
73
-
74
- Ensure that you have the required dependencies and tools installed for Vigilant, such as Selenium and the corresponding browser drivers.
75
-
76
- By configuring Vigilant using the methods mentioned above, you can customize its behavior to suit your testing needs and automate web testing tasks effectively.
@@ -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.")
@@ -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,81 +0,0 @@
1
- import os
2
- import json
3
- from dotenv import load_dotenv, find_dotenv
4
-
5
-
6
- def check_env_variables_exist(variables):
7
- missing_variables = []
8
- for variable in variables:
9
- if variable not in os.environ:
10
- missing_variables.append(variable)
11
-
12
- if missing_variables:
13
- raise ValueError(f"Environment variables are missing: {', '.join(missing_variables)}")
14
-
15
- return True
16
-
17
-
18
- def check_json_file_exist(filename):
19
- current_dir = os.getcwd()
20
-
21
- while True:
22
- for root, dirs, files in os.walk(current_dir):
23
- if filename in files:
24
- return True
25
-
26
- parent_dir = os.path.dirname(current_dir)
27
- # Check if reached the root directory
28
- if current_dir == parent_dir:
29
- break
30
- current_dir = parent_dir
31
-
32
- return False
33
-
34
-
35
- def find_json_file(filename):
36
- current_dir = os.getcwd()
37
-
38
- while True:
39
- for root, dirs, files in os.walk(current_dir):
40
- if filename in files:
41
- return os.path.join(root, filename)
42
-
43
- parent_dir = os.path.dirname(current_dir)
44
- # Check if reached the root directory
45
- if current_dir == parent_dir:
46
- break
47
- current_dir = parent_dir
48
-
49
- return None
50
-
51
-
52
- def set_env_variables_from_json(filename):
53
- json_file_path = find_json_file(filename)
54
- if json_file_path is None:
55
- print(f"JSON file '{filename}' not found in the project's root directory or its subdirectories.")
56
- return
57
-
58
- with open(json_file_path, 'r') as file:
59
- data = json.load(file)
60
-
61
- for key, value in data.items():
62
- os.environ[key] = str(value)
63
-
64
-
65
- env_variables = ['BASE_URL', 'SELENIUM_HOST', 'SELENIUM_BROWSER', 'WAIT_TIMEOUT', 'LOGGER_LEVEL']
66
- json_configuration_file = 'vigilant.json'
67
- env_configuration_file = '.vigilant.env'
68
-
69
- if find_dotenv(env_configuration_file):
70
- print("Setting configuration from .vigilant.env file.")
71
- load_dotenv(env_configuration_file)
72
- elif check_json_file_exist(json_configuration_file):
73
- print("Setting configuration from .vigilant.json file.")
74
- set_env_variables_from_json(json_configuration_file)
75
- else:
76
- print("Could not find nor `.vigilant.env` nor `vigilant.json` configuration files.")
77
- print("If you don't want to use `.vigilant.env` nor `vigilant.json` configuration files - make sure, "
78
- "that you provide all configuration data as environment variables through the way that is acceptable for "
79
- "you (pipeline configuration, custom bash script, etc.).")
80
- if check_env_variables_exist(env_variables):
81
- print("All mandatory environment variables exist.")
@@ -1,87 +0,0 @@
1
- import os
2
-
3
- from selenium import webdriver
4
-
5
- from vigilant.actions.vigilant_actions import VigilantActions
6
- from vigilant.logger import logger as log
7
-
8
-
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
-
50
- SELENIUM_HOST = os.environ.get("SELENIUM_HOST")
51
- SELENIUM_BROWSER = os.environ.get("SELENIUM_BROWSER")
52
-
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.
57
-
58
- Returns:
59
- Options: return default browser options according to value from SELENIUM_BROWSER variable.
60
- """
61
- options = None
62
- if self.SELENIUM_BROWSER.lower() == "firefox":
63
- options = webdriver.FirefoxOptions()
64
- elif self.SELENIUM_BROWSER.lower() == "chrome":
65
- options = webdriver.ChromeOptions()
66
- log.info(f"Setting default browser options: {self.SELENIUM_BROWSER}")
67
- return options
68
-
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
- """
79
- log.info("Creating remote session.\n"
80
- f"Command executor: {self.SELENIUM_HOST}\n"
81
- f"Browser: {self.SELENIUM_BROWSER}")
82
-
83
- if browser_options is None:
84
- browser_options = self.default_browser_options()
85
-
86
- return webdriver.Remote(command_executor=self.SELENIUM_HOST,
87
- options=browser_options)
@@ -1,7 +0,0 @@
1
- {
2
- "BASE_URL": "http://www.python.org",
3
- "SELENIUM_HOST": "http://127.0.0.1:4444/wd/hub",
4
- "SELENIUM_BROWSER": "firefox",
5
- "WAIT_TIMEOUT": 10,
6
- "LOGGER_LEVEL": "INFO"
7
- }
File without changes
File without changes