Tanmay Patil
Tanmay Patil

Reputation: 699

typeError in calling user defined test library function ( with arguments ) in robot framework

I have user defined function saveLogin in test library implemented as follows.

def saveLogin(userId,serialNo):
    conn = sqlite3.connect('new.db')
    conn.execute("INSERT INTO login VALUES(?,?)",userId,serialNo)
    conn.commit()

When i try to call this function . In test case sessionTest,

sessionTest
    saveLogin    ${CRE_USER_ID}    1

Getting following error :

sessionTest
          | FAIL |
**TypeError: function takes at most 2 arguments (3 given).**

When i pass only 1 argument

sessionTest
    saveLogin    ${CRE_USER_ID}

sessionTest
   | FAIL |
**Keyword 'getSequence.Save Login' expected 2 arguments, got 1.**

Not able to figure out the reason for this error .

Upvotes: 1

Views: 177

Answers (1)

Tanmay Patil
Tanmay Patil

Reputation: 699

Problem was the argument to the sqlite function execute . execute function expects at most 2 arguments . Modified function saveLogin to pass correct arguments to execute function. Earlier i was passing 3 arguments , hence the error was coming.

def saveLogin(userId,serialNo):
    conn = sqlite3.connect('new.db')
    values = ( userId,serialNo)
    conn.execute("INSERT INTO login VALUES(?,?)",values)
    conn.commit()

Upvotes: 1

Related Questions