1

I am using pytest and allure-pytest to automate my web app test cases. My test case has below format:

import allure
from selenium import webdriver
class Test_Abc():

    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    options.add_argument("--foreground")
    options.add_argument('disable-infobars')
    options.add_argument("--disable-extensions")
    driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=options.to_capabilities())

    def test_check_reapply_page_001(self):
        allure.attach(self.driver.get_screenshot_as_png(), "Failed", allure.attachment_type.PNG)

When running test case, an error return at the allure.attach command:

AttributeError: 'module' object has no attribute 'attachment_type'

Please advise me how to overcome this error?

Libs:

  • allure-pytest==2.5.4

  • allure-python-commons==2.5.4

  • pytest==3.7.0

  • selenium==3.141.0

Bill P
  • 3,622
  • 10
  • 20
  • 32
Tai Tran
  • 11
  • 1
  • 3
  • This answer https://stackoverflow.com/a/29929416/494134 says you should be using `allure.constants.AttachmentType.PNG`. Why are you using `allure.attachment_type.PNG`? – John Gordon Dec 21 '18 at 02:48
  • Thanks @JohnGordon, I am using Allure 2. I tried with suggested codes of Tuan Chau: https://stackoverflow.com/a/47028328/7749257 ` But the below error occurs: Hint: make sure your test modules/packages have valid Python names. Traceback: src/tests/abstract_test.py:9: in from src.pages.abstract_page import AbstractPage src/pages/abstract_page.py:8: in from allure_commons.types import AttachmentType E ImportError: No module named allure_commons.types – Tai Tran Dec 21 '18 at 03:23
  • `import allure from selenium import webdriver class Test_Abc(): options = webdriver.ChromeOptions() options.add_argument("--no-sandbox") options.add_argument("--foreground") options.add_argument('disable-infobars') options.add_argument("--disable-extensions") driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=options.to_capabilities()) def test_check_reapply_page_001(self): allure.attach(self.driver.get_screenshot_as_png(), "Failed", allure.attachment_type.PNG)` The error occurs with above code – Tai Tran Dec 21 '18 at 04:59

1 Answers1

0

Try to use the type allure module attachment type constant, which is an Enum with extension attribute defined.

For allure:

from allure.constants import AttachmentType

allure.attach('screenshot', driver.get_screenshot_as_png(), type=AttachmentType.PNG)

For allure 2:

from allure_commons.types import AttachmentType

allure.attach(driver.get_screenshot_as_png(), name="Screenshot", attachment_type=AttachmentType.PNG)

Edit:

Have a look at allures own attachment tests. E.g:

 allure.attach(xml_body, attachment_type=allure.attachment_type.XML)
zerocewl
  • 11,401
  • 6
  • 27
  • 53
  • Thanks for your help. I resolved this issue by removing allure-python-commons since this lib is conflict with others. – Tai Tran Mar 11 '19 at 10:22