diff --git a/tests/appium_tests.py b/tests/appium_tests.py index 5cbf002..2fd4e42 100644 --- a/tests/appium_tests.py +++ b/tests/appium_tests.py @@ -17,6 +17,7 @@ def selenium_driver(self): .set_soft_assert(True) .set_appium_driver() ) + driver.configuration.save_full_stacktrace yield driver driver.quit() @@ -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() diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 404944d..241f345 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -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"]}') @@ -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, ) @@ -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): @@ -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 diff --git a/testui/support/testui_driver.py b/testui/support/testui_driver.py index a90b064..ca1b7ff 100644 --- a/testui/support/testui_driver.py +++ b/testui/support/testui_driver.py @@ -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) @@ -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,