Execute Scripts in Command Prompt or Terminal using Python Appium Framework
Run Python Appium test scripts from the Command Prompt or Terminal on Windows or macOS, and generate Allure reports for your mobile site test automation results.
Prerequisites
Ensure your environment is set up for script execution on Windows. For detailed setup steps, refer to Setting up and Connecting to a Mobile Emulator. The Appium server must be running before executing scripts.
Executing the scripts
To run scripts on a Windows computer, use the Command Prompt. Navigate to the folder where the Feature File is located, and open the Command Prompt from this location.
The script execution command must resemble the following example:
behave -f allure_behave.formatter:AllureFormatter -o D:\projects1\Mobile_App\Android\mmt\Python_APPium_Project133425488530054187\features\temp -f pretty "D:\projects1\Mobile_App\Android\mmt\Python_APPium_Project133425488530054187\features" --tags=@test001
The previous command instructs Behave to run tests from the specified Feature File, generate Allure reports, and include only scenarios with the @test001 tag. The temporary Allure report files will be stored in the specified output directory. This command is added in the readme file and can be used to generate Allure reports. Use the following command:
allure generate --single-file <json_file_path> -o <output_path>
The following table represents command-line arguments:
| Key | Description |
|---|---|
behave | This is the command to run Behave, which is a popular Python testing library for behavior-driven development (BDD). |
-f allure_behave.formatter:AllureFormatter | Specifies the formatter for the output. In this case, it uses the AllureFormatter to generate reports in the Allure format — a flexible and extensible test reporting framework. |
-o D:\projects1\Mobile_App\Android\mmt\Python_APPium_Project133425488530054187\features\temp | This flag specifies the output directory where the Allure report files will be generated. In this case, it's set to a temporary directory. |
-f pretty | This flag specifies that the output must also be in a human-readable format (pretty format). |
"D:\projects1\Mobile_App\Android\mmt\Python_APPium_Project133425488530054187\features" | This is the path to the directory where your Behave Feature File is located. Behave will look for feature files in this directory. |
--tags=@test001 | This flag filters the execution of scenarios based on the specified tags. In this case, it runs scenarios with the @test001 tag. Tags in Behave are used to categorize and filter scenarios. |
Alternatively, if the report isn't generated despite executing the previous commands, then perform the following to generate reports using Mono packages:
Generate Reports Using Mono
- Download the Mono package from the official website: Mono-project.com.
- Follow the on-screen instructions in the installer to complete the installation.
- To verify the installed Mono version, open the Command Prompt or Terminal and run the following command:
mono --version
If you are running the script on an iOS device to generate reports, open a terminal and run the commands specified previously, replacing Command Prompt with Terminal.