SikuliXIDE; Mojave; Robot Framework: TypeError: unsupported operand type(s) for -: 'unicode' and 'int'

Asked by Melvin Raymond

I seem to be getting hung up in something that I think ought to be easy, but I've been going round and round with this for a while. I a have function that worked fine in Jython (outside the Robot Framework), but when I put it in the Robot Framework I had to change things up a bit by converting a string back to an integer in order to get the "If, elif, else" to work. I'm attempting to use this function for moving around a table grid so I can write values into the cells. The problem is, the grid movement actually appears to work (because I can see it highlight the next cell I intend to write to), but it throws the following error and fails my keyword. The error is:

TypeError: unsupported operand type(s) for -: 'unicode' and 'int'

FOLLOWING IS ROBOT FRAMEWORK DRIVING IT ALL:

runScript("""
robot
*** Variables ***
${TESTAPP} "/Applications/Vernier Graphical Analysis.app"
${moveright} 1
${moveleft} 2
${moveup} 3
${movedown} 4

*** Settings ***
Library ./inline/GA4
Suite Setup Suite Setup Actions
Suite Teardown Suite Teardown Actions
Test Teardown Test Case Tear Down
*** Test Cases ***
Test Manual Copy and Paste to Cell
    [Documentation] Test Case to do a manual copy and paste to cell (Table view)
    Log Executing Manual Copy and Paste to Cell Test
    press manual entry button
    press view options button
    select table view
    initialize table ${TESTAPP}
    write to selected cell 2
    grid movement ${movedown} 1

*** Keywords ***
Suite Setup Actions
    Log Suite Setup Actions done below
    start my application ${TESTAPP}
    define application region

Suite Teardown Actions
    Log Suite Teardown Actions done below
    stop my application ${TESTAPP}

Test Case Tear Down
    Log Test Teardown Actions done below
    prep for next test

""")

FOLLOWING IS THE FUNCTION (I've stripped all out of the Class but that one to shorten it up here):

class GA4(object):

  def grid_movement(self, direction, loopvalue):
    print "Executing 'grid_movement' function"
    movdirection = int(direction)
    while(loopvalue > 0):
      if movdirection == 1:
        type(Key.RIGHT)
      elif movdirection == 2:
        type(Key.LEFT)
      elif movdirection == 3:
        type(Key.UP)
      elif movdirection == 4:
        type(Key.DOWN)
      else:
        break
      loopvalue -= 1
      print loopvalue

FOLLOWING IS THE ROBOT FRAMEWORK OUTPUT:

Test Execution Log

00:00:13.367SUITE GA4-experimenting
Full Name: GA4-experimenting
Source: /Users/labquest_automation/Desktop/SikuliX_Scripts/GA4-experimenting.sikuli.robot/GA4-experimenting.robot
Start / End / Elapsed: 20190418 12:56:33.650 / 20190418 12:56:47.017 / 00:00:13.367
Status: 1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
00:00:02.021SETUP Suite Setup Actions
00:00:01.594TEARDOWN Suite Teardown Actions
00:00:09.550TEST Test Manual Copy and Paste to Cell
Full Name: GA4-experimenting.Test Manual Copy and Paste to Cell
Documentation:
Test Case to do a manual copy and paste to cell (Table view)
Start / End / Elapsed: 20190418 12:56:35.869 / 20190418 12:56:45.419 / 00:00:09.550
Status: FAIL (critical)
Message: TypeError: unsupported operand type(s) for -: 'unicode' and 'int'
00:00:00.002KEYWORD BuiltIn . Log Executing Manual Copy and Paste to Cell Test
00:00:02.949KEYWORD GA4 . Press Manual Entry Button
00:00:00.770KEYWORD GA4 . Press View Options Button
00:00:02.239KEYWORD GA4 . Select Table View
00:00:03.342KEYWORD GA4 . Initialize Table ${TESTAPP}
00:00:00.174KEYWORD GA4 . Write To Selected Cell 2
00:00:00.062KEYWORD GA4 . Grid Movement ${movedown}, 1
Start / End / Elapsed: 20190418 12:56:45.350 / 20190418 12:56:45.412 / 00:00:00.062
12:56:45.404 INFO Executing 'grid_movement' function
[log] TYPE "#DOWN."
12:56:45.412 FAIL TypeError: unsupported operand type(s) for -: 'unicode' and 'int'
00:00:00.004TEARDOWN Test Case Tear Down

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Melvin Raymond
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

apparently loopvalue is a string, when handed over to the GA4::grid_movement.

so this should help:
 def grid_movement(self, direction, cells = 1):
    print "Executing 'grid_movement' function"
    movdirection = int(direction)
    loopvalue = int(cells)
    while(loopvalue > 0):
...

usage with one-cell movement:

grid movement ${movedown}

Revision history for this message
Melvin Raymond (fribian) said :
#2

Ugh! OK, that was an overlooked miss on my part. Didn't even think about the other variable getting converted since I had not used a variable for it in Robot Framework. I just typed in the loopvalue I wanted into the tabbed Robot Framework. I didn't even try that since the error looked as if it were coming from the type and Key statement. Apparently the Robot Framework even converts the values to string that aren't assigned a Variable in the Variables part of Robot Framework.

I just added "loopvalue = int(loopvalue)" in there and that fixed it.

I haven't searched for it, but there could be something built into Robot Framework that defines these kind of tabbed values.

Thanks Railman. Good to come back Monday and find I can keep it rolling along.

Revision history for this message
Melvin Raymond (fribian) said :
#3

Did I type in "RailMan"? Or did that auto correct do that?
Sorry RaiMan,
RailMan = RaiMan

Revision history for this message
RaiMan (raimund-hocke) said :
#4

LOL - really no problem - I know its me ;-)