pytest optimization framework - will be extremely screenshots added to the allure report

Pain point analysis:

In doing allure custom of the time, add on accessories this piece, we are ready we can add accessories in the code, here with pictures, can be achieved by the following method

allure.attach (File, 'Image Title ' , allure.attachment_type.PNG)

What if we execute allure test report test case generation, able to capture abnormal test case of failure or abnormal also automatically added to the allure of the report, would it not be more perfect?

Thinking question:

1. Use cases executed, abnormal images are shot at OutPus catalog, how to talk to patients associated with?

2. I am going to add to the allure reports?

3. Abnormal shots so much, how do I add pictures to capture the relevant exception under the corresponding use cases do?

4. Taking into account the order of execution of the code yet?

5. Screenshot from where generated, what is called abnormal method will generate screenshot picture?

......

I took the above questions, and so on, slowly groping, summed up the three points are important:

  • Code execution order
  • Exception is generated from the theme driver.save_screenshot (file_name) method
  • Screenshot abnormal approach is encapsulated in the module basepage

Solution:

Because the execution of test cases, the test will call PageObjects step inside the method, and the method PageObjects which in turn calls the method is a series of action basepage inside, while the action method inside the package and call a method to capture a screen shot, so we just need to Add the allure.attach () method to method screenshots captured inside it.

Abnormal opening the screenshot, we can see the specific content of the picture:

code show as below:

    DEF save_screenshot (Self, img_doc):
         '' ' 
        page screen shot saved screenshot 
        : param img_doc: Screenshot Description 
        : return: 
        ' '' 
        file_name = OUTPUTS_DIR + " \\ _ {{}} PNG. " .format (datetime.strftime (datetime .now (), " % D% the Y% m% H% m% S " ), img_doc) 
        self.driver.save_screenshot (file_name) 
        with Open (file_name, MODE = ' RB ' ) AS F: 
            File = reached, f.read () 
        allure.attach (File, ' abnormal shots ' , allure.attachment_type.PNG)
        case_logger.info ( "Page screenshot files are saved in: {} " .format (file_name))

 

Guess you like

Origin www.cnblogs.com/xiaogongjin/p/11705914.html