A little load container GPT and I came up with. https://auzietek.com

Auzie Morgan b11c4da106 Few tweaks on the example test 2 years ago
experimental 5c1f688302 Some cleanup 2 years ago
selenium_bot 5c1f688302 Some cleanup 2 years ago
Dockerfile 66b7bd185d Confilict, cleaning up a few updates including headless mode fixes 2 years ago
Dockerfile-merge 66b7bd185d Confilict, cleaning up a few updates including headless mode fixes 2 years ago
Readme.md 66b7bd185d Confilict, cleaning up a few updates including headless mode fixes 2 years ago
Readme.md.last 66b7bd185d Confilict, cleaning up a few updates including headless mode fixes 2 years ago
build.sh c2bcb93ab8 Shifting to running python exported scripts for selenium_bot Dockerfile and scripts 2 years ago
requirements.txt 21f16fcd58 A minor update to requrements and readme. 2 years ago
run.sh 90a629c43e Confilict, cleaning up a few updates including headless mode fixes 2 years ago
selenium_bot-headless.py 94967779b7 A few updates including headles for the docker container 2 years ago
selenium_bot.py 997eaaf140 Various cahnges to simplify running on a desktop 2 years ago
test_quick.py b11c4da106 Few tweaks on the example test 2 years ago

Readme.md

Selenium Bot

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.

Setup

Selenium Bot requires Python 3 and Google Chrome with chromedriver installed. The following steps explain how to install these requirements on CentOS 7:

  1. Install Python 3 and pip:

    sudo yum -y install epel-release
    sudo yum -y install python36 python36-pip
    
  2. Install Google Chrome:

    sudo curl https://intoli.com/install-google-chrome.sh | bash
    
  3. 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
    
  4. Checkout the latest version:

    git clone https://dtlab.auzietek.com/auzieman/selenium_bot.git
    cd selenium-bot
    pip3 install -r requirements.txt
    

Configuration

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

Exporting selenium pytest scripts

  1. Record your test in Selenium IDE
  2. Export the test as a Python/pytest file
  3. Open the exported file in a text editor
  4. 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)
    
  5. 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.

Usage

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.

Output

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 executed
  • fork: The fork number that executed the script
  • start_time: The start time of the test run, in Unix timestamp format
  • end_time: The end time of the test run, in Unix timestamp format
  • exit_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
  • `