behave-contrib / behave-html-formatter

HTML formatter for Behave
https://pypi.org/project/behave-html-formatter/
GNU General Public License v3.0
7 stars 10 forks source link

Formatter is unknown #36

Open CojanuAlin opened 1 year ago

CojanuAlin commented 1 year ago

I did all the steps with behave install, html formatter install and the behave.ini. But I get the error:

usage: behave [options] [ [DIR|FILE|FILE:LINE] ]+
behave: error: format=html is unknown
bittner commented 1 year ago

I recommend you specify the exact steps you performed verbatim, and the related (error) output. This makes it easier to help you.

Instructions on configuring and running behave with formatters are included in the official Behave docs.

CojanuAlin commented 1 year ago

I recommend you specify the exact steps you performed verbatim, and the related (error) output. This makes it easier to help you.

Instructions on configuring and running behave with formatters are included in [the official Behave docs](https://behave.readthedocs.io/en/latest/formatters.html#more

Pycharm -> New Project:

But when I run behave -f html -o behave-report.html I straight receive the error:

usage: behave [options] [ [DIR|FILE|FILE:LINE] ]+
behave: error: format=html is unknown
bittner commented 1 year ago

I have created the behave.ini file

What is the content of the behave.ini file?

I run in terminal "behave" command. I failed some steps, they are shown in terminal.

This may be relevant. Include the terminal output verbatim to make it easier to help you.

CojanuAlin commented 1 year ago

I have created the behave.ini file

What is the content of the behave.ini file?

[behave.formatters]
html = behave_html_formatter:HTMLFormatter 

I run in terminal "behave" command. I failed some steps, they are shown in terminal.

This may be relevant. Include the terminal output verbatim to make it easier to help you.

Is not a work done. I need to do some tweaks. Is more like a copy from someone and I will change it to be done properly. But here it is:

Feature: Check if you can login on the Form Authentication page # login_page.feature:1

  Scenario: Check if you can Log In with correct credentials                 # login_page.feature:11
    Given I am on the the-internet.herokuapp.com/login page                  # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert correct username and correct password                      # None
    And I click the login button                                             # None
    Then I can login into the application and redireceted to the secure page # None

  Scenario: Check if you can Log In with incorect username and correct password         # login_page.feature:17
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert incorrect username and correct password                               # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your username is invalid!\n× # None

  Scenario: Check if you can Log In with incorect username and incorrect password       # login_page.feature:23
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert incorrect username and incorrect password                             # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your username is invalid!\n× # None

  Scenario: Check if you can Log In with corect username and incorrect password         # login_page.feature:29
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert correct username and incorrect password                               # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your password is invalid!\n× # None

  Scenario: Check if you can Log In with no username and correct password               # login_page.feature:35
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert no username and correct password                                      # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your username is invalid!\n× # None

  Scenario: Check if you can Log In with corect username and no password                # login_page.feature:41
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert correct username and no password                                      # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your password is invalid!\n× # None

  Scenario: Check if you can Log In with no username and no password                    # login_page.feature:47
    Given I am on the the-internet.herokuapp.com/login page                             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I insert no username and no password                                           # None
    When I click the login button                                                       # None
    Then I cannot login into the application and I receive Your username is invalid!\n× # None

Feature: Check the main page clickable links # main_page.feature:1

  Scenario: Check if you find A/B Testing clickable link and go to the page  # main_page.feature:8
    Given I am on the-internet.herokuapp page                                # steps/main_page_steps.py:3
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\main_page_steps.py", line 5, in step_impl
          context.main_page_object.navigate_to_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'main_page_object'

    When I find the A/B testing link and click on it                         # None
    Then I am redirected to the A/B testing page                             # None

  Scenario: Check if you find Broken Images clickable link and go to the page  # main_page.feature:13
    Given I am on the-internet.herokuapp page                                  # steps/main_page_steps.py:3
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\main_page_steps.py", line 5, in step_impl
          context.main_page_object.navigate_to_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'main_page_object'

    When I find the Broken Images link and click on it                         # None
    Then I am redirected to the Broken Images page                             # None

  Scenario: Check if you find Dynamic Controls clickable link and go to the page  # main_page.feature:18
    Given I am on the-internet.herokuapp page                                     # steps/main_page_steps.py:3
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\main_page_steps.py", line 5, in step_impl
          context.main_page_object.navigate_to_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'main_page_object'

    When I find the Dynamic Controls link and click on it                         # None
    Then I am redirected to the Dynamic Controls page                             # None

  Scenario: Check if you find Form Authentications clickable link and go to the page  # main_page.feature:23
    Given I am on the-internet.herokuapp page                                         # steps/main_page_steps.py:3
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\main_page_steps.py", line 5, in step_impl
          context.main_page_object.navigate_to_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'main_page_object'

    When I find the Form Authentication link and click on it                          # None
    Then I am redirected to the Form Authentication page                              # None

Feature: Check if we are on the right page an we could Log out # secured_login.feature:1

  Scenario: Check if the Log In message is displayed                    # secured_login.feature:6
    Given I am on the the-internet.herokuapp.com/login page             # steps/login_page_steps.py:4
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\login_page_steps.py", line 6, in step_impl
          context.login_page_object.navigate_to_login_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'login_page_object'

    When I complete with the correct credentials and I press Log In     # None
    Then I am redirected to the secure page and a valid message appears # None

  Scenario: Check if I press the Log Out button redirects me to previous page  # secured_login.feature:11
    Given I am on the the-internet.herokuapp.com/secure page                   # steps/secured_login_steps.py:14
      Traceback (most recent call last):
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\model.py", line 1329, in run
          match.run(runner.context)
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\matchers.py", line 98, in run
          self.func(context, *args, **kwargs)
        File "steps\secured_login_steps.py", line 16, in step_impl
          context.secured_login_object.navigate_to_secured_page()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\nick_\Documents\Alin\Sesiunea12\Tema\venv\Lib\site-packages\behave\runner.py", line 321, in __getattr__
          raise AttributeError(msg)
      AttributeError: 'Context' object has no attribute 'secured_login_object'

    When I press the Log Out button                                            # None
    Then I am redirected to Log In page                                        # None

Failing scenarios:
  login_page.feature:11  Check if you can Log In with correct credentials
  login_page.feature:17  Check if you can Log In with incorect username and correct password
  login_page.feature:23  Check if you can Log In with incorect username and incorrect password
  login_page.feature:29  Check if you can Log In with corect username and incorrect password
  login_page.feature:35  Check if you can Log In with no username and correct password
  login_page.feature:41  Check if you can Log In with corect username and no password
  login_page.feature:47  Check if you can Log In with no username and no password
  main_page.feature:8  Check if you find A/B Testing clickable link and go to the page
  main_page.feature:13  Check if you find Broken Images clickable link and go to the page
  main_page.feature:18  Check if you find Dynamic Controls clickable link and go to the page
  main_page.feature:23  Check if you find Form Authentications clickable link and go to the page
  secured_login.feature:6  Check if the Log In message is displayed
  secured_login.feature:11  Check if I press the Log Out button redirects me to previous page

0 features passed, 3 failed, 0 skipped
0 scenarios passed, 13 failed, 0 skipped
0 steps passed, 13 failed, 26 skipped, 7 undefined
Took 0m0.000s

You can implement step definitions for undefined steps with these snippets:

@then(u'I cannot login into the application and I receive Your username is invalid!\n×')
def step_impl(context):
    raise NotImplementedError(u'STEP: Then I cannot login into the application and I receive Your username is invalid!\n×')

@then(u'I cannot login into the application and I receive Your password is invalid!\n×')
def step_impl(context):
    raise NotImplementedError(u'STEP: Then I cannot login into the application and I receive Your password is invalid!\n×')

@then(u'I am redirected to the Broken Images page')
def step_impl(context):
    raise NotImplementedError(u'STEP: Then I am redirected to the Broken Images page')
bittner commented 1 year ago

How to create a Minimal, Reproducible Example. :books:

The integration seems configured correctly. You may try to use the verbose option to find out whether the formatter is actually loaded.

gilferro commented 1 year ago

@bittner I am facing the same issue.

Steps to reproduce:

  1. Installed behave and behave-html-formatter 0.9.10
  2. Added the behave.ini file to my home directory
    
    $ cat ~/behave.ini

-- FILE: behave.ini

Define ALIAS for HtmlFormatter.

[behave.formatters] html = behave_html_formatter:HTMLFormatter

3. Run `behave -f html --verbose`

Loading config defaults from "/Users/myuser/behave.ini" Using defaults: color True show_snippets True show_skipped True dry_run False show_source True show_timings True stdout_capture True stderr_capture True log_capture True logging_format %(levelname)s:%(name)s:%(message)s logging_level 20 steps_catalog False summary True junit False stage None userdata {} default_format pretty default_tags scenario_outline_annotation_schema {name} -- @{row.id} {examples.name} more_formatters {'html': 'behave_html_formatter:HTMLFormatter'}

usage: behave [options] [ [DIR|FILE|FILE:LINE] ]+ behave: error: format=html is unknown



python3 version: `Python 3.10.5`
CojanuAlin commented 1 year ago

@bittner I am facing the same issue.

Steps to reproduce:

  1. Installed behave and behave-html-formatter 0.9.10
  2. Added the behave.ini file to my home directory
    
    $ cat ~/behave.ini

-- FILE: behave.ini

Define ALIAS for HtmlFormatter.

[behave.formatters] html = behave_html_formatter:HTMLFormatter

3. Run `behave -f html --verbose`

Loading config defaults from "/Users/myuser/behave.ini" Using defaults: color True show_snippets True show_skipped True dry_run False show_source True show_timings True stdout_capture True stderr_capture True log_capture True logging_format %(levelname)s:%(name)s:%(message)s logging_level 20 steps_catalog False summary True junit False stage None userdata {} default_format pretty default_tags scenario_outline_annotation_schema {name} -- @{row.id} {examples.name} more_formatters {'html': 'behave_html_formatter:HTMLFormatter'}

usage: behave [options] [ [DIR|FILE|FILE:LINE] ]+ behave: error: format=html is unknown



python3 version: `Python 3.10.5`

I managed to resolve this by creating the project using Python Interpreter. When I got the error i started the project using venv hence the error. If you try to create new project can you verify if you have the correct interpreter

jenisys commented 1 year ago

@CojanuAlin @gilferro Which behave version are you using ?

NOTES:

TRY: The help formatter shows a number of problems related to registration and use of user-defined formatters:

$ behave -f help                                                                                                                                         ─╯
AVAILABLE FORMATTERS:
  html           Very basic HTML formatter
  json           JSON dump of test run
  ...
  tags           Shows tags (and how often they are used).
  tags.location  Shows tags and the location where they are used.

UNAVAILABLE FORMATTERS:
  allure         ModuleNotFoundError: No module named 'allure_behave'

SEE ALSO: Testcase to using a user-defined formatter

jenisys commented 1 year ago

Use a newer behave version from the Github repo to get better diagnostics what is wrong.

# -- WORKDIR: behave repo
$ behave --version
behave 1.2.7.dev3

# -- SYNDROME: Unknown module is used (maybe: formatter is not installed)
$ behave -f unknown.more:Formatter
usage: behave [options] [DIRECTORY|FILE|FILE:LINE|AT_FILE]*
behave: error: BAD_FORMAT=unknown.more:Formatter (problem: ModuleNotFoundError)

# -- SYNDROME: Use unknown class in existing module
$ behave -f behave.formatter.steps:UnknownFormatter
...
behave: error: BAD_FORMAT=behave.formatter.steps:UnknownFormatter (problem: ClassNotFoundError)

# -- SYNDROME: Use a existing class that is not a Formatter class
$ behave -f behave.formatter.base:StreamOpener
...
behave: error: BAD_FORMAT=behave.formatter.base:StreamOpener (problem: InvalidClassError)

# -- USING: FORMATTER-ALIAS from config-file (but: allure-behave is not installed)
$ behave -f allure
...
behave: error: BAD_FORMAT=allure (problem: ModuleNotFoundError)

HINTS: