vigilant-kit 1.1.1__tar.gz → 1.2.1__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 (34) hide show
  1. vigilant_kit-1.2.1/PKG-INFO +59 -0
  2. vigilant_kit-1.2.1/README.md +43 -0
  3. vigilant_kit-1.2.1/docs/selenium_install.md +50 -0
  4. vigilant_kit-1.1.1/README.md → vigilant_kit-1.2.1/docs/vigilant_unittest.md +1 -40
  5. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/pyproject.toml +1 -1
  6. vigilant_kit-1.2.1/src/vgl_cli/install_dev_kit_command.py +14 -0
  7. vigilant_kit-1.2.1/src/vgl_cli/install_standalone_command.py +44 -0
  8. vigilant_kit-1.2.1/src/vgl_cli/install_webdriver_command.py +111 -0
  9. vigilant_kit-1.2.1/src/vgl_cli/run_selenium_command.py +22 -0
  10. vigilant_kit-1.2.1/src/vgl_cli/vgl.py +38 -0
  11. vigilant_kit-1.1.1/PKG-INFO +0 -150
  12. vigilant_kit-1.1.1/docs/selenium_install.md +0 -41
  13. vigilant_kit-1.1.1/docs/vigilant_unittest.md +0 -49
  14. vigilant_kit-1.1.1/src/vgl_cli/local_dev.py +0 -51
  15. vigilant_kit-1.1.1/src/vgl_cli/utils.py +0 -11
  16. vigilant_kit-1.1.1/src/vgl_cli/vgl.py +0 -13
  17. vigilant_kit-1.1.1/src/vigilant/actions/__init__.py +0 -0
  18. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/.gitignore +0 -0
  19. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/.vigilant.env.example +0 -0
  20. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/LICENSE +0 -0
  21. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/docs/actions.md +0 -0
  22. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/docs/browser_options.md +0 -0
  23. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/docs/native_selenium.md +0 -0
  24. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/docs/tutorial_pytest.md +0 -0
  25. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/docs/vigilant_pytest.md +0 -0
  26. {vigilant_kit-1.1.1/src/vgl_cli → vigilant_kit-1.2.1/src/vigilant}/__init__.py +0 -0
  27. {vigilant_kit-1.1.1/src/vigilant → vigilant_kit-1.2.1/src/vigilant/actions}/__init__.py +0 -0
  28. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/actions/assertions.py +0 -0
  29. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/actions/finder.py +0 -0
  30. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/actions/vigilant_actions.py +0 -0
  31. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/actions/waiter.py +0 -0
  32. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/driver/__init__.py +0 -0
  33. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/driver/vigilant_driver.py +0 -0
  34. {vigilant_kit-1.1.1 → vigilant_kit-1.2.1}/src/vigilant/logger.py +0 -0
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.1
2
+ Name: vigilant_kit
3
+ Version: 1.2.1
4
+ Summary: Library that makes functional testing with Selenium WebDriver fast and easy.
5
+ Project-URL: Homepage, https://github.com/ivpel/vigilant
6
+ Project-URL: Bug Tracker, https://github.com/ivpel/vigilant/issues
7
+ Author-email: Pelykh Ivan <ivan.pelykh@protonmail.com>
8
+ License-File: LICENSE
9
+ Keywords: bdd,functional,functional-testing,pytest,selenium,tdd,testing,unittest,webdriver
10
+ Requires-Python: >=3.7
11
+ Requires-Dist: click
12
+ Requires-Dist: python-dotenv
13
+ Requires-Dist: requests
14
+ Requires-Dist: selenium
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Vigilant Kit
18
+ Vigilant is a set of tools designed to help write and run robust functional tests using Selenium WebDriver. It provides
19
+ methods for interacting with the WebBrowser, assertions, and waiting. With Vigilant, you can start writing complex test
20
+ cases in a minute.
21
+
22
+ ## Why Vigilant?
23
+ - **Easy to start & Fast To Write**: Easy configuration process, straightforward way to writing your tests.
24
+ Vigilant provides you with methods that help you write functional tests quickly without spending time on writing
25
+ boilerplate code every time you start a new project.
26
+ - **Flexible Framework Usage**: Usage is not limited to a single testing framework; you can use Vigilant with unittest,
27
+ pytest, or anything else.
28
+
29
+ ## What it includes?
30
+ Methods for **interacting** with WebBrowser (`click`, `scroll_to`, etc.), **assertions** (`see`, `dont_see`, `see_text`
31
+ , etc.) **waiters** (`wait_for_element_to_be_visible`, `wait_for_element_to_be_clickable`, etc.)
32
+ It is already there, ready to use.
33
+
34
+ Also, a bunch of CLI scripts, to make your life easier!
35
+
36
+ Use `vgl --help` to see all available commands.
37
+
38
+ List of all available [actions](docs/actions.md).
39
+
40
+ ## Extending Functionality
41
+ If you need something that is not covered in this library, you still have access to all native `Selenium WebDriver`
42
+ methods. You can create your own methods or use native `WebDriver` methods and share them on one browser session.
43
+
44
+ ## Install
45
+ ```shell
46
+ pip install vigilant-kit
47
+ ```
48
+
49
+ ## Docs
50
+ - [How to install Selenium server & browser drivers](docs/selenium_install.md)
51
+ - [Quick start example using `unittest` library](docs/vigilant_unittest.md)
52
+ - [Quick start example using `pytest`](docs/vigilant_pytest.md)
53
+ - [How to add custom browser options](docs/browser_options.md)
54
+ - [Access native Selenium WebDriver methods](docs/native_selenium.md)
55
+ - [List of actions](docs/actions.md).
56
+
57
+ ## Tutorials
58
+ - [Testing ecommerce project using `vigilant-kit` and `pytest`](docs/tutorial_pytest.md)
59
+
@@ -0,0 +1,43 @@
1
+ # Vigilant Kit
2
+ Vigilant is a set of tools designed to help write and run robust functional tests using Selenium WebDriver. It provides
3
+ methods for interacting with the WebBrowser, assertions, and waiting. With Vigilant, you can start writing complex test
4
+ cases in a minute.
5
+
6
+ ## Why Vigilant?
7
+ - **Easy to start & Fast To Write**: Easy configuration process, straightforward way to writing your tests.
8
+ Vigilant provides you with methods that help you write functional tests quickly without spending time on writing
9
+ boilerplate code every time you start a new project.
10
+ - **Flexible Framework Usage**: Usage is not limited to a single testing framework; you can use Vigilant with unittest,
11
+ pytest, or anything else.
12
+
13
+ ## What it includes?
14
+ Methods for **interacting** with WebBrowser (`click`, `scroll_to`, etc.), **assertions** (`see`, `dont_see`, `see_text`
15
+ , etc.) **waiters** (`wait_for_element_to_be_visible`, `wait_for_element_to_be_clickable`, etc.)
16
+ It is already there, ready to use.
17
+
18
+ Also, a bunch of CLI scripts, to make your life easier!
19
+
20
+ Use `vgl --help` to see all available commands.
21
+
22
+ List of all available [actions](docs/actions.md).
23
+
24
+ ## Extending Functionality
25
+ If you need something that is not covered in this library, you still have access to all native `Selenium WebDriver`
26
+ methods. You can create your own methods or use native `WebDriver` methods and share them on one browser session.
27
+
28
+ ## Install
29
+ ```shell
30
+ pip install vigilant-kit
31
+ ```
32
+
33
+ ## Docs
34
+ - [How to install Selenium server & browser drivers](docs/selenium_install.md)
35
+ - [Quick start example using `unittest` library](docs/vigilant_unittest.md)
36
+ - [Quick start example using `pytest`](docs/vigilant_pytest.md)
37
+ - [How to add custom browser options](docs/browser_options.md)
38
+ - [Access native Selenium WebDriver methods](docs/native_selenium.md)
39
+ - [List of actions](docs/actions.md).
40
+
41
+ ## Tutorials
42
+ - [Testing ecommerce project using `vigilant-kit` and `pytest`](docs/tutorial_pytest.md)
43
+
@@ -0,0 +1,50 @@
1
+ # How to install Selenium Server & browser drivers
2
+
3
+ ***
4
+ ## Option 1: Run Selenium server + browser driver locally
5
+ ### 1. Install Selenium Standalone Server and Webdriver
6
+ `vgl install dev-kit -b chrome`
7
+
8
+ If everything is okay and your machine has all dependencies installed, you will see this output:
9
+ ```text
10
+ Found: chrome browser, version 112.0.5615.165.
11
+ Downloading driver for chrome browser ... OK
12
+ Downloading Selenium Standalone server ...OK
13
+ ```
14
+
15
+ ### 2. Run Selenium Server
16
+ To run your Selenium Server use:
17
+ `vgl run selenium-server`
18
+
19
+ This command will launch Selenium Standalone server on your local machine.
20
+
21
+ ### Need help? Use `--help`
22
+ To see all available options for these commands you can use `--help` flag.
23
+
24
+ For example:
25
+ `vgl run selenium-server --help`
26
+
27
+ Will output this:
28
+ ```text
29
+ Usage: vgl run selenium-server [OPTIONS]
30
+
31
+ Run Selenium Server JAR file
32
+
33
+ Options:
34
+ -p, --port INTEGER Port number for the server
35
+ -D, --driver TEXT Specify driver options (e.g.
36
+ -Dwebdriver.chrome.driver=chromedriver)
37
+ -d, --daemon Run the server as a daemon
38
+ --help Show this message and exit.
39
+ ```
40
+
41
+ ## Option 2: Start Selenium server + browser inside Docker
42
+ ***
43
+ If you don't want to install and run Selenium server and the browser locally, you can run both of them in a Docker
44
+ container. The Selenium project provides many prepared official containers.
45
+ For example to start a container with Selenium server and Firefox, simply run:
46
+ ```shell
47
+ docker run -d -p 4446:4444 -p 7902:7900 --shm-size="2g" selenium/standalone-firefox:4.6.0-20221104
48
+ ```
49
+
50
+ For more info about available options check official [Docker Selenium](https://github.com/SeleniumHQ/docker-selenium) page.
@@ -1,42 +1,3 @@
1
- # Vigilant Kit
2
- Vigilant is a set of tools made to help writing and running robust functional tests using Selenium WebDriver.
3
-
4
- ## Why Vigilant?
5
- - It allows you to start writing complex test cases in a minute.
6
- - Simple configuration process (just one `.vigilant.env` file to start)
7
- - Usage is not limited to a single testing framework, it can be used with `unittest`, `pytest` or anything else.
8
- It is up to you.
9
-
10
- **Vigilant** provide you with methods that help write functional tests fast, without spending your time on writing
11
- boilerplate code every time you start new project.
12
-
13
- Methods for **interacting** with WebBrowser (`click`, `scroll_to`, etc.), **assertions** (`see`, `dont_see`, `see_text`
14
- , etc.) **waiting** (`wait_for_element_to_be_visible`, `wait_for_element_to_be_clickable`, etc.)
15
- It is already there, ready to use.
16
-
17
- List of all available [actions](docs/actions.md).
18
-
19
- ### What if you need something that is not covered in this library?
20
-
21
- You still have access to all native `Selenium WebDriver` methods. Despite all functional that library provide -
22
- you can create your own methods or use native `WebDriver` methods and share them on one browser session.
23
-
24
- ## Docs
25
- - [How to install Selenium server & browser drivers](docs/selenium_install.md)
26
- - [Quick start example using `unittest` library](docs/vigilant_unittest.md)
27
- - [Quick start example using `pytest`](docs/vigilant_pytest.md)
28
- - [How to add custom browser options](docs/browser_options.md)
29
- - [Access native Selenium WebDriver methods](docs/native_selenium.md)
30
- - [List of actions](docs/actions.md).
31
-
32
- ## Tutorials
33
- - [Testing ecommerce project using `vigilant-kit` and `pytest`](docs/tutorial_pytest.md)
34
-
35
- ## Install
36
- ```shell
37
- pip install vigilant-kit
38
- ```
39
-
40
1
  ## Quick start
41
2
  We will write our first test with `unittest` library. Also make sure that you installed
42
3
  `vigilant-kit` library.
@@ -44,7 +5,7 @@ We will write our first test with `unittest` library. Also make sure that you in
44
5
 
45
6
  ### Configuration
46
7
  Configuration can be done through environment variables. Make sure that your Selenium Server is up and running, if not -
47
- [**Install Selenium server**](docs/selenium_install.md)
8
+ [**Install Selenium server**](selenium_install.md)
48
9
 
49
10
  Create `.vigilant.env` file with next data:
50
11
  ```shell
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "vigilant_kit"
7
- version = "1.1.1"
7
+ version = "1.2.1"
8
8
  authors = [
9
9
  { name="Pelykh Ivan", email="ivan.pelykh@protonmail.com" },
10
10
  ]
@@ -0,0 +1,14 @@
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='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_version_and_download_driver(browser)
10
+ check_req_and_install_selenium_server()
11
+
12
+
13
+ if __name__ == "__main__":
14
+ install_dev_kit()
@@ -0,0 +1,44 @@
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="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()
@@ -0,0 +1,111 @@
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/{browser}_driver/")
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/{browser}_driver/")
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='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()
@@ -0,0 +1,22 @@
1
+ import os
2
+ import click
3
+
4
+ SELENIUM_SERVER_JAR = "selenium-server/selenium-server-standalone.jar"
5
+
6
+
7
+ @click.command(name='selenium-server', help="Run Selenium Server JAR file")
8
+ @click.option('--port', '-p', type=int, default=4444, help="Port number for the server")
9
+ @click.option('--driver', '-D', multiple=True,
10
+ help="Specify driver options (e.g. -Dwebdriver.chrome.driver=chromedriver)")
11
+ @click.option('--daemon', '-d', is_flag=True, help="Run the server as a daemon")
12
+ def run_selenium_server(port, driver, daemon):
13
+ driver_options = " ".join(driver)
14
+ cmd = f"java -jar {SELENIUM_SERVER_JAR} -port {port} {driver_options}"
15
+ click.echo(f"Running Selenium Server with command:\n {cmd}")
16
+ if daemon:
17
+ cmd += " &"
18
+ os.system(cmd)
19
+
20
+
21
+ if __name__ == "__main__":
22
+ run_selenium_server()
@@ -0,0 +1,38 @@
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 .run_selenium_command import run_selenium_server
9
+
10
+
11
+ @click.group(name="vgl.py")
12
+ def vgl():
13
+ pass
14
+
15
+
16
+ @click.group(name="install", help="Install commands")
17
+ def install_group():
18
+ pass
19
+
20
+
21
+ @click.group(name="run", help="Run commands")
22
+ def run_group():
23
+ pass
24
+
25
+
26
+ run_group.add_command(run_selenium_server)
27
+
28
+
29
+ install_group.add_command(install_webdriver)
30
+ install_group.add_command(install_selenium_standalone)
31
+ install_group.add_command(install_dev_kit)
32
+
33
+ vgl.add_command(install_group)
34
+ vgl.add_command(run_group)
35
+
36
+
37
+ if __name__ == '__main__':
38
+ vgl()
@@ -1,150 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: vigilant_kit
3
- Version: 1.1.1
4
- Summary: Library that makes functional testing with Selenium WebDriver fast and easy.
5
- Project-URL: Homepage, https://github.com/ivpel/vigilant
6
- Project-URL: Bug Tracker, https://github.com/ivpel/vigilant/issues
7
- Author-email: Pelykh Ivan <ivan.pelykh@protonmail.com>
8
- License-File: LICENSE
9
- Keywords: bdd,functional,functional-testing,pytest,selenium,tdd,testing,unittest,webdriver
10
- Requires-Python: >=3.7
11
- Requires-Dist: click
12
- Requires-Dist: python-dotenv
13
- Requires-Dist: requests
14
- Requires-Dist: selenium
15
- Description-Content-Type: text/markdown
16
-
17
- # Vigilant Kit
18
- Vigilant is a set of tools made to help writing and running robust functional tests using Selenium WebDriver.
19
-
20
- ## Why Vigilant?
21
- - It allows you to start writing complex test cases in a minute.
22
- - Simple configuration process (just one `.vigilant.env` file to start)
23
- - Usage is not limited to a single testing framework, it can be used with `unittest`, `pytest` or anything else.
24
- It is up to you.
25
-
26
- **Vigilant** provide you with methods that help write functional tests fast, without spending your time on writing
27
- boilerplate code every time you start new project.
28
-
29
- Methods for **interacting** with WebBrowser (`click`, `scroll_to`, etc.), **assertions** (`see`, `dont_see`, `see_text`
30
- , etc.) **waiting** (`wait_for_element_to_be_visible`, `wait_for_element_to_be_clickable`, etc.)
31
- It is already there, ready to use.
32
-
33
- List of all available [actions](docs/actions.md).
34
-
35
- ### What if you need something that is not covered in this library?
36
-
37
- You still have access to all native `Selenium WebDriver` methods. Despite all functional that library provide -
38
- you can create your own methods or use native `WebDriver` methods and share them on one browser session.
39
-
40
- ## Docs
41
- - [How to install Selenium server & browser drivers](docs/selenium_install.md)
42
- - [Quick start example using `unittest` library](docs/vigilant_unittest.md)
43
- - [Quick start example using `pytest`](docs/vigilant_pytest.md)
44
- - [How to add custom browser options](docs/browser_options.md)
45
- - [Access native Selenium WebDriver methods](docs/native_selenium.md)
46
- - [List of actions](docs/actions.md).
47
-
48
- ## Tutorials
49
- - [Testing ecommerce project using `vigilant-kit` and `pytest`](docs/tutorial_pytest.md)
50
-
51
- ## Install
52
- ```shell
53
- pip install vigilant-kit
54
- ```
55
-
56
- ## Quick start
57
- We will write our first test with `unittest` library. Also make sure that you installed
58
- `vigilant-kit` library.
59
-
60
-
61
- ### Configuration
62
- Configuration can be done through environment variables. Make sure that your Selenium Server is up and running, if not -
63
- [**Install Selenium server**](docs/selenium_install.md)
64
-
65
- Create `.vigilant.env` file with next data:
66
- ```shell
67
- # Selenium host URL
68
- SELENIUM_HOST=http://127.0.0.1:4444/wd/hub
69
-
70
- # Browser which will performing the tests
71
- SELENIUM_BROWSER=firefox
72
-
73
- # The root URL of the application under test.
74
- BASE_URL=http://www.python.org
75
-
76
- # Amount of time (in seconds) that a test will wait while loading a page or waiting for element
77
- WAIT_TIMEOUT=10
78
-
79
- # Log level
80
- LOGGER_LEVEL=INFO
81
- ```
82
-
83
- ### Test
84
- Create file `test_first.py` with same code as below. We will cover 3 simple cases for demo purposes.
85
- ```python
86
- import unittest
87
-
88
- from vigilant.driver.vigilant_driver import VigilantDriver
89
-
90
-
91
- class TestHomePage(unittest.TestCase):
92
-
93
- @classmethod
94
- def setUpClass(cls) -> None:
95
- cls.act = VigilantDriver()
96
-
97
- @classmethod
98
- def tearDownClass(cls) -> None:
99
- cls.act.quit()
100
-
101
- def test_home_page(self):
102
- # Case 1. Go to some page and assert page title
103
- self.act.get_page('/') # Go to root page
104
- self.act.assertions.see_in_title('Python') # Assert that page title contains 'Python' string
105
-
106
- def test_text_block(self):
107
- # Case 2. Scroll to some block and assert visible text
108
- self.act.get_page('/') # Go to root page
109
- self.act.scroll_to('//h2[text()="Success Stories"]') # Scroll to Success Stories block
110
- self.act.assertions.see_text('Success Stories') # Assert that Success Stories string is visible
111
-
112
- def test_search_page(self):
113
- # Case 3. Fill in Search field with search key word, assert result in search result page.
114
- self.act.get_page('/') # Go to root page
115
- self.act.fill_field('//input[@name="q"]', 'python') # Fill search field
116
- self.act.click('//button[@id="submit"]') # Click Search button
117
- self.act.assertions.see_in_url(
118
- '/search/?q=python') # See in URL that we are redirected to search result page
119
- self.act.assertions.see_text('Results') # Assert visible Results text
120
-
121
-
122
- if __name__ == '__main__':
123
- unittest.main()
124
-
125
- ```
126
- Now run our script:
127
- ```shell
128
- python3 test_first.py
129
- ```
130
- ### Results
131
- If you are running your Selenium Server locally - you can see how script interact with browser in real time. But in any
132
- case you should have terminal output similar to this, due to LOGGER_LEVEL=INFO:
133
- ```text
134
- [2022-11-02 16:34:26,452: INFO] Creating remote session.
135
- Command executor: http://127.0.0.1:4444/wd/hub
136
- Browser: firefox
137
- [2022-11-02 16:34:26,452: INFO] Setting default browser options: firefox
138
- [2022-11-02 16:34:27,890: INFO] Getting page: /
139
- [2022-11-02 16:34:33,942: INFO] Assert: see string Python in current page title
140
- [2022-11-02 16:34:33,956: INFO] Scrolling to element: //h2[text()="Success Stories"]
141
- [2022-11-02 16:34:33,956: INFO] Execute JS script: arguments[0].scrollIntoView({block: "center"}) with arguments: <selenium.webdriver.remote.webelement.WebElement (session="3c63a627-1ffd-40ed-b008-78e671d82085", element="703e049a-3ab4-4bd5-814a-bb38dd64864a")>
142
- [2022-11-02 16:34:33,980: INFO] Waiting for element with selector: //input[@name="q"] - to be visible.
143
- [2022-11-02 16:34:33,991: INFO] Filling field: //input[@name="q"] with value: python
144
- [2022-11-02 16:34:34,012: INFO] Waiting for element with selector: //button[@id="submit"] - to be visible.
145
- [2022-11-02 16:34:34,026: INFO] Clicking on element: //button[@id="submit"]
146
- [2022-11-02 16:34:34,411: INFO] Assert: see string /search/?q=python in current page URL
147
- [2022-11-02 16:34:34,434: INFO] Quits the driver and closes every associated window
148
-
149
- ```
150
- Congrats! You successfully created your first testing script using Vigilant Kit :)
@@ -1,41 +0,0 @@
1
- # How to install Selenium Server & browser drivers
2
-
3
- ***
4
- ## Option 1: Run Selenium server + browser driver locally
5
- ### 1. Install Selenium server
6
- Selenium server is simply a jar file. To install (download) it, just run this command in the root directory
7
- of your project or root directory of your tests
8
- ```shell
9
- mkdir selenium-server && cd selenium && wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.6.0/selenium-server-4.6.0.jar && cd -
10
- ```
11
- ### 2. Install browser driver
12
- You will also need to download Selenium driver for the browser where you want to execute the tests. This driver is used
13
- by Selenium server to start the browser of your choice - see following table for the most common browsers:
14
-
15
- | Browser | Driver | Download link |
16
- |---------|---------------------|-----------------------------------------------------------------------------------|
17
- | Firefox | Geckodriver | [Download](https://github.com/mozilla/geckodriver/releases) |
18
- | Chrome | Chromedriver | [Download](https://sites.google.com/a/chromium.org/chromedriver/downloads) |
19
- | MS Edge | Microsoft WebDriver | [Download](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) |
20
-
21
- Download the browser driver and place the binary file (like geckodriver or chromedriver) to the `selenium-server/`
22
- directory (where our selenium standalone server is located).
23
- You can also place the file elsewhere, but then you must pass the path to the Selenium server, but as for me, it is easier
24
- to have server and driver binaries in one place.
25
-
26
- ### 3. Start Selenium server
27
- To start the Selenium server listening for incoming connections simply run:
28
- ```shell
29
- java -jar selenium-server/selenium-server-4.6.0.jar
30
- ```
31
-
32
- ## Option 2: Start Selenium server + browser inside Docker
33
- ***
34
- If you don't want to install and run Selenium server and the browser locally, you can run both of them in a Docker
35
- container. The Selenium project provides many prepared official containers.
36
- For example to start a container with Selenium server and Firefox, simply run:
37
- ```shell
38
- docker run -d -p 4446:4444 -p 7902:7900 --shm-size="2g" selenium/standalone-firefox:4.6.0-20221104
39
- ```
40
-
41
- For more info about available options check official [Docker Selenium](https://github.com/SeleniumHQ/docker-selenium) page.
@@ -1,49 +0,0 @@
1
- # How to start testing with `unittest` library
2
-
3
- If you are not already familiar with the basic concepts of testing, you might want to read this tutorial:
4
- [unittest](https://docs.python.org/3/library/unittest.html)
5
-
6
- Example using `unittest` library.
7
- ```python
8
- import unittest
9
-
10
- from vigilant.driver.vigilant_driver import VigilantDriver
11
- from selenium.webdriver.firefox.options import Options
12
-
13
-
14
- class TestHomePage(unittest.TestCase):
15
-
16
- @classmethod
17
- def setUpClass(cls) -> None:
18
- cls.act = VigilantDriver()
19
-
20
- @classmethod
21
- def tearDownClass(cls) -> None:
22
- cls.act.quit()
23
-
24
- def test_home_page(self):
25
- # Case 1. Go to some page and assert page title
26
- self.act.get_page('/') # Go to root page
27
- self.act.assertions.see_in_title('Python') # Assert that page title contains 'Python' string
28
-
29
- def test_text_block(self):
30
- # Case 2. Scroll to some block and assert visible text
31
- self.act.get_page('/') # Go to root page
32
- self.act.scroll_to('//h2[text()="Success Stories"]') # Scroll to Success Stories block
33
- self.act.assertions.see_text('Success Stories') # Assert that Success Stories string is visible
34
-
35
- def test_search_page(self):
36
- # Case 3. Fill in Search field with search key word, assert result in search result page.
37
- self.act.get_page('/') # Go to root page
38
- self.act.fill_field('//input[@name="q"]', 'python') # Fill search field
39
- self.act.click('//button[@id="submit"]') # Click Search button
40
- self.act.assertions.see_in_url(
41
- '/search/?q=python') # See in URL that we are redirected to search result page
42
- self.act.assertions.see_text('Results') # Assert visible Results text
43
-
44
-
45
- if __name__ == '__main__':
46
- unittest.main()
47
-
48
- ```
49
-
@@ -1,51 +0,0 @@
1
- import os
2
- import sys
3
- import tarfile
4
- import click
5
- from .utils import download_file
6
-
7
-
8
- def install_selenium():
9
- try:
10
- click.echo("Creating directory for Selenium server...", nl=False)
11
- os.mkdir('selenium')
12
- os.chdir('selenium')
13
- click.secho("OK", fg='green')
14
-
15
- # Download Selenium jar file
16
- click.echo("Downloading Selenium jar file...", nl=False)
17
- download_file('https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.7.0/selenium-server-4.7.2.jar')
18
- click.secho("OK", fg='green')
19
-
20
- except FileExistsError:
21
- click.secho("Error", fg='red')
22
- click.secho("Directory 'selenium' already exist!", fg='red')
23
- sys.exit(1)
24
-
25
-
26
- def install_webdriver(browser):
27
- chromedriver = "https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip"
28
- geckodriver = "https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux64.tar.gz"
29
- try:
30
- click.echo(f"Downloading driver for browser {browser}...", nl=False)
31
- if browser == "chrome":
32
- download_file(chromedriver)
33
- elif browser == "firefox":
34
- download_file(geckodriver)
35
- file = tarfile.open('geckodriver-v0.32.0-linux64.tar.gz')
36
- file.extractall('.')
37
-
38
- click.secho("OK", fg='green')
39
- except FileNotFoundError as e:
40
- click.secho("Error", fg='red')
41
- click.echo(e)
42
-
43
-
44
- @click.command(name='install:dev-server')
45
- @click.option('--browser', default='firefox', help='Browser which will be used for testing.')
46
- def install_selenium_dev_server(browser):
47
- install_selenium()
48
- install_webdriver(browser)
49
- click.secho("Installation complete.", fg='green')
50
- click.secho(f"INFO: Before running your Selenium Server locally, make sure that your {browser} browser is updated "
51
- f"to the last stable version!")
@@ -1,11 +0,0 @@
1
- import requests
2
-
3
-
4
- def download_file(url):
5
- local_filename = url.split('/')[-1]
6
- with requests.get(url, stream=True) as r:
7
- r.raise_for_status()
8
- with open(local_filename, 'wb') as f:
9
- for chunk in r.iter_content(chunk_size=8192):
10
- f.write(chunk)
11
- return local_filename
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- import click
4
- from .local_dev import install_selenium_dev_server
5
-
6
-
7
- @click.group(name="vgl.py")
8
- def vgl():
9
- pass
10
-
11
-
12
- vgl.add_command(install_selenium_dev_server)
13
- vgl()
File without changes
File without changes
File without changes