Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter is unknown #36

Open
CojanuAlin opened this issue May 2, 2023 · 9 comments
Open

Formatter is unknown #36

CojanuAlin opened this issue May 2, 2023 · 9 comments
Labels
question Further information is requested

Comments

@CojanuAlin
Copy link

CojanuAlin commented May 2, 2023

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 bittner added the question Further information is requested label May 2, 2023
@bittner
Copy link
Member

bittner commented May 2, 2023

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
Copy link
Author

CojanuAlin commented May 2, 2023

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:

  • I created the BDD project I am working on created all the files and folders needed as features, steps etc
  • I am using PyCharm
  • I installed the packages:
pip install selenium
pip install behave
pip install behave-html-formatter 
pip install webdriver-manager
  • I have created the behave.ini file
  • I run in terminal "behave" command. I failed some steps, they are shown in terminal.

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
Copy link
Member

bittner commented May 2, 2023

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
Copy link
Author

CojanuAlin commented May 2, 2023

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
Copy link
Member

bittner commented May 2, 2023

How to create a Minimal, Reproducible Example. 📚

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

@gilferro
Copy link

@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
  1. 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
Copy link
Author

@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
  1. 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
Copy link
Member

jenisys commented May 26, 2023

@CojanuAlin @gilferro
Which behave version are you using ?

NOTES:

  • I just tried to use the HTML formatter with the HEAD of the behave repository
  • I was using behave-html-formatter v0.9.8 and v0.9.10 with Python 3.10.11
  • I run behave -f html -f progress features by using the behave repository
  • I did not see the error described above
  • Therefore, it is working for me which means the HTML formatter is not completely broken

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
Copy link
Member

jenisys commented May 28, 2023

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:

  • If you pip install -U behave-html-formatter to update or install this formatter, behave-v1.2.6 will be installed (from pypi.org), too.
    Therefore, you may need to use pip install git+https://github.com/behave/behave@v1.2.7.dev3 (or similar) to get a newer version again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

4 participants