1

On https://kb.froglogic.com/display/KB/Sharing+step+definitions+across+test+suites+%28BDD%29 it is described how to share step definition across test suits, but is not working for me.

My case:

source(findFile('scripts', 'python/bdd.py'))
setupHooks('../shared/scripts/bdd_hooks.py')

# Collect my custom step definitions:
collectStepDefinitions('/home/myuser/squish/pagesteps/steps')

def main():
    testSettings.throwOnFailure = True
    runFeatureFile('test.feature')

If I set this in test.py I get the error "Given is not defined" my implemented steps are not mapped (I emptied the steps folder from (shared/scripts/steps) path where steps are created when you select Implement missing steps)

Has anybody some info about how can I implement all the steps in a folder pagesteps? and not to be related with steps suite?

kleusmeus
  • 61
  • 9
  • This works for me. Have you adjusted the path to be valid for your operating system and system? Which path did you use exactly? Are there any *.py files in that path? Please paste the output of "ls THAT_PATH" (replace THAT_PATH with the actual path specified for your custom call of collectStepDefinitions()) executed in a shell, so that we can double check. Please also copy & paste the error shown when editing the feature file while hovering over one of the error markers. – frog.ca Aug 27 '18 at 11:31
  • This is my import statement from the top of test.py file:
    source(findFile('scripts', 'python/bdd.py'))
    setupHooks('../shared/scripts/bdd_hooks.py')
    collectStepDefinitions('/lib/panels/traffic/script_1')
    the script_1.py contains the steps definitions
    – Horatiu Moldovan Aug 28 '18 at 10:56
  • collectStepDefinitions() requires that you pass a path to a directory to it. It will try to look for *.py files in "/lib/panels/traffic/script_1". Does that path really exists, and is it really a folder? (It seems odd to place a user's files in the operating system's /lib folder.) – frog.ca Aug 29 '18 at 10:40
  • Indeed is working now. My problem was that I didn't pass entire path of the file, seems that is necessary to pass ('/myproject/squish/lib/panels/traffic') in collectStepDefinitions(), you cannot pass('../lib/panels/traffic'). Thanks for your help – Horatiu Moldovan Nov 07 '18 at 13:48

1 Answers1

-1

In order to share steps across test suite and you want to change the default location for steps, and put steps folder in Global scripts, you have to pass in collectStepDefinitions() the entire path of your steps location director

ex: if your steps are located to ('E:/myproject/squish/lib/panels/steps') than collectStepDefinitions() is implemented like this collectStepDefinitions('/myproject/squish/lib/panels/steps') not collectStepDefinitions('../lib/panels/steps')

  • It cannot be true that you need to pass the absolute/full path to collectStepDefinitions(), because the default call to collectStepDefinitions() in test.py uses relative paths (which are relative to the test case folder of the test suite) anyway: collectStepDefinitions('./steps', '../shared/steps') – frog.ca Nov 08 '18 at 14:21
  • Indeed if the steps are implemented under the shared folder from test suite, but if you have an page object architecture and the folder steps is implemented where pages are implemented under Global scripts than you cannot pass collectStepDefinitions('./steps', '../lib/panels/steps') – Horatiu Moldovan Nov 09 '18 at 08:30
  • Yes, because the working directory of the script interpreter is the test case folder of the current test suite, therefore relative paths must be relative to that. Using collectStepDefinitions('./steps', '../lib/panels/steps') to collect something located somewhere in the Global Scripts folders does not work, because the ".." part is relative to the script interpreter working directory/the test case folder. – frog.ca Nov 12 '18 at 14:51
  • You can rate the answer as +1, because in the situation explained above is the correct answer – Horatiu Moldovan Dec 05 '18 at 13:06
  • The answer is imprecise/wrong, because using relative paths is just fine. For example when suite dir and one of the global shared folders are in the same parent folder, then one can use collectStepDefinitions(... "../../the_global_script_dir"). This is in contrast to what your answer claims. – frog.ca Dec 05 '18 at 14:44
  • In order to have a proper answer for this question, and if someone want it without reading all the comments, maybe you can provide an answer with the situations when you can use relative path and when you have to use the entire path for collectStepDefinitions(). – Horatiu Moldovan Dec 06 '18 at 07:12