Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Pick the point dropdown
move_to_et_click(dimension['draw_on_map'])
time.sleep(sleep)
# Draw a counding box for line test
start_point = dimension['map_point']
direction = 80
move_right = (start_point[0] + direction, start_point[1])
move_down = (move_right[0], move_right[1] - direction)
move_left = (move_down[0] - direction, move_down[1])
move_up = (move_left[0], move_left[1] + direction)
move_to_et_click(dimension['map_point'])
move_to_et_click(move_right)
move_to_et_click(move_down)
move_to_et_click(move_left)
move_to_et_click(move_up)
gui.click(move_up)
time.sleep(plot_render_sleep)
gui.alert('Conducting test...', 'Wait', timeout=4000)
# Find expected plot
image_loc = gui.locateCenterOnScreen(
paths['line_index'], confidence=0.3, grayscale=True)
if image_loc is None:
gui.alert(text='Line index not found!', title='UI test', button='OK', timeout=box_timeout)
# Retry the test in case of slow network connection
retry_location_test(paths['line_index'], 'Line Index')
else:
gui.alert(text='Line UI test complete!', title='UI test', button='Close', timeout=box_timeout)
# Close index sub-tab
time.sleep(.30)
gui.click(dimension['close_index'])
time.sleep(sleep)
# Draw a counding box for line test
start_point = dimension['map_point']
direction = 80
move_right = (start_point[0] + direction, start_point[1])
move_down = (move_right[0], move_right[1] - direction)
move_left = (move_down[0] - direction, move_down[1])
move_up = (move_left[0], move_left[1] + direction)
move_et_click(dimension['map_point'])
move_et_click(move_right)
move_et_click(move_down)
move_et_click(move_left)
move_et_click(move_up)
gui.click(move_up)
time.sleep(plot_render_sleep)
gui.alert('Conducting test...', 'Wait', timeout=4000)
# Find expected plot
image_loc = gui.locateCenterOnScreen(
paths['line_index'], confidence=0.3, grayscale=True)
if image_loc is None:
gui.alert(text='Line index not found!', title='UI test', button='OK', timeout=box_timeout)
# Retry the test in case of slow network connection
retry_location_test(paths['line_index'], 'Line Index')
result = 'Test Failed'
else:
gui.alert(text='Line UI test complete!', title='UI test', button='Close', timeout=box_timeout)
result = 'Test Completed'
line_index_results['Profile'] = result
#Hovmoller Diagram test
point_tests(paths['line_index'], line_index_results)
move_left = (move_down[0] - direction, move_down[1])
move_up = (move_left[0], move_left[1] + direction)
move_et_click(dimension['map_point'])
move_et_click(move_right)
move_et_click(move_down)
move_et_click(move_left)
move_et_click(move_up)
gui.click(move_up)
time.sleep(plot_render_sleep)
gui.alert('Conducting test...', 'Wait', timeout=4000)
# Find expected plot
image_loc = gui.locateCenterOnScreen(
paths['line_index'], confidence=0.3, grayscale=True)
if image_loc is None:
gui.alert(text='Line index not found!', title='UI test', button='OK', timeout=box_timeout)
# Retry the test in case of slow network connection
retry_location_test(paths['line_index'], 'Line Index')
result = 'Test Failed'
else:
gui.alert(text='Line UI test complete!', title='UI test', button='Close', timeout=box_timeout)
result = 'Test Completed'
line_index_results['Profile'] = result
#Hovmoller Diagram test
point_tests(paths['line_index'], line_index_results)
# Close index sub-tab
time.sleep(.30)
gui.click(dimension['close_index'])
time.sleep(.30)
return line_index_results
def move_et_click(position):
"""
Function to move to a postion and click
*reduce duplicated codes.
"""
gui.moveTo(position)
gui.click()
def pasteIntoTextField(value, removePreviousContents=True, useClipboard=True, layout="de"):
"""
@brief paste value into current text field
"""
print(value)
# remove previous content
if removePreviousContents:
typeTwoKeys('ctrl', 'a')
time.sleep(DELAY_KEY)
if useClipboard:
# use copy & paste (due problems with certain characters, for example '|')
pyperclip.copy(value)
pyautogui.hotkey('ctrl', 'v')
else:
pyautogui.typewrite(translateKeys(value, layout))
def typeThreeKeys(key1, key2, key3):
"""
@brief type three keys at the same time (key1 -> key2 -> key3)
"""
# wait before every operation
time.sleep(DELAY_KEY)
# type two keys at the same time
pyautogui.hotkey(key1, key2, key3)
def _location_matches_expected(self):
if self.expected_region is None:
return False
screenshot = pyautogui.screenshot(region=self.expected_region)
self._last_screenshot = screenshot
result = pyautogui.locate(str(self.image_path), screenshot)
return result is not None
def find_temperature_bar():
"""
Function to locate the temperature bar on
the ocean navigator public page.
"""
result = None
time.sleep(2)
screenWidth, screenHeight = gui.size()
# Go to the navigator web page
#navigator_webpage()
# Locate temperature color bar on public page
image_loc = gui.locateCenterOnScreen(
paths['test_temperature'], confidence=0.7, grayscale=True)
if image_loc is None:
gui.alert(text='Temperature bar not found!', title='Temperature bar', button='OK')
result = 'Test Failed'
else:
gui.click(button='right', x=image_loc.x, y=image_loc.y)
gui.alert(text='Temperature bar check complete!', title='Temperature bar', button='Close', timeout=box_timeout)
result = 'Test Completed'
return result, get_time()
@brief create connection
"""
# check if connection has to be created in certain mode
if mode == "conflict":
pyautogui.keyDown('ctrl')
elif mode == "yield":
pyautogui.keyDown('shift')
# select first lane
leftClick(referencePosition, fromLanePositionX, fromLanePositionY)
# select another lane for create a connection
leftClick(referencePosition, toLanePositionX, toLanePositionY)
# check if connection has to be created in certain mode
if mode == "conflict":
pyautogui.keyUp('ctrl')
elif mode == "yield":
pyautogui.keyUp('shift')
def createConnection(referencePosition, fromLanePositionX, fromLanePositionY,
toLanePositionX, toLanePositionY, mode=""):
"""
@brief create connection
"""
# check if connection has to be created in certain mode
if mode == "conflict":
pyautogui.keyDown('ctrl')
elif mode == "yield":
pyautogui.keyDown('shift')
# select first lane
leftClick(referencePosition, fromLanePositionX, fromLanePositionY)
# select another lane for create a connection
leftClick(referencePosition, toLanePositionX, toLanePositionY)
# check if connection has to be created in certain mode
if mode == "conflict":
pyautogui.keyUp('ctrl')
elif mode == "yield":
pyautogui.keyUp('shift')