0
Scenario: Navigate from overview to system details
    Given the login page is displyed
    When log in is selected
    the user selects a red bubble
    Then bubble-details are displayed


@When('the user selects a red bubble')
def click_checkpoint(self):
    def find_checkpoint(self):
        p = pyautogui.locateOnScreen('venv/screens/2018-04-26_0806.png')
        c = pyautogui.center(p)
        d = list(c)
    find_checkpoint(pyautogui.click(d[0], d[1], duration=1))

I keep getting an error on: File "src\Playground\Navigation\steps\interaction.py", line 55, in click_checkpoint find_checkpoint(pyautogui.click(d[0], d[1], duration=1)) NameError: name 'd' is not defined

obviously i have not structured the python correctly but lack the skills to trouble shoot it, maybe someone has a quick fix.

The goal is to define the pyautogui and run it immediately after but in the same step

1 Answers1

0

It is because d is defined in the score within the inner function find_checkpoint

When you define a function, all the variables in them becomes local. If you REALLY need the variables to be global, you can use the global keyword.

See this question about scoping rules

What I believe you really need to do is return the value of d and then assign it;

@When('the user selects a red bubble')
def click_checkpoint(self):
    def find_checkpoint(self):
        p = pyautogui.locateOnScreen('venv/screens/2018-04-26_0806.png')
        c = pyautogui.center(p)
        return list(c)
    d = find_checkpoint(self)
    find_checkpoint(pyautogui.click(d[0], d[1], duration=1))
Pax Vobiscum
  • 2,551
  • 2
  • 21
  • 32
  • thats because i can't call the find checkpoint unless it is outside the inner function. i need to call the coordinates in the same step somehow – Christian Busse Apr 26 '18 at 13:33
  • thanks, the error has now changed to: pyscreeze\__init__.py", line 407, in center return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2)) TypeError: 'NoneType' object is not subscriptable (which is closer to reality) – Christian Busse Apr 26 '18 at 13:43
  • You could add a print after assigning `d` to see what its contents are. – Pax Vobiscum Apr 26 '18 at 13:57
  • `def click_checkpoint(context): p = context.browser(pyautogui.locateOnScreen("venv/screens/2018-04-26_0806.png")) c = pyautogui.center(p) d = list(c) pyautogui.click(d[0], d[1], duration=1)` The problem is that as soon as i put it into a function it doesn't find the coordinates. i'ts like it is trapped inside the function and can't look outside. so i tried calling the context which has the browser session stored but im notgood enough to combine it – Christian Busse Apr 27 '18 at 09:47