18. Unittest Allure Report - naveens33/selenium_python GitHub Wiki
Steps to generate Allure report in Unittest
1. Install Allure
- To install Allure check the below link
- If scoop is not available. check the below link to install scoop
Scoop- A command-line installer for Windows
2. Create Python Unit Test Case Class
- Define test functions in the class
3. Import allure
- Install allure module
- Import below modules
import allure
4. Decorate class with allure decorators
Allure will take the name of the Class and put that as the Test Suite for the tests within it. It will also take the name of the test method and report it as the test case. So make sure to use descriptive names there. If needed, we can map the Class to a User Story or Feature using the following decorators
@allure.story('Story/Requirement Name')
@allure.feature('Feature Name')
5. Decorate test with allure decorators
@allure.testcase("Test Case name")
6.1. Add steps using with clause
def test_login(self):
with allure.step("Open application"):
driver=webdriver.Chrome(executable_path=r'..\chromedriver.exe')
driver.maximize_window()
driver.get("http://zero.webappsecurity.com")
with allure.step("Verify Page Title"):
assert "Zero - Personal Banking - Loans - Credit Cards" == driver.title
Or
6.2. Add steps using decorator
def test_login(self):
self.open_application()
self.verify_page_title()
@allure.step("Open application")
def open_application(self):
self.driver = webdriver.Chrome(executable_path=r'..\chromedriver.exe')
self.driver.maximize_window()
self.driver.get("http://zero.webappsecurity.com")
@allure.step("Verify Page Title")
def verify_page_title(self):
assert "Zero - Personal Banking - Loans - Credit Cards" == self.driver.title
7. Run the test
While running the test and specify a path for the report to be saved
python -m pytest allurereportexample.py --alluredir ./results
This will run the test in allurereportexample.py and create an Allure Directory name “results” to store the report
8. Get/Show Allure report
allure serve ./results/
This will open default browser and shows the report