Home > Software engineering >  The term 'behave' is not recognized as the name of a cmdlet, function
The term 'behave' is not recognized as the name of a cmdlet, function

Time:01-13

I have Python 3.10.7 with the follwing packgaes installed using pip install in command line: behave 1.2.6 selenium 4.4.3

These have also been added to the packagelist of the project using the project config in pycharm Also behave is in the systme path as well along with python.

I am trying to use the behave command but I am getting the following error:

behave : The term 'behave' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
  behave features\myfeaturefile.feature

Following is my project directory: enter image description here

Following is my project in pycharm: enter image description here

I need help in fixing this problem as I am new to this tool. Thanks

CodePudding user response:

First check if you have behave and python in the path variables. Check if you can execute the below command

C:\demo>behave -h

If this does not return a list of help commands associated with behave, this means that behave is not in the path variables

Alternatively, you can check it via cmd using the "PATH" command. This will show you all the entries in the system path

C:\demo>PATH
PATH=C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot\bin...

If behave or python are not in the path variables, you can set them using

set PATH=%PATH%;c:\PATH_TO_BEHAVE

NOTE: Setting path using cmd is only valid till the time the cmd window is open. Once you close it, the path variable will be rest to original values.

CodePudding user response:

Behave, along with a few other .exe files is sitting in the: C:\Users\chauhany\AppData\Roaming\Python\Python310\Scripts enter image description here

As per your instructions @Manish Agarwal, I added the C:\Users\chauhany\AppData\Roaming\Python to the PATH from the command line and re-started the machine. But it didn't help. I then moved the behave.exe from the above location to my python 3.10 directory which is sitting in C:\Program Files\Python310 and python is in the system path, and restarted my machine again.

I then deleted and recreated my project with the new feature file (same directory structure).

If I now run the same command, that is, features\myfeaturefile.feature from C:\Users\chauhany\PycharmProjects\martechBehaveProject> I get a FileNotFound error

So I went to the folder where the file is actually sitting that is:

C:\Users\chauhany\PycharmProjects\martechBehaveProject\features\steps> and then re-ran the command and it worked.

I was under the impression that if you have just one feature file you don't have to specify the actual feature file and it can be run from anywhere in your project i.e., from any location which certainly is not correct.

  • Related