Skip to content

Commit

Permalink
Change inclusive search to regex search (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikahanninen authored Sep 26, 2023
1 parent e9bd5ef commit b7a8055
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/JABWrapper/context_tree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import threading
from dataclasses import dataclass
from typing import List
Expand Down Expand Up @@ -213,7 +214,7 @@ def _match_attrs(self, search_elements: List[SearchElement]) -> bool:
for search_element in search_elements:
attr = getattr(self._aci, search_element.name)
if isinstance(attr, str) and not search_element.strict:
if not attr.startswith(search_element.value):
if not re.match(search_element.value, attr):
return False
else:
if not attr == search_element.value:
Expand Down
39 changes: 35 additions & 4 deletions tests/test_jab_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ def shutdown_app(jab_wrapper, context_info_tree):

@pytest.fixture(params=["title", "pid"])
def test_application(jab_wrapper, request):
context_info_tree = application_launcher(jab_wrapper, request.param)
yield context_info_tree

shutdown_app(jab_wrapper, context_info_tree)


def application_launcher(jab_wrapper, by_attr):
app_path = os.path.join(os.path.abspath(os.path.curdir), "tests", "test-app")
# Compile a simple Java program.
subprocess.run(["makejar.bat"], check=True, shell=True, cwd=app_path, close_fds=True)
# Run the swing program in the background.
logging.info("Opening Java Swing application...")
by_attr = request.param
title = f"Chat Frame - By {by_attr}"
subprocess.Popen(["java", "BasicSwing", title], cwd=app_path, close_fds=True)

Expand All @@ -97,9 +103,7 @@ def test_application(jab_wrapper, request):
select_window(jab_wrapper, window_id)
context_info_tree = parse_elements(jab_wrapper)

yield context_info_tree

shutdown_app(jab_wrapper, context_info_tree)
return context_info_tree


def wait_until_text_contains(element: ContextNode, text: str, retries=10):
Expand Down Expand Up @@ -260,3 +264,30 @@ def test_app_flow(test_application):
click_send_button(test_application, text_area)
click_clear_button(test_application, text_area)
verify_table_content(test_application)


@pytest.fixture(
params=[
[["role", "push button", True], ["name", "Cl[a-z]{3}", False]],
[["role", "push button", True], ["name", "S.*1", False]],
[["role", "push button", True], ["name", ".*1", False]],
[["role", "push.*", False], ["name", "Clear", False]],
]
)
def base_locator(jab_wrapper, request):
context_info_tree = application_launcher(jab_wrapper, "title")
logging.warning(request.param)
search_elements = []
for item in request.param:
search_elements.append(SearchElement(item[0], item[1], item[2]))

element = context_info_tree.get_by_attrs(search_elements)
logging.debug("Found element by role (push button) and name (Send): {}".format(element))
yield element

shutdown_app(jab_wrapper, context_info_tree)


def test_locator_click(base_locator):
assert len(base_locator) == 1, "Elements found should have been 1 by locator={}".format(base_locator)
base_locator[0].click()

0 comments on commit b7a8055

Please sign in to comment.