0

Is there a way to explicitly access multiple objects of the same class in robot framework. I have a class with a function to telnet to a host. I want to connect to two different hosts and run different commands on those. In my Robot Testcases file, I have

myclass.Login To Host     | host1  |  user  |  password

myclass.Run Cmd            |  ls

myclass.Login To Host    |  host2 | user  |  password

myclass.Run Cmd           |   ls -l

I see that the Run Cmd is executed on the first host (host1) in both the cases. is there a way I can call functions on specific objects Since this is part of my test case, I cant split them into two different test cases.

How can I call the second "Run Cmd" on the object thats created as a result of the Login To Host for host2 ?

Thanks Bobby

4
  • could you share a little bit of the source code of your class so it is easier to answer you? Commented Apr 10, 2014 at 7:49
  • Here is my python code Commented Apr 16, 2014 at 20:58
  • Here is my Python Code import pxssh <br> import pexpect class test(): def __init__(self): self.conn = None def login_to_host(self, host, username='user', password='password'): ''' SSH to the box ''' print 'logging in to %s' %host try: s = pxssh.pxssh() s.login (host, username, password) self.conn = s except pxssh.ExceptionPxssh, e: print "pxssh failed on login to %s." %host print str(e) print 'Successfully logged into %s' %host return s run_cmd (self, cmd): self.conn.sendline(cmd) Commented Apr 16, 2014 at 21:00
  • @user3517560: a comment is not an appropriate place to put code. If the code in that comment clarifies your question, please put it in the question. It's impossible to read they way it is formatted in a comment. Commented May 12, 2014 at 20:08

1 Answer 1

1

Yes, it is possible. The Selenium2Library does this, for example. If this is your class, you can do whatever you want. For example, have your login keyword return an identifier -- or let the test case supply one. Then, you could modify your run keyword to accept this identifier to know which connection to use.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.