cancel
Showing results for 
Search instead for 
Did you mean: 

Python BDD modules

SOLVED
Occasional Contributor

Python BDD modules

Hi

 

Just getting started with TestComplete and BDD. I'm experienced with Python BDD (Behave) with Selenium. Just a little unsure how to work with python modules. I can't seem to import my classes currently. Wondered if anyone could point me in the right direction. I also wasn't sure how to create a .py file.

 

I included a file named "test", with no extension inside my Scripts folder. But not sure how to import that class into my step definitions?

 

tc.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: Python BDD modules

Ok, I managed it like this:

 

import login as login_object

 

login = login_object.Login.get_instance()

 

 

My Class is like this though:

 

class Login:
    instance = None

    @classmethod
    def get_instance(cls):
        if cls.instance is None:
            cls.instance = Login()
        return cls.instance

login = Login.get_instance()

 

So looks a bit ugly, but does work. But if anyone has a better solution that would be cool

View solution in original post

4 REPLIES 4
Occasional Contributor

Re: Python BDD modules

Ok, I managed it like this:

 

import login as login_object

 

login = login_object.Login.get_instance()

 

 

My Class is like this though:

 

class Login:
    instance = None

    @classmethod
    def get_instance(cls):
        if cls.instance is None:
            cls.instance = Login()
        return cls.instance

login = Login.get_instance()

 

So looks a bit ugly, but does work. But if anyone has a better solution that would be cool

View solution in original post

Contributor

Re: Python BDD modules

Hi @jonathon ,

 

firstly when you add a file in python project under Script folder, it will automatically create a ".py" file.

for importing classes from one file to another file, you can refer here (call procedures or variables declared in another unit) , 

in your case if you want to use the definitions or variables declared n "test" file in any other file (sample),

you have to Add the following to the beginning of the "sample" file

 

import test

and after that you can refer to the variables in "sample" script which are declared in "test" file like showen in the below code snippet.

unser "test.py"

 

 

UserName = 'sampleUsername'
Password = 'samplePassword'

under "sample.py"

 

 

import test

def sampleTest():
uName = test.sampleUsername
pwd = test.Password
Log.Message(uName + pwd)
##### Output will be 'sampleUsernamesamplePassword'

 

 

 

Regards,
Sathish Kumar K
Contributor

Re: Python BDD modules

@jonathon,
Please accept as solution if it solved your problem.
Regards,
Sathish Kumar K
Occasional Contributor

Re: Python BDD modules

I solved it myself as noted

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors