Setting Up and Executing Selenium Scripts in Command Prompt Using Python
Set up and execute Python Selenium test scripts from the Windows Command Prompt using Behave, and generate Allure reports.
Execute generated Python Selenium scripts locally from the Windows Command Prompt, then review the results in an Allure report.
Prerequisites
Before executing scripts, ensure that Python and Selenium are configured on your machine.
To configure Python and Selenium, refer to the article Installation Steps for Python Selenium Framework.
Executing Selenium Scripts in Command Prompt on Windows Operating System
Perform the following:
Download and extract the script to your local folder.
Navigate to the generated script folder in algoQA and click the download icon. Extract the downloaded script to a local folder on your machine, then navigate to that folder.
In the folder navigation bar, type 'cmd ' and press 'Enter' to view the Command Prompt screen.
This opens a Command Prompt window already navigated to the script folder, so you can run Behave commands directly.
Run the following command to execute the script:
behave -f allure_behave.formatter:AllureFormatter -o D:\projects1\Web_App\Application\mmt\Python_Selenium_Project133425488530054187\features\temp -f pretty D:\projects1\Web_App\Application\mmt\Python_Selenium_Project133425488530054187\features --tags=@test001
This command instructs Behave to run tests from the specified feature file, generate Allure reports, and include only scenarios tagged with @test001. Temporary Allure report files are stored in the specified output directory.
The following command, also available in the readme file, generates a single-file Allure report: allure generate --single-file <json file path> -o <output path>
The following table describes each command-line argument:
| Key | Description |
|---|---|
behave | Runs Behave, a Python testing library for behavior-driven development. |
-f allure_behave.formatter:AllureFormatter -o | Selects the Allure formatter and specifies the report output option. |
D:\projects1\Web_App\Android\mmt\Python_Selenium_Project133425488530054187\features\temp | Specifies the temporary directory for generated Allure report files. |
-f pretty: | Displays the output in a human-readable format. |
"D:\projects1\Web_App\Android\mmt\Python_Selenium_Project133425488530054187\features" | Specifies the directory containing the Behave feature files. |
--tags=@test001 | Runs only scenarios tagged with @test001. |
You can view the respective report.
After the script executes successfully, navigate to the reports folder to view the generated Allure report. The report includes test results, step-by-step logs, and screenshots for verification steps.