Test automation beginner’s notes from the Android APP end, write wrong place all your comments well before the release of python + appium test automation pytest + allure test report (1) of this article because the part is wrong, after modification and supplement to release now

Allure installation

1. Pytest and Allure plugins installed

pip install allure-pytest
pip install pytest
Copy the code

2. Allure

https://docs.qameta.io/allure/#_about
Copy the code

3. Allure

A. spoon install allure b

  • [github.com/allure-fram…]

  • Allure2 is a zip that needs to be unzipped to your own directory (either in your project’s test case or python installation directory), where you can find the files yourself.
  • Open the allure2 directory, find the bin directory, copy the bin file directory, and configure environment variables. The purpose of setting environment variables is to enable the system to run Allure2 in any directory.
  • Environment variable Settings :(desktop — my computer — right click properties — advanced system configuration — environment variables — system variables — Path — edit environment variables — add the directory Path we copied above to the environment variable)

  • Once configured, open the CMD terminal, type Allure, and the following help document appears to indicate that the configuration is successful.

If a later version is available, use the latest version

Generate a test report in JSON format

Operating environment:

  • Equipment: U4AIUKFAL7W4MJLR
  • Test APP: Weibo APP(V10.12.0)Andriod version
  • Test function: Log in using the account and password

Method 1: Generate a TEST report in JSON format on the terminal

Terminal Enter the following content to run

Pytest run py file --alluredir= Address where the test report is stored Example: Pytest add_weibo_test.py --alluredir=.. /report/jsonCopy the code

Run the test case and generate one or more test reports in JSON or XML format at the location where the test reports are stored

Method 2: Configure Additional Arguments in the test case to generate the JSON test report

1. Select the test case you want to Run and right-click Create Run Configuration:” Test case file name “.

2. In the Additional Arguments text box, enter – – allureDir = The location where the generated JSON test report is stored

3. After setting, click APPLY→OK to run the test file in the test function

After running, one or more test reports in JSON or XML format will be generated in the location where the test reports are stored

3. The test report is converted from JSON format to HTML format

Convert at the terminal

1. After the test case runs and generates a test report in JSON format, run the terminal command.

Allure generate./report/ -o./report/ HTML --clean./report/: indicates the location of the file to perform the conversion, The file to be converted is saved in the report folder./ Report/HTML: indicates the location of the CONVERTED HTML file, that is, the HTML file is saved in the report folder. -- Clean: indicates that the previous test report is cleared, because an error will be reported if the same test report is generated repeatedlyCopy the code

Note: In Terminal, you can use CD to go back to the previous level or enter other files

2. After the execution, an HTML file will be generated in the Report folder and an index. HTML file will be generated in the HTML directory, which is the visual report, as shown in the figure below

3. Open the HTML file, right-click the index. HTML file, choose Open in Broswer, and choose Chrome

4. The test report picture after Google Browser is opened is shown as the following figure:

4. Allure

1. @allure. Feature: Used to describe the requirements of the product being tested

2. @allure. Story: Used to describe feature’s user story, i.e. testing requirements, as a parent to Feature

3. @allure. Title: User description test case title, default to use case name not set

4. @allure. Description: Used for some additional description of the test case

5. @allure. Step: Used to output some generic functions as test steps to the report, where this function is called to output steps to the report

  • Step: Used to describe the test steps, which will be output in the report
  • Allure. Attach: Used to feed a test report with additional information, usually test data, screenshots, etc

The code is as follows:

Test case for logging in with mobile phone account password
import allure
import pytest
from common.init import AppStart

@allure.feature("This is the test feature")
class TestAccountPwd:
    def setup_class(self) :
        self.account_login_page = AppStart.start().enter_account_login()

    @allure.story("story_one")
    @allure.title("title_one")
    def test_one(self) :
        with allure.step("Step -- Enter the account number"):
            allure.attach("123123231321313"."Account")
            account = "123123231321313"
        with allure.step("Step -- Enter your password"):
            pwd = "asdfgh"
            self.account_login_page.input_account_pwd(account, pwd)
        with allure.step("Step - assertion"):
            allure.attach("There is something wrong with the mobile phone format. If it is not a Chinese mainland mobile phone number, please click on international mobile login."."Desired outcome")
            assert self.account_login_page.get_bounced_context() == "There is something wrong with the mobile phone format. If it is not a Chinese mainland mobile phone number, please click on international mobile login."
            print("\ naccount value.", account, "\ NPWD:", pwd)

    @allure.story("story_two")
    @allure.title("title_two")
    @allure.step("This is test step.")
    def test_two(self) :
        account = "w124hhh77"
        pwd = "asdfg"
        self.account_login_page.input_account_pwd(account, pwd)
        assert self.account_login_page.get_bounced_context() == "You have not registered on Weibo, do you want to register now?"
        print("\ naccount value.", account, "\ NPWD:", pwd)

    @allure.story("story_three")
    @allure.title("title_three")
    def test_three(self) :
        account = "hhhhhhhhh"
        pwd = "asdfg"
        self.account_login_page.input_account_pwd(account, pwd)
        assert self.account_login_page.get_bounced_context() == "You have not registered on Weibo, do you want to register now?"
        print("\ naccount value.", account, "\ NPWD:", pwd)

    @allure.story("story_four")
    @allure.title("title_four")
    @allure.description("description")
    def test_four(self) :
        account = "15059941156"
        pwd = "123123"
        self.account_login_page.input_account_pwd(account, pwd)
        assert self.account_login_page.get_account_pwd_tips() == "Wrong account or password"
        print("\ naccount value.", account, "\ NPWD:", pwd)

    def teardown_class(self) :
        AppStart.quit()

if __name__ == '__main__':
    pytest.main(["account_pwd_test.py"])
Copy the code

[email protected], @allure. Story, @allure. Title Results:

[email protected] Results are as follows

[email protected] results are as follows:

4. With allure. Step and allure.