سؤال

I have just begun working on Robot framework (just started learning Python as well..) . Whenever I try to run some code examples from google docs, it throws me various errors. Now, I apologize for my ignorance, bit I want to know where I am going wrong. Ex: I copy this code from google code, but it doesnt work.

:FOR    ${var}  IN  @{VALUES}
Continue For Loop If    '${var}' == 'CONTINUE'  

What should my values/var variables contain to make it work. It always throws a "NOT a keyword Exception". I have not installed Jython BTW. Do i have to install it?

Also, how can I use the "CALL METHOD" keyword.

Call Method ${hashtable} isEmpty

doesnt work. Even if I initialize hashtable to some val or set it to none.

EDIT :

TC 01
     FOR    ${item} IN  @{list}
       Log  ${item}

I am trying to run the above code. I have defined both list and item (i think declaring item as variable is unnecessary, correct me if i am wrong). Now when I try to run this code, I am getting 'For' is a reserved keyword error. If I try to inser a '\' before LOG or FOR, it says - "No KeyWord WITH name '\FOR' FOUND." . What am I doing wrong??

هل كانت مفيدة؟

المحلول

With Robot Framework you don't need Jython, it is just an option. Python is all you need.

Your for loop is not valid, it should be like this:

*** Variables ***
@{list}           foo    bar    lorem    ipsum    dolor    sit    amet

*** Test Cases ***
Example
    : FOR    ${item}    IN    @{list}
    \    Log    ${item}

If you save that as an example.txt and run pybot example.txt in the same directory, it passes and logs all items of list individually.

In order to use Call Method you need to have some object with methods to call. So you must have a python file which has a class, function and have that class instantiated and assigned to a variable. Like this:

class MyObject:
    def __init__(self):
        self.args = None
    def my_method(self, *args):
        self.args = args

obj = MyObject()

and save that to vars.py (same directory as example.txt) and then put this in to your example.txt

*** Settings ***
Variables         vars.py

*** Variables ***
@{list}           foo    bar    lorem    ipsum    dolor    sit    amet

*** Test Cases ***
Example
    : FOR    ${item}    IN    @{list}
    \    Log    ${item}

Example2
    Call Method    ${obj}    my_method
    Should Be True    ${obj.args} == ()
    Call Method    ${obj}    my_method    arg
    Should Be True    ${obj.args} == ('arg',)
    Call Method    ${obj}    my_method     a1     a2
    Should Be True    ${obj.args} == ('a1','a2')

But my guess is that you don't really want to use Call Method at this point.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top