A little load container GPT and I came up with. https://auzietek.com
|
2 years ago | |
---|---|---|
experimental | 2 years ago | |
selenium_bot | 2 years ago | |
Dockerfile | 2 years ago | |
Dockerfile-merge | 2 years ago | |
Readme.md | 2 years ago | |
Readme.md.last | 2 years ago | |
build.sh | 2 years ago | |
requirements.txt | 2 years ago | |
run.sh | 2 years ago | |
selenium_bot-headless.py | 2 years ago | |
selenium_bot.py | 2 years ago | |
test_quick.py | 2 years ago |
Selenium Bot is a Python script that runs Selenium tests in parallel using multiple forks. It monitors a directory for Python files ending in .py
and executes them as tests. The number of forks and the interval between test runs are configurable through environment variables.
Selenium Bot requires Python 3 and Google Chrome with chromedriver installed. The following steps explain how to install these requirements on CentOS 7:
Install Python 3 and pip:
sudo yum -y install epel-release
sudo yum -y install python36 python36-pip
Install Google Chrome:
sudo curl https://intoli.com/install-google-chrome.sh | bash
Install chromedriver:
sudo yum -y install unzip
wget https://chromedriver.storage.googleapis.com/88.0.4324.96/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
Checkout the latest version:
git clone https://dtlab.auzietek.com/auzieman/selenium_bot.git
cd selenium-bot
pip3 install -r requirements.txt
Selenium Bot is configured through environment variables. The following variables are available:
SELENIUM_SCRIPT_DIR
: The directory to monitor for Selenium tests (default: /selenium_bot/
)SELENIUM_SCRIPT_INTERVAL
: The interval between test runs, in seconds (default: 10
)SELENIUM_SCRIPT_FORKS
: The number of forks to use for each test (default: 1
)CHROMEDRIVER_PATH
: The path to the chromedriver binary (default: /usr/bin/chromedriver
)To set an environment variable, use the export
command. For example, to set the SELENIUM_SCRIPT_FORKS
variable to 2, use the following command:
export SELENIUM_SCRIPT_FORKS=2
Modify the file to include the necessary webdriver options, such as running headless or no-sandbox mode. 5. You can do this by adding the following lines of code to the setup_method function:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
self.driver = webdriver.Chrome(options=chrome_options)
Save the modified file to a working folder path. For example, /selenium_bot/tests.
When exporting a test from Selenium IDE, it's important to make sure that the test name and the name of the first test step match exactly, and to modify them if necessary to ensure they match.
To start Selenium Bot, simply run the selenium_bot.py
script:
python3 selenium_bot.py
This will monitor the directory specified by the SELENIUM_SCRIPT_DIR
variable for Python files ending in .py
, and execute them as tests using multiple forks.
Selenium Bot outputs the results of each test run as JSON. By default, the output is printed to the console. You can redirect the output to a file using the >
operator. For example, to save the output to a file named output.json
, use the following command:
python3 selenium_bot.py > output.json
======================== 1 passed, 2 warnings in 3.99s =========================
. [100%]
=============================== warnings summary ===============================
../../../../../usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:428
/usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:428: PytestCacheWarning: could not create cache path /selenium_bot/.pytest_cache/v/cache/nodeids
config.cache.set("cache/nodeids", sorted(self.cached_nodeids))
../../../../../usr/lib/python3.10/site-packages/_pytest/stepwise.py:49
/usr/lib/python3.10/site-packages/_pytest/stepwise.py:49: PytestCacheWarning: could not create cache path /selenium_bot/.pytest_cache/v/cache/stepwise
session.config.cache.set(STEPWISE_CACHE_DIR, [])
-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 1 passed, 2 warnings in 4.19s =========================
. [100%]
=============================== warnings summary ===============================
../../../../../usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:428
/usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:428: PytestCacheWarning: could not create cache path /selenium_bot/.pytest_cache/v/cache/nodeids
config.cache.set("cache/nodeids", sorted(self.cached_nodeids))
../../../../../usr/lib/python3.10/site-packages/_pytest/stepwise.py:49
/usr/lib/python3.10/site-packages/_pytest/stepwise.py:49: PytestCacheWarning: could not create cache path /selenium_bot/.pytest_cache/v/cache/stepwise
session.config.cache.set(STEPWISE_CACHE_DIR, [])
-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 1 passed, 2 warnings in 4.57s =========================
[
{
"script": "test_redminequick.py",
"fork": 1,
"start_time": 1678743147.718879,
"end_time": 1678743157.756006,
"exit_status": "ERROR",
"pid": 528780,
"current_time": null
},
{
"script": "test_quick.py",
"fork": 1,
"start_time": 1678743147.71961,
"end_time": 1678743157.775154,
"exit_status": "ERROR",
"pid": 528781,
"current_time": null
},
{
"script": "test_lightweight.py",
"fork": 1,
"start_time": 1678743147.720332,
"end_time": 1678743157.791993,
"exit_status": "ERROR",
"pid": 528782,
"current_time": null
}
]
The output contains the following fields:
script
: The name of the script that was executedfork
: The fork number that executed the scriptstart_time
: The start time of the test run, in Unix timestamp formatend_time
: The end time of the test run, in Unix timestamp formatexit_status
: The exit status of the test run. Possible values are S
(success), R
(running), T
(stopped by job control signal), D
(stopped by debugger), X
(terminated by signal), Z
(defunct or zombie process), F
(failed, return code not zero), or ERROR
(an error occurred while checking the status)pid
: The process ID of the test run