From 07e55bef9143706be10b7b5366a9c94c2c5b3371 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Mon, 9 Dec 2019 12:27:09 +0530 Subject: [PATCH 01/12] Write screenshots to file and return the file path instead of returning screenshots bytes. getgauge/gauge#1476 --- getgauge/executor.py | 9 ++++----- getgauge/python.py | 2 +- getgauge/registry.py | 28 +++++++++++++++++++++------- tests/test_python.py | 15 +++++++++++---- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/getgauge/executor.py b/getgauge/executor.py index 17b19d4..aeda180 100644 --- a/getgauge/executor.py +++ b/getgauge/executor.py @@ -35,7 +35,7 @@ def execute_method(params, step, response, is_continue_on_failure=_false): _add_exception(e, response, is_continue_on_failure(step.impl, e)) response.executionResult.executionTime = _current_time() - start response.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionResult.screenshotFiles.extend(ScreenshotsStore.pending_screenshots()) def _current_time(): return int(round(time.time() * 1000)) @@ -54,9 +54,8 @@ def _get_args(params, hook_or_step): def _add_exception(e, response, continue_on_failure): if os.getenv('screenshot_on_failure') == 'true': - screenshot = registry.screenshot_provider()() - response.executionResult.screenShot = screenshot - response.executionResult.failureScreenshot = screenshot + screenshot = ScreenshotsStore.capture_to_file() + response.executionResult.failureScreenshotFile = screenshot response.executionResult.failed = True message = e.__str__() if not message: @@ -67,4 +66,4 @@ def _add_exception(e, response, continue_on_failure): if continue_on_failure: response.executionResult.recoverableError = True response.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionResult.screenshotFiles.extend(ScreenshotsStore.pending_screenshots()) diff --git a/getgauge/python.py b/getgauge/python.py index a785283..2e827e2 100644 --- a/getgauge/python.py +++ b/getgauge/python.py @@ -62,7 +62,7 @@ def screenshot(func): def custom_screen_grabber(func): - registry.set_screenshot_provider(func) + registry.set_screenshot_provider(func, False) return func diff --git a/getgauge/registry.py b/getgauge/registry.py index a15d331..9eecda5 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -3,6 +3,7 @@ import re import sys import tempfile +from uuid import uuid1 from subprocess import call from getgauge import logger @@ -107,6 +108,7 @@ class Registry(object): def __init__(self): self.__screenshot_provider, self.__steps_map, self.__continue_on_failures = _take_screenshot, {}, {} + self.is_file_based_screenshot = True for hook in Registry.hooks: self.__def_hook(hook) @@ -150,8 +152,9 @@ def get_info_for(self, step_text): def get_infos_for(self, step_text): return self.__steps_map.get(step_text) - def set_screenshot_provider(self, func): + def set_screenshot_provider(self, func, is_file_based): self.__screenshot_provider = func + self.is_file_based_screenshot = is_file_based def screenshot_provider(self): return self.__screenshot_provider @@ -226,13 +229,11 @@ def _get_step_value(step_text): def _take_screenshot(): - temp_file = os.path.join(tempfile.gettempdir(), 'screenshot.png') + temp_file_name = "screenshot-%s.png"%(uuid1().int) + temp_file = os.path.join(os.getenv('screenshots_dir'), temp_file_name) try: call(['gauge_screenshot', temp_file]) - _file = open(temp_file, 'r+b') - data = _file.read() - _file.close() - return data + return temp_file_name except Exception as err: logger.error( "\nFailed to take screenshot using gauge_screenshot.\n{0}".format(err)) @@ -256,7 +257,20 @@ def pending_screenshots(): @staticmethod def capture(): - ScreenshotsStore.__screenshots.append(registry.screenshot_provider()()) + screenshot = ScreenshotsStore.capture_to_file() + ScreenshotsStore.__screenshots.append(screenshot) + + @staticmethod + def capture_to_file(): + content = registry.screenshot_provider()() + if not registry.is_file_based_screenshot: + temp_file_name = "screenshot-%s.png"%(uuid1().int) + temp_file = os.path.join(os.getenv('screenshots_dir'), temp_file_name) + file = open(temp_file, "w") + file.write(content) + file.close() + content = temp_file_name + return content @staticmethod def clear(): diff --git a/tests/test_python.py b/tests/test_python.py index 00b58eb..300f056 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -6,6 +6,8 @@ DataStoreContainer, data_store, Table, Specification, Scenario, Step, ExecutionContext, create_execution_context_from) +import os +import tempfile try: from collections.abc import MutableMapping except ImportError: @@ -508,11 +510,14 @@ def test_screenshot_decorator(self): class ScreenshotsTests(TestCase): + def setUp(self): + os.environ["screenshots_dir"] = tempfile.mkdtemp() def test_pending_screenshots(self): ScreenshotsStore.capture() pending_screenshots = ScreenshotsStore.pending_screenshots() - self.assertEqual(['foo'], pending_screenshots) + self.assertEqual(1, len(pending_screenshots)) + self.assertTrue(os.path.exists(os.path.join(os.getenv("screenshots_dir"), pending_screenshots[0]))) def test_clear(self): ScreenshotsStore.capture() @@ -523,12 +528,14 @@ def test_clear(self): def test_pending_screenshots_gives_only_those_screenshots_which_are_not_collected(self): ScreenshotsStore.capture() pending_screenshots = ScreenshotsStore.pending_screenshots() - self.assertEqual(['foo'], pending_screenshots) + self.assertEqual(1, len(pending_screenshots)) + screenshot_file = pending_screenshots[0] pending_screenshots = ScreenshotsStore.pending_screenshots() - self.assertEqual([], pending_screenshots) + self.assertEqual(0, len(pending_screenshots)) ScreenshotsStore.capture() pending_screenshots = ScreenshotsStore.pending_screenshots() - self.assertEqual(['foo'], pending_screenshots) + self.assertEqual(1, len(pending_screenshots)) + self.assertNotEqual(screenshot_file, pending_screenshots[0]) if __name__ == '__main__': From f0b8c229a25b128732224fab0f9bc13274f8f728 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Mon, 9 Dec 2019 15:20:14 +0530 Subject: [PATCH 02/12] Introduced an API for file based screenshot grabber. getgauge/gauge#1476 --- getgauge/python.py | 12 ++++++++---- getgauge/registry.py | 21 ++++++++++++++------- tests/test_python.py | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/getgauge/python.py b/getgauge/python.py index 2e827e2..56ce0fa 100644 --- a/getgauge/python.py +++ b/getgauge/python.py @@ -56,19 +56,23 @@ def after_step(obj=None): def screenshot(func): - _warn_screenshot_deprecation() - registry.set_screenshot_provider(func) + _warn_screenshot_deprecation('screenshot', 'file_based_screen_grabber') + registry.set_screenshot_provider(func, False) return func def custom_screen_grabber(func): + _warn_screenshot_deprecation('custom_screen_grabber', 'file_based_screen_grabber') registry.set_screenshot_provider(func, False) return func +def file_based_screen_grabber(func): + registry.set_screenshot_provider(func, True) + return func -def _warn_screenshot_deprecation(): +def _warn_screenshot_deprecation(old_function, new_function): warnings.warn( - "'screenshot' is deprecated in favour of 'custom_screen_grabber'", + "'{0}' is deprecated in favour of '{1}'".format(old_function, new_function), DeprecationWarning, stacklevel=3) warnings.simplefilter('default', DeprecationWarning) diff --git a/getgauge/registry.py b/getgauge/registry.py index 9eecda5..ce907a7 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -2,7 +2,6 @@ import os import re import sys -import tempfile from uuid import uuid1 from subprocess import call @@ -262,15 +261,23 @@ def capture(): @staticmethod def capture_to_file(): - content = registry.screenshot_provider()() if not registry.is_file_based_screenshot: - temp_file_name = "screenshot-%s.png"%(uuid1().int) - temp_file = os.path.join(os.getenv('screenshots_dir'), temp_file_name) - file = open(temp_file, "w") + screenshot_file = "screenshot-%s.png" % (uuid1().int) + screenshot_file_path = os.path.join( + os.getenv('screenshots_dir'), screenshot_file) + content = registry.screenshot_provider()() + file = open(screenshot_file_path, "w") file.write(content) file.close() - content = temp_file_name - return content + return screenshot_file + screenshot_file = registry.screenshot_provider()() + if(not os.path.isabs(screenshot_file)): + screenshot_file = os.path.join( + os.getenv("screenshots_dir"), screenshot_file) + if(not os.path.exists(screenshot_file)): + raise Exception( + "Screenshot file {0} does not exists.".format(screenshot_file)) + return os.path.basename(screenshot_file) @staticmethod def clear(): diff --git a/tests/test_python.py b/tests/test_python.py index 300f056..aa57405 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -6,6 +6,7 @@ DataStoreContainer, data_store, Table, Specification, Scenario, Step, ExecutionContext, create_execution_context_from) +from uuid import uuid1 import os import tempfile try: @@ -511,13 +512,16 @@ def test_screenshot_decorator(self): class ScreenshotsTests(TestCase): def setUp(self): + self.__old_screenshot_provider = registry.screenshot_provider() + self.__is_file_based_screenshot = registry.is_file_based_screenshot os.environ["screenshots_dir"] = tempfile.mkdtemp() def test_pending_screenshots(self): ScreenshotsStore.capture() pending_screenshots = ScreenshotsStore.pending_screenshots() self.assertEqual(1, len(pending_screenshots)) - self.assertTrue(os.path.exists(os.path.join(os.getenv("screenshots_dir"), pending_screenshots[0]))) + self.assertTrue(os.path.exists(os.path.join( + os.getenv("screenshots_dir"), pending_screenshots[0]))) def test_clear(self): ScreenshotsStore.capture() @@ -537,6 +541,42 @@ def test_pending_screenshots_gives_only_those_screenshots_which_are_not_collecte self.assertEqual(1, len(pending_screenshots)) self.assertNotEqual(screenshot_file, pending_screenshots[0]) + def test_capture_shoould_vefify_screenshot_file_for_file_based_custom_screenshot(self): + def returns_abs_path(): + file = open(os.path.join(os.getenv("screenshots_dir"), + "screenshot{0}.png".format(uuid1())), "w") + file.write("screenshot data") + return file.name + + def returns_base_ath(): + file_name = "screenshot{0}.png".format(uuid1()) + file = open(os.path.join( + os.getenv("screenshots_dir"), file_name), "w") + file.write("screenshot data") + return file_name + registry.set_screenshot_provider(returns_abs_path, True) + ScreenshotsStore.capture() + self.assertEqual(1, len(ScreenshotsStore.pending_screenshots())) + + registry.set_screenshot_provider(returns_base_ath, True) + ScreenshotsStore.capture() + self.assertEqual(1, len(ScreenshotsStore.pending_screenshots())) + + def test_capture_should_raise_exception_when_screenshot_file_does_not_exists(self): + def take_screenshot(): + return "this_file_does_not_exists.png" + registry.set_screenshot_provider(take_screenshot, True) + with self.assertRaises(Exception) as cm: + ScreenshotsStore.capture() + message = "Screenshot file {0} does not exists.".format( + os.path.join(os.getenv("screenshots_dir"), + 'this_file_does_not_exists.png') + ) + self.assertEqual(message, cm.exception.message) + + def tearDown(self): + registry.set_screenshot_provider(self.__old_screenshot_provider, self.__is_file_based_screenshot) + if __name__ == '__main__': main() From 35901116d4fe092a872b475e108153b31720e83c Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Mon, 9 Dec 2019 15:30:08 +0530 Subject: [PATCH 03/12] Fixed file based screenshot test --- tests/test_python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_python.py b/tests/test_python.py index aa57405..b260c3c 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -572,7 +572,7 @@ def take_screenshot(): os.path.join(os.getenv("screenshots_dir"), 'this_file_does_not_exists.png') ) - self.assertEqual(message, cm.exception.message) + self.assertEqual(message, cm.exception.__str__()) def tearDown(self): registry.set_screenshot_provider(self.__old_screenshot_provider, self.__is_file_based_screenshot) From db4bb940ca2ce65eb4441a03f044e5f3678b3e0f Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Mon, 9 Dec 2019 15:45:06 +0530 Subject: [PATCH 04/12] Install html-report from source. --- .github/workflows/tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7f6de27..f001512 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -71,6 +71,13 @@ jobs: go run -mod=vendor build/make.go --install --prefix=/tmp/gauge --verbose echo "::add-path::/tmp/gauge/bin" + - name: Install html report + run: | + git clone --depth=1 https://github.com/getgauge/html-report + cd html-report + go run build/make.go + go run build/make.go --install + - name: Install Python run: | pip install -r requirements.txt From 23f41d3244593b968334ae211fa8a8901aea89e6 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Mon, 9 Dec 2019 17:04:08 +0530 Subject: [PATCH 05/12] Clone gauge-tests from fileBasedScreenshot branch --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f001512..302106e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,7 +85,7 @@ jobs: - name: Prep FTs run: | - git clone https://github.com/getgauge/gauge-tests + git clone --branch=fileBasedScreenshot https://github.com/getgauge/gauge-tests cd gauge-tests gauge install From d459c52697d79eb194df565cf72a7f6d2dcdeec4 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 10 Dec 2019 18:38:16 +0530 Subject: [PATCH 06/12] Log warrning message when screenshot is not found. getgauge/gauge#1476 --- getgauge/registry.py | 3 +-- tests/test_python.py | 37 ++++++++++++++++--------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/getgauge/registry.py b/getgauge/registry.py index ce907a7..e3ed097 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -275,8 +275,7 @@ def capture_to_file(): screenshot_file = os.path.join( os.getenv("screenshots_dir"), screenshot_file) if(not os.path.exists(screenshot_file)): - raise Exception( - "Screenshot file {0} does not exists.".format(screenshot_file)) + logger.warning("Screenshot file {0} does not exists.".format(screenshot_file)) return os.path.basename(screenshot_file) @staticmethod diff --git a/tests/test_python.py b/tests/test_python.py index b260c3c..c80d1d2 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -542,40 +542,35 @@ def test_pending_screenshots_gives_only_those_screenshots_which_are_not_collecte self.assertNotEqual(screenshot_file, pending_screenshots[0]) def test_capture_shoould_vefify_screenshot_file_for_file_based_custom_screenshot(self): + first_screenshot = os.path.join( + os.getenv("screenshots_dir"), "screenshot{0}.png".format(uuid1())) + second_screenshot = os.path.join( + os.getenv("screenshots_dir"), "screenshot{0}.png".format(uuid1())) + def returns_abs_path(): - file = open(os.path.join(os.getenv("screenshots_dir"), - "screenshot{0}.png".format(uuid1())), "w") + file = open(first_screenshot, "w") file.write("screenshot data") + file.close() return file.name def returns_base_ath(): - file_name = "screenshot{0}.png".format(uuid1()) - file = open(os.path.join( - os.getenv("screenshots_dir"), file_name), "w") + file = open(second_screenshot, "w") file.write("screenshot data") - return file_name + file.close() + return os.path.basename(file.name) registry.set_screenshot_provider(returns_abs_path, True) ScreenshotsStore.capture() - self.assertEqual(1, len(ScreenshotsStore.pending_screenshots())) + self.assertEqual([os.path.basename(first_screenshot)], + ScreenshotsStore.pending_screenshots()) registry.set_screenshot_provider(returns_base_ath, True) ScreenshotsStore.capture() - self.assertEqual(1, len(ScreenshotsStore.pending_screenshots())) - - def test_capture_should_raise_exception_when_screenshot_file_does_not_exists(self): - def take_screenshot(): - return "this_file_does_not_exists.png" - registry.set_screenshot_provider(take_screenshot, True) - with self.assertRaises(Exception) as cm: - ScreenshotsStore.capture() - message = "Screenshot file {0} does not exists.".format( - os.path.join(os.getenv("screenshots_dir"), - 'this_file_does_not_exists.png') - ) - self.assertEqual(message, cm.exception.__str__()) + self.assertEqual([os.path.basename(second_screenshot)], + ScreenshotsStore.pending_screenshots()) def tearDown(self): - registry.set_screenshot_provider(self.__old_screenshot_provider, self.__is_file_based_screenshot) + registry.set_screenshot_provider( + self.__old_screenshot_provider, self.__is_file_based_screenshot) if __name__ == '__main__': From e01085ed99f79cd71f6e71740b1c66170669c445 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Wed, 11 Dec 2019 11:12:47 +0530 Subject: [PATCH 07/12] Extracted generation of unique screenshot file name into a function. getgauge/gauge#1476 --- getgauge/registry.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/getgauge/registry.py b/getgauge/registry.py index e3ed097..e3aad2f 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -228,11 +228,10 @@ def _get_step_value(step_text): def _take_screenshot(): - temp_file_name = "screenshot-%s.png"%(uuid1().int) - temp_file = os.path.join(os.getenv('screenshots_dir'), temp_file_name) + temp_file = _uniqe_screenshot_file() try: call(['gauge_screenshot', temp_file]) - return temp_file_name + return os.path.basename(temp_file) except Exception as err: logger.error( "\nFailed to take screenshot using gauge_screenshot.\n{0}".format(err)) @@ -262,18 +261,15 @@ def capture(): @staticmethod def capture_to_file(): if not registry.is_file_based_screenshot: - screenshot_file = "screenshot-%s.png" % (uuid1().int) - screenshot_file_path = os.path.join( - os.getenv('screenshots_dir'), screenshot_file) + screenshot_file = _uniqe_screenshot_file() content = registry.screenshot_provider()() - file = open(screenshot_file_path, "w") + file = open(screenshot_file, "w") file.write(content) file.close() - return screenshot_file + return os.path.basename(screenshot_file) screenshot_file = registry.screenshot_provider()() if(not os.path.isabs(screenshot_file)): - screenshot_file = os.path.join( - os.getenv("screenshots_dir"), screenshot_file) + screenshot_file = os.path.join(_screenshots_dir(), screenshot_file) if(not os.path.exists(screenshot_file)): logger.warning("Screenshot file {0} does not exists.".format(screenshot_file)) return os.path.basename(screenshot_file) @@ -281,3 +277,9 @@ def capture_to_file(): @staticmethod def clear(): ScreenshotsStore.__screenshots = [] + +def _uniqe_screenshot_file(): + return os.path.join(_screenshots_dir(), "screenshot-{0}.png".format(uuid1().int)) + +def _screenshots_dir(): + return os.getenv('screenshots_dir') \ No newline at end of file From c1acc487d6eb0213ea3a0c98ab36833ca814135a Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 17 Dec 2019 15:10:42 +0530 Subject: [PATCH 08/12] Rename file_based_screen_grabber to custom_screenshot_writer getgauge/gauge#1476 --- getgauge/python.py | 6 +++--- getgauge/registry.py | 8 ++++---- tests/test_python.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/getgauge/python.py b/getgauge/python.py index 56ce0fa..6431a68 100644 --- a/getgauge/python.py +++ b/getgauge/python.py @@ -56,17 +56,17 @@ def after_step(obj=None): def screenshot(func): - _warn_screenshot_deprecation('screenshot', 'file_based_screen_grabber') + _warn_screenshot_deprecation('screenshot', 'custom_screenshot_writer') registry.set_screenshot_provider(func, False) return func def custom_screen_grabber(func): - _warn_screenshot_deprecation('custom_screen_grabber', 'file_based_screen_grabber') + _warn_screenshot_deprecation('custom_screen_grabber', 'custom_screenshot_writer') registry.set_screenshot_provider(func, False) return func -def file_based_screen_grabber(func): +def custom_screenshot_writer(func): registry.set_screenshot_provider(func, True) return func diff --git a/getgauge/registry.py b/getgauge/registry.py index e3aad2f..a9d5a9d 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -107,7 +107,7 @@ class Registry(object): def __init__(self): self.__screenshot_provider, self.__steps_map, self.__continue_on_failures = _take_screenshot, {}, {} - self.is_file_based_screenshot = True + self.is_screenshot_writer = True for hook in Registry.hooks: self.__def_hook(hook) @@ -151,9 +151,9 @@ def get_info_for(self, step_text): def get_infos_for(self, step_text): return self.__steps_map.get(step_text) - def set_screenshot_provider(self, func, is_file_based): + def set_screenshot_provider(self, func, is_writer): self.__screenshot_provider = func - self.is_file_based_screenshot = is_file_based + self.is_screenshot_writer = is_writer def screenshot_provider(self): return self.__screenshot_provider @@ -260,7 +260,7 @@ def capture(): @staticmethod def capture_to_file(): - if not registry.is_file_based_screenshot: + if not registry.is_screenshot_writer: screenshot_file = _uniqe_screenshot_file() content = registry.screenshot_provider()() file = open(screenshot_file, "w") diff --git a/tests/test_python.py b/tests/test_python.py index c80d1d2..92b859f 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -513,7 +513,7 @@ def test_screenshot_decorator(self): class ScreenshotsTests(TestCase): def setUp(self): self.__old_screenshot_provider = registry.screenshot_provider() - self.__is_file_based_screenshot = registry.is_file_based_screenshot + self.__is_screenshot_writer = registry.is_screenshot_writer os.environ["screenshots_dir"] = tempfile.mkdtemp() def test_pending_screenshots(self): @@ -570,7 +570,7 @@ def returns_base_ath(): def tearDown(self): registry.set_screenshot_provider( - self.__old_screenshot_provider, self.__is_file_based_screenshot) + self.__old_screenshot_provider, self.__is_screenshot_writer) if __name__ == '__main__': From 6677ddc16417b3ef16a3304c50f313cf4ba351e0 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 17 Dec 2019 15:20:25 +0530 Subject: [PATCH 09/12] Return bytearray in test data --- getgauge/registry.py | 2 +- tests/test_data/impl_stubs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/getgauge/registry.py b/getgauge/registry.py index a9d5a9d..56a8e9b 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -263,7 +263,7 @@ def capture_to_file(): if not registry.is_screenshot_writer: screenshot_file = _uniqe_screenshot_file() content = registry.screenshot_provider()() - file = open(screenshot_file, "w") + file = open(screenshot_file, "wb") file.write(content) file.close() return os.path.basename(screenshot_file) diff --git a/tests/test_data/impl_stubs.py b/tests/test_data/impl_stubs.py index f747043..457c4cd 100644 --- a/tests/test_data/impl_stubs.py +++ b/tests/test_data/impl_stubs.py @@ -87,4 +87,4 @@ def after_suite2(): @custom_screen_grabber def take_screenshot(): - return "foo" + return bytearray("foo", "utf-8") From 4b6c5926a02bb93053d31f8b1df1a716a6030f28 Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 17 Dec 2019 15:22:21 +0530 Subject: [PATCH 10/12] Avoid creating file in tests --- tests/test_python.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_python.py b/tests/test_python.py index 92b859f..c31e0fe 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -548,16 +548,10 @@ def test_capture_shoould_vefify_screenshot_file_for_file_based_custom_screenshot os.getenv("screenshots_dir"), "screenshot{0}.png".format(uuid1())) def returns_abs_path(): - file = open(first_screenshot, "w") - file.write("screenshot data") - file.close() - return file.name + return first_screenshot def returns_base_ath(): - file = open(second_screenshot, "w") - file.write("screenshot data") - file.close() - return os.path.basename(file.name) + return os.path.basename(second_screenshot) registry.set_screenshot_provider(returns_abs_path, True) ScreenshotsStore.capture() self.assertEqual([os.path.basename(first_screenshot)], From 0251f6485af6aead80972c2c039a993c5e826f1b Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 17 Dec 2019 17:20:16 +0530 Subject: [PATCH 11/12] Install gauge from plugin-grpc branch --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 302106e..ba45279 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,7 @@ jobs: - name: Clone gauge run: | - git clone --depth=1 https://github.com/getgauge/gauge + git clone --depth=1 --branch=plugin-grpc https://github.com/getgauge/gauge - name: Build gauge run: | From 53bab1ee97591fe2c3bb77b92de00848565e0a6c Mon Sep 17 00:00:00 2001 From: Dharmendra Singh Date: Tue, 17 Dec 2019 17:57:25 +0530 Subject: [PATCH 12/12] Revert "Install gauge from plugin-grpc branch" This reverts commit 0251f6485af6aead80972c2c039a993c5e826f1b. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ba45279..302106e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,7 @@ jobs: - name: Clone gauge run: | - git clone --depth=1 --branch=plugin-grpc https://github.com/getgauge/gauge + git clone --depth=1 https://github.com/getgauge/gauge - name: Build gauge run: |