Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions appium/webdriver/extensions/images_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ def match_images_features(self, base64_image1: Base64Payload, base64_image2: Bas
Returns:
The dictionary containing the following entries:

visualization (bytes): base64-encoded content of PNG visualization of the current comparison
visualization (str): base64-encoded content of PNG visualization of the current comparison
operation. This entry is only present if `visualize` option is enabled
count (int): The count of matched edges on both images.
The more matching edges there are no both images the more similar they are.
totalCount (int): The total count of matched edges on both images.
It is equal to `count` if `goodMatchesFactor` does not limit the matches,
otherwise it contains the total count of matches before `goodMatchesFactor` is
applied.
points1 (dict): The array of matching points on the first image. Each point is a dictionary
points1 (list): The array of matching points on the first image. Each point is a dictionary
with 'x' and 'y' keys
rect1 (dict): The bounding rect for the `points1` array or a zero rect if not enough matching points
were found. The rect is represented by a dictionary with 'x', 'y', 'width' and 'height' keys
points2 (dict): The array of matching points on the second image. Each point is a dictionary
points2 (list): The array of matching points on the second image. Each point is a dictionary
with 'x' and 'y' keys
rect2 (dict): The bounding rect for the `points2` array or a zero rect if not enough matching points
were found. The rect is represented by a dictionary with 'x', 'y', 'width' and 'height' keys
Expand All @@ -78,7 +78,7 @@ def match_images_features(self, base64_image1: Base64Payload, base64_image2: Bas

def find_image_occurrence(
self, base64_full_image: Base64Payload, base64_partial_image: Base64Payload, **opts: Any
) -> dict[str, bytes | dict]:
) -> dict[str, Any] | list[dict[str, Any]]:
"""Performs images matching by template to find possible occurrence of the partial image
in the full image.

Expand All @@ -94,13 +94,17 @@ def find_image_occurrence(
Keyword Args:
visualize (bool): Set it to True in order to return the visualization of the matching operation.
False by default
multiple (bool): Set it to True in order to return all matches above the threshold
as a list. False by default

Returns:
The dictionary containing the following entries:
visualization (bytes): base64-encoded content of PNG visualization of the current comparison
operation. This entry is only present if `visualize` option is enabled
The dictionary containing the following entries, or a list of such dictionaries
(one per match) if `multiple` is enabled:
visualization (str): base64-encoded content of PNG visualization of the current comparison
operation. This entry is only filled if `visualize` option is enabled
rect (dict): The region of the partial image occurrence on the full image.
The rect is represented by a dictionary with 'x', 'y', 'width' and 'height' keys
score (float): The similarity score of the match
"""
options = {
'mode': 'matchTemplate',
Expand All @@ -110,9 +114,7 @@ def find_image_occurrence(
}
return self.execute(Command.COMPARE_IMAGES, options)['value']

def get_images_similarity(
self, base64_image1: Base64Payload, base64_image2: Base64Payload, **opts: Any
) -> dict[str, bytes | dict]:
def get_images_similarity(self, base64_image1: Base64Payload, base64_image2: Base64Payload, **opts: Any) -> dict[str, Any]:
"""Performs images matching to calculate the similarity score between them.

The flow there is similar to the one used in
Expand All @@ -124,12 +126,12 @@ def get_images_similarity(
base64_image2: base64-encoded content of the second image

Keyword Args:
visualize (boo): Set it to True in order to return the visualization of the matching operation.
visualize (bool): Set it to True in order to return the visualization of the matching operation.
False by default

Returns:
The dictionary containing the following entries:
visualization (bytes): base64-encoded content of PNG visualization of the current comparison
visualization (str): base64-encoded content of PNG visualization of the current comparison
operation. This entry is only present if `visualize` option is enabled
score (float): The similarity score as a float number in range [0.0, 1.0].
1.0 is the highest score (means both images are totally equal).
Expand Down
8 changes: 6 additions & 2 deletions appium/webdriver/extensions/log_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.


from typing import Any

from typing_extensions import Self

from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands
Expand All @@ -21,7 +23,7 @@


class LogEvent(CanExecuteCommands):
def get_events(self, type: list[str] | None = None) -> dict[str, str | int]:
def get_events(self, type: list[str] | None = None) -> dict[str, Any]:
"""Retrieves events information from the current session
(Since Appium 1.16.0)

Expand All @@ -33,11 +35,13 @@ def get_events(self, type: list[str] | None = None) -> dict[str, str | int]:
| events = driver.get_events(['appium:funEvent'])

Returns:
`dict`: A dictionary of events timing information containing the following entries
`dict`: A dictionary of events timing information. Every value is a list.
| commands: (`list` of `dict`) List of dictionaries containing the following entries
| cmd: The command name that has been sent to the appium server
| startTime: Received time
| endTime: Response time
| Each other key is an event name, such as 'appium:funEvent', and its value is
| the `list` of timestamps (`int`, milliseconds) when that event happened
"""
data = {}
if type is not None:
Expand Down
Loading