vigilant-kit 1.1.1__py3-none-any.whl → 1.2.1__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.
- vgl_cli/install_dev_kit_command.py +14 -0
- vgl_cli/install_standalone_command.py +44 -0
- vgl_cli/install_webdriver_command.py +111 -0
- vgl_cli/run_selenium_command.py +22 -0
- vgl_cli/vgl.py +28 -3
- vigilant_kit-1.2.1.dist-info/METADATA +59 -0
- {vigilant_kit-1.1.1.dist-info → vigilant_kit-1.2.1.dist-info}/RECORD +10 -9
- {vigilant_kit-1.1.1.dist-info → vigilant_kit-1.2.1.dist-info}/WHEEL +1 -1
- vgl_cli/__init__.py +0 -0
- vgl_cli/local_dev.py +0 -51
- vgl_cli/utils.py +0 -11
- vigilant_kit-1.1.1.dist-info/METADATA +0 -150
- {vigilant_kit-1.1.1.dist-info → vigilant_kit-1.2.1.dist-info}/entry_points.txt +0 -0
- {vigilant_kit-1.1.1.dist-info → vigilant_kit-1.2.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -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()
|
vgl_cli/vgl.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
|
|
3
3
|
import click
|
|
4
|
-
from .
|
|
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
|
|
5
9
|
|
|
6
10
|
|
|
7
11
|
@click.group(name="vgl.py")
|
|
@@ -9,5 +13,26 @@ def vgl():
|
|
|
9
13
|
pass
|
|
10
14
|
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
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()
|
|
@@ -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
|
+
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
vgl_cli/
|
|
2
|
-
vgl_cli/
|
|
3
|
-
vgl_cli/
|
|
4
|
-
vgl_cli/
|
|
1
|
+
vgl_cli/install_dev_kit_command.py,sha256=n-sZHneVmvZ90c1cyGUvPg5CF-7S3qEzxVvq8SgvjIk,539
|
|
2
|
+
vgl_cli/install_standalone_command.py,sha256=lRVYEEJAO6KlT46Fh5rdG_I2Ve0Mhu6S-ar0y_fCQj0,1439
|
|
3
|
+
vgl_cli/install_webdriver_command.py,sha256=4bns1zSX7ShpzlBvLNg4mgdYMNhCRg3a1JNhKQeyEn4,5058
|
|
4
|
+
vgl_cli/run_selenium_command.py,sha256=ZVIbhEsWecRxtVLKcCRWcElyhxdhxZrqlwiWfOHhMyg,815
|
|
5
|
+
vgl_cli/vgl.py,sha256=KRN2MLaBBTGGp1vs8wr4kBdG7kVYlQ13xi-VfrZjRQc,767
|
|
5
6
|
vigilant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
7
|
vigilant/logger.py,sha256=euYrqEDMEWNo9Eak31_4eTQEVzLZBwR8YiArhOtI9uQ,191
|
|
7
8
|
vigilant/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -11,8 +12,8 @@ vigilant/actions/vigilant_actions.py,sha256=2OwnuKJHU4MUq4atLq49FbRQPUeE0mCXs0ps
|
|
|
11
12
|
vigilant/actions/waiter.py,sha256=_sgL-R-Kp3I-DP27Sd_OAL8erjvhLvHLWFURXNX3V2w,3298
|
|
12
13
|
vigilant/driver/__init__.py,sha256=brf9Jk8uq_TNomOKu2k_0u9mAuimLf9bxF0XHafaZGs,207
|
|
13
14
|
vigilant/driver/vigilant_driver.py,sha256=rw5CfWfBWOIFPgnkmxTi7cSbrrxLtDtRlxg2FMfyEVw,3398
|
|
14
|
-
vigilant_kit-1.
|
|
15
|
-
vigilant_kit-1.
|
|
16
|
-
vigilant_kit-1.
|
|
17
|
-
vigilant_kit-1.
|
|
18
|
-
vigilant_kit-1.
|
|
15
|
+
vigilant_kit-1.2.1.dist-info/METADATA,sha256=sOPWPkskC1HySS4nO2Nh-lPD9s4GlYFPAHaYgWSKvQg,2566
|
|
16
|
+
vigilant_kit-1.2.1.dist-info/WHEEL,sha256=9MIigYJ7D5sOqAPqr0-o6tSMY_nQ7c6kvtvyeUB99YQ,87
|
|
17
|
+
vigilant_kit-1.2.1.dist-info/entry_points.txt,sha256=c_azSnuBSdtgwdPlioaG0n2gZOEhuPIzL9VQ8DeKTow,40
|
|
18
|
+
vigilant_kit-1.2.1.dist-info/licenses/LICENSE,sha256=VQoL58PKrdEeZx2K4hXS7O6w4O_DMBB0XFE-GjK1CMo,35125
|
|
19
|
+
vigilant_kit-1.2.1.dist-info/RECORD,,
|
vgl_cli/__init__.py
DELETED
|
File without changes
|
vgl_cli/local_dev.py
DELETED
|
@@ -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!")
|
vgl_cli/utils.py
DELETED
|
@@ -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,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 :)
|
|
File without changes
|
|
File without changes
|