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
5 changes: 3 additions & 2 deletions tests/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def selenium_driver(self):
.set_soft_assert(True)
.set_appium_driver()
)
driver.configuration.save_full_stacktrace
yield driver
driver.quit()

Expand All @@ -29,9 +30,9 @@ def test_screenshot_methods(self, selenium_driver: TestUIDriver):
)
selenium_driver.start_recording_screen()
time.sleep(1)
selenium_driver.stop_recording_and_compare("./resources/comp.png", fps_reduction=30, keep_image_as="v_image.png")
selenium_driver.stop_recording_and_compare("./resources/comp.png", fps_reduction=30, keep_image_as="./logs/v-image.png")
selenium_driver.find_image_match(
"./resources/comp.png", 0.9, True, image_match="image.png"
"./resources/comp.png", 0.9, True, image_match="./logs/image.png"
)
selenium_driver.click_by_image("./resources/comp.png")
selenium_driver.raise_errors()
33 changes: 19 additions & 14 deletions testui/support/appium_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def __local_run(url, desired_caps, use_port, udid, log_file):
os.getenv("PYTEST_XDIST_WORKER").split("w")[1]
)
bport += int(os.getenv("PYTEST_XDIST_WORKER").split("w")[1]) * 2
logger.log(f"running: appium -p {port.__str__()} -bp {bport.__str__()}")
logger.log(f"running: appium -p {port.__str__()}")
if udid is None:
desired_caps = __set_android_device(desired_caps, device)
logger.log(f'setting device for automation: {desired_caps["udid"]}')
Expand All @@ -422,7 +422,7 @@ def __local_run(url, desired_caps, use_port, udid, log_file):
file_path = os.path.join(log_dir, log_file)
with open(file_path, "wb") as out:
process = subprocess.Popen(
["appium", "-p", port.__str__(), "-bp", bport.__str__()],
["appium", "-p", port.__str__()],
stdout=out,
stderr=subprocess.STDOUT,
)
Expand All @@ -437,13 +437,15 @@ def __local_run(url, desired_caps, use_port, udid, log_file):
out.close()
break
out.close()
return (
f"http://localhost:{port.__str__()}/wd/hub",
desired_caps,
process,
file_path,
)
return url, desired_caps, None
# Check Appium Version
result = subprocess.run(["appium", "-v"], stdout=subprocess.PIPE).stdout
url = f"http://localhost:{port.__str__()}/wd/hub"
if result.decode('utf-8').startswith("2."):
# for Appium version > 2.0.0
url = f"http://localhost:{port.__str__()}"
return url, desired_caps, process, file_path

return url, desired_caps, None, None


def __local_run_ios(url, desired_caps, use_port, udid, log_file):
Expand Down Expand Up @@ -487,11 +489,14 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file):
out.close()
break
out.close()
return (
f"http://localhost:{port.__str__()}/wd/hub",
desired_caps,
file_path,
)
# Check Appium Version
url = f"http://localhost:{port.__str__()}/wd/hub"
result = subprocess.run(["appium", "-v"], stdout=subprocess.PIPE).stdout
if result.decode('utf-8').startswith("2."):
# for Appium version > 2.0.0
url = f"http://localhost:{port.__str__()}"
return url, desired_caps, file_path

return url, desired_caps, process


Expand Down
10 changes: 6 additions & 4 deletions testui/support/testui_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def find_image_match(
current_time = now.strftime("%Y-%m-%d%H%M%S")
image_name = f"{self.device_udid}{current_time}.png"
image_path = self.save_screenshot(image_name)
comparison = os.path.join(
self.__configuration.screenshot_path,
comparison
)
found, p = ImageRecognition(
image_path, comparison, threshold, self.device_name, self.configuration.screenshot_path
).compare(image_match)
Expand Down Expand Up @@ -457,11 +461,9 @@ def stop_recording_and_compare(
"""
now = datetime.now()
current_time = now.strftime("%Y-%m-%d%H%M%S")
log_dir = self.__configuration.screenshot_path
video_name = f"{self.device_udid}{current_time}.mp4"
self.stop_recording_screen(video_name)
log_dir = "./logs"
if self.__configuration.screenshot_path != "":
log_dir = self.__configuration.screenshot_path
self.stop_recording_screen(os.path.join(log_dir, video_name))
found = ImageRecognition(
video_name, comparison, threshold,
device_name=self.device_name,
Expand Down