-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from aodn/testing/138-add-map-tests
Playwright: Add map tests
- Loading branch information
Showing
23 changed files
with
389 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"python.envFile": "${workspaceFolder}/playwright/.env.debug", | ||
"python.testing.pytestArgs": [ | ||
"playwright/tests", | ||
"--rootdir=playwright", | ||
"-c /dev/null" /* ignore configfile: pytest.ini */ | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from enum import Enum, auto | ||
|
||
|
||
class LayerType(Enum): | ||
MARINE_PARKS = auto() | ||
WORLD_BOUNDARIES = auto() | ||
SPIDER = auto() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from core.enums.layer_type import LayerType | ||
from pages.components.map import Map | ||
|
||
|
||
class LayerFactory: | ||
def __init__(self, map: Map): | ||
self.map = map | ||
|
||
def get_layer_id(self, layer_type: LayerType) -> str: | ||
if layer_type == LayerType.MARINE_PARKS: | ||
return self.map.get_AU_Marine_Parks_Layer_id() | ||
elif layer_type == LayerType.WORLD_BOUNDARIES: | ||
return self.map.get_World_Boundaries_Layer_id() | ||
elif layer_type == LayerType.SPIDER: | ||
return self.map.get_Spider_Layer_id() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2312,5 +2312,7 @@ | |
], | ||
"itemType": "Collection" | ||
} | ||
] | ||
], | ||
"total": 17, | ||
"search_after": ["c13451a9-7cfe-091c-e044-00144f7bc0f4"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,5 +470,7 @@ | |
}, | ||
"itemType": "Collection" | ||
} | ||
] | ||
], | ||
"total": 17, | ||
"search_after": ["c13451a9-7cfe-091c-e044-00144f7bc0f4"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,7 @@ | |
], | ||
"itemType": "Collection" | ||
} | ||
] | ||
], | ||
"total": 1, | ||
"search_after": ["8112a083-019e-4b70-9404-431648892026"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,7 @@ | |
}, | ||
"itemType": "Collection" | ||
} | ||
] | ||
], | ||
"total": 1, | ||
"search_after": ["8112a083-019e-4b70-9404-431648892026"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from playwright.sync_api import Page | ||
|
||
from pages.base_page import BasePage | ||
from pages.js_scripts.js_utils import execute_js, load_js_functions | ||
|
||
|
||
class Map(BasePage): | ||
def __init__(self, page: Page): | ||
self.page = page | ||
load_js_functions(page) | ||
|
||
# Page locators | ||
self.basemap_show_hide_menu = page.get_by_label( | ||
'basemap-show-hide-menu' | ||
) | ||
|
||
def hover_map(self) -> None: | ||
"""Move the mouse cursor to the center of the map""" | ||
self.page.get_by_label('Map', exact=True).hover() | ||
|
||
def drag_map(self) -> None: | ||
"""Drag the map to a fixed distance using the mouse""" | ||
self.hover_map() | ||
# Calculate the center coordinates | ||
bounding_box = self.page.get_by_label('Map', exact=True).bounding_box() | ||
x, y = 0.0, 0.0 | ||
if bounding_box is not None: | ||
x = bounding_box['x'] + bounding_box['width'] / 2 | ||
y = bounding_box['y'] + bounding_box['height'] / 2 | ||
|
||
self.page.mouse.down() | ||
self.page.mouse.move(x + 150, y + 50) # fixed mouse move | ||
self.page.mouse.up() | ||
|
||
def center_map(self, lng: str, lat: str) -> None: | ||
"""Center the map to a given longitude and latitude coordinates""" | ||
execute_js(self.page, 'centerMap', lng, lat, '12') | ||
self.wait_for_map_loading() | ||
|
||
def wait_for_map_loading(self) -> None: | ||
"""Wait until the map is fully loaded""" | ||
self.page.wait_for_function('() => {return isMapLoaded();}') | ||
|
||
def click_map(self) -> None: | ||
"""Click the map at the current position of the mouse""" | ||
self.page.mouse.down() | ||
self.page.mouse.up() | ||
|
||
def get_map_layers(self) -> str: | ||
"""Get the total number of heatmap layers""" | ||
self.wait_for_map_loading() | ||
layers = execute_js(self.page, 'getMapLayers') | ||
return str(layers) | ||
|
||
def get_Layer_id_from_test_props(self, layer_function_name: str) -> str: | ||
"""Get specific layer id""" | ||
self.wait_for_map_loading() | ||
layer_id = execute_js(self.page, layer_function_name) | ||
return str(layer_id) | ||
|
||
def get_AU_Marine_Parks_Layer_id(self) -> str: | ||
"""Get the Australian Marine Parks layer id""" | ||
return self.get_Layer_id_from_test_props('getAUMarineParksLayer') | ||
|
||
def get_World_Boundaries_Layer_id(self) -> str: | ||
"""Get the World Boundaries layer id""" | ||
return self.get_Layer_id_from_test_props('getWorldBoundariesLayer') | ||
|
||
def get_Spider_Layer_id(self) -> str: | ||
"""Get the Spider layer id""" | ||
return self.get_Layer_id_from_test_props('getSpiderLayer') | ||
|
||
def is_map_layer_visible(self, layer_id: str) -> bool: | ||
"""Check whether a given map layer is visible""" | ||
self.wait_for_map_loading() | ||
is_visible = execute_js(self.page, 'isMapLayerVisible', layer_id) | ||
return is_visible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
from typing import Any | ||
|
||
from playwright.sync_api import Page | ||
|
||
|
||
def load_js_functions(page: Page) -> None: | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
js_file_path = os.path.join(current_dir, 'map_functions.js') | ||
with open(js_file_path, 'r') as file: | ||
js_code = file.read() | ||
page.add_init_script(js_code) | ||
|
||
|
||
def execute_js(page: Page, func_name: str, *args: Any) -> Any: | ||
args_str = ', '.join(map(repr, args)) | ||
script = f'{func_name}({args_str});' | ||
return page.evaluate(script) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function getTestProps() { | ||
return window.testProps; | ||
} | ||
|
||
function getMap() { | ||
return getTestProps().getMap(); | ||
} | ||
|
||
function getHeatmapLayer() { | ||
return getTestProps().getHeatmapLayer(); | ||
} | ||
|
||
function centerMap(lng, lat, zoom) { | ||
const map = getMap(); | ||
map.setZoom(zoom); | ||
map.setCenter([lng, lat]); | ||
} | ||
|
||
function isMapLoaded() { | ||
const map = getMap(); | ||
return map.loaded(); | ||
} | ||
|
||
function getMapLayers() { | ||
const map = getMap(); | ||
const layer = getHeatmapLayer(); | ||
return map.queryRenderedFeatures({ layers: [layer] }).length; | ||
} | ||
|
||
function getAUMarineParksLayer() { | ||
return getTestProps().getAUMarineParksLayer | ||
? getTestProps().getAUMarineParksLayer() | ||
: ""; | ||
} | ||
|
||
function getWorldBoundariesLayer() { | ||
return getTestProps().getWorldBoundariesLayer | ||
? getTestProps().getWorldBoundariesLayer() | ||
: ""; | ||
} | ||
|
||
function getSpiderLayer() { | ||
return getTestProps().getSpiderLayer ? getTestProps().getSpiderLayer() : ""; | ||
} | ||
|
||
function isMapLayerVisible(layerId) { | ||
const map = getMap(); | ||
return undefined != map.getLayer(layerId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.