当前位置: 首页>>代码示例>>Python>>正文


Python VisualTest.assert_screenshot方法代码示例

本文整理汇总了Python中toolium.visual_test.VisualTest.assert_screenshot方法的典型用法代码示例。如果您正苦于以下问题:Python VisualTest.assert_screenshot方法的具体用法?Python VisualTest.assert_screenshot怎么用?Python VisualTest.assert_screenshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在toolium.visual_test.VisualTest的用法示例。


在下文中一共展示了VisualTest.assert_screenshot方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_no_enabled

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_no_enabled(driver_wrapper):
    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('VisualTests', 'enabled', 'false')
    visual = VisualTest(driver_wrapper)

    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    driver_wrapper.driver.save_screenshot.assert_not_called()
开发者ID:jframos,项目名称:toolium,代码行数:9,代码来源:test_visual_test.py

示例2: test_assert_screenshot_mobile_web_resize_and_exclude

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_mobile_web_resize_and_exclude(driver_wrapper):
    # Create elements mock
    driver_wrapper.driver.execute_script.return_value = 0  # scrollX=0 and scrollY=0
    form_element = get_mock_element(x=0, y=0, height=559, width=375)
    exclude_elements = [get_mock_element(x=15, y=296.515625, height=32, width=345)]

    # Configure driver mock
    file_ios_web = os.path.join(root_path, 'resources', 'ios_web.png')
    with open(file_ios_web, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data
    driver_wrapper.driver.get_window_size.return_value = {'width': 375, 'height': 667}

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('Driver', 'type', 'ios')
    driver_wrapper.config.set('AppiumCapabilities', 'browserName', 'safari')
    visual = VisualTest(driver_wrapper)

    # Assert screenshot
    visual.assert_screenshot(form_element, filename='screenshot_ios_web', file_suffix='screenshot_suffix',
                             exclude_elements=exclude_elements)
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()

    # Check cropped image
    expected_image = os.path.join(root_path, 'resources', 'ios_web_exclude.png')
    output_file = os.path.join(visual.output_directory, '01_screenshot_ios_web__screenshot_suffix.png')
    MagickEngine().assertSameFiles(output_file, expected_image, 0.1)

    # Output image and new baseline image must be equal
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_ios_web.png')
    MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
开发者ID:jframos,项目名称:toolium,代码行数:33,代码来源:test_visual_test.py

示例3: test_assert_screenshot_mobile_resize_and_exclude

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_mobile_resize_and_exclude(driver_wrapper):
    # Create elements mock
    exclude_elements = [get_mock_element(x=0, y=0, height=24, width=375)]

    # Configure driver mock
    with open(file_ios, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data
    driver_wrapper.driver.get_window_size.return_value = {'width': 375, 'height': 667}

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('Driver', 'type', 'ios')
    visual = VisualTest(driver_wrapper)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_ios', file_suffix='screenshot_suffix',
                             exclude_elements=exclude_elements)
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()

    # Check cropped image
    expected_image = os.path.join(root_path, 'resources', 'ios_excluded.png')
    output_file = os.path.join(visual.output_directory, '01_screenshot_ios__screenshot_suffix.png')
    PilEngine().assertSameFiles(output_file, expected_image, 0.1)

    # Output image and new baseline image must be equals
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox',
                                 'screenshot_ios.png')
    PilEngine().assertSameFiles(output_file, baseline_file, 0.1)
开发者ID:Telefonica,项目名称:toolium,代码行数:30,代码来源:test_visual_test.py

示例4: test_assert_screenshot_no_enabled_force

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_no_enabled_force(driver_wrapper):
    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('VisualTests', 'enabled', 'false')
    visual = VisualTest(driver_wrapper, force=True)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()
开发者ID:jframos,项目名称:toolium,代码行数:15,代码来源:test_visual_test.py

示例5: test_assert_screenshot_full_and_compare

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_full_and_compare(driver_wrapper):
    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data
    visual = VisualTest(driver_wrapper)

    # Add baseline image
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_full.png')
    shutil.copyfile(file_v1, baseline_file)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()
开发者ID:jframos,项目名称:toolium,代码行数:16,代码来源:test_visual_test.py

示例6: test_assert_screenshot_full_and_save_baseline

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_full_and_save_baseline(driver_wrapper):
    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data
    visual = VisualTest(driver_wrapper)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    output_file = os.path.join(visual.output_directory, '01_screenshot_full__screenshot_suffix.png')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()

    # Output image and new baseline image must be equal
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_full.png')
    MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
开发者ID:jframos,项目名称:toolium,代码行数:17,代码来源:test_visual_test.py

示例7: test_assert_screenshot_no_enabled_force

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_no_enabled_force(driver_wrapper):
    # Configure driver mock
    def copy_file_side_effect(output_file):
        shutil.copyfile(file_v1, output_file)

    driver_wrapper.driver.save_screenshot.side_effect = copy_file_side_effect

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('VisualTests', 'enabled', 'false')
    visual = VisualTest(driver_wrapper, force=True)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    output_file = os.path.join(visual.output_directory, '01_screenshot_full__screenshot_suffix.png')
    driver_wrapper.driver.save_screenshot.assert_called_once_with(output_file)
开发者ID:Telefonica,项目名称:toolium,代码行数:17,代码来源:test_visual_test.py

示例8: test_assert_screenshot_full_and_compare

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_full_and_compare(driver_wrapper):
    # Configure driver mock
    def copy_file_side_effect(output_file):
        shutil.copyfile(file_v1, output_file)

    driver_wrapper.driver.save_screenshot.side_effect = copy_file_side_effect
    visual = VisualTest(driver_wrapper)

    # Add baseline image
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox',
                                 'screenshot_full.png')
    shutil.copyfile(file_v1, baseline_file)

    # Assert screenshot
    visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    output_file = os.path.join(visual.output_directory, '01_screenshot_full__screenshot_suffix.png')
    driver_wrapper.driver.save_screenshot.assert_called_once_with(output_file)
开发者ID:Telefonica,项目名称:toolium,代码行数:19,代码来源:test_visual_test.py

示例9: test_assert_screenshot_element_and_compare

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_element_and_compare(driver_wrapper):
    # Add baseline image
    driver_wrapper.driver.execute_script.return_value = 0  # scrollX=0 and scrollY=0
    visual = VisualTest(driver_wrapper)
    expected_image = os.path.join(root_path, 'resources', 'register_cropped_element.png')
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_elem.png')
    shutil.copyfile(expected_image, baseline_file)

    # Create element mock
    web_element = get_mock_element(x=250, y=40, height=40, width=300)

    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data

    # Assert screenshot
    visual.assert_screenshot(web_element, filename='screenshot_elem', file_suffix='screenshot_suffix')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()
开发者ID:jframos,项目名称:toolium,代码行数:21,代码来源:test_visual_test.py

示例10: test_assert_screenshot_no_enabled_force_fail

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_no_enabled_force_fail(driver_wrapper):
    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('VisualTests', 'fail', 'false')
    driver_wrapper.config.set('VisualTests', 'enabled', 'false')
    visual = VisualTest(driver_wrapper, force=True)

    # Add v2 baseline image
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_full.png')
    shutil.copyfile(file_v2, baseline_file)

    # Assert screenshot
    with pytest.raises(AssertionError):
        visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()
开发者ID:jframos,项目名称:toolium,代码行数:21,代码来源:test_visual_test.py

示例11: test_assert_screenshot_no_enabled_force_fail

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_no_enabled_force_fail(driver_wrapper):
    # Configure driver mock
    def copy_file_side_effect(output_file):
        shutil.copyfile(file_v1, output_file)

    driver_wrapper.driver.save_screenshot.side_effect = copy_file_side_effect

    # Update conf and create a new VisualTest instance
    driver_wrapper.config.set('VisualTests', 'fail', 'false')
    driver_wrapper.config.set('VisualTests', 'enabled', 'false')
    visual = VisualTest(driver_wrapper, force=True)

    # Add v2 baseline image
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_full.png')
    shutil.copyfile(file_v2, baseline_file)

    # Assert screenshot
    with pytest.raises(AssertionError):
        visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
    output_file = os.path.join(visual.output_directory, '01_screenshot_full__screenshot_suffix.png')
    driver_wrapper.driver.save_screenshot.assert_called_once_with(output_file)
开发者ID:Telefonica,项目名称:toolium,代码行数:23,代码来源:test_visual_test.py

示例12: test_assert_screenshot_element_and_save_baseline

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_element_and_save_baseline(driver_wrapper):
    # Create element mock
    driver_wrapper.driver.execute_script.return_value = 0  # scrollX=0 and scrollY=0
    web_element = get_mock_element(x=250, y=40, height=40, width=300)

    # Configure driver mock
    with open(file_v1, "rb") as f:
        image_data = f.read()
    driver_wrapper.driver.get_screenshot_as_png.return_value = image_data
    visual = VisualTest(driver_wrapper)

    # Assert screenshot
    visual.assert_screenshot(web_element, filename='screenshot_elem', file_suffix='screenshot_suffix')
    driver_wrapper.driver.get_screenshot_as_png.assert_called_once_with()

    # Check cropped image
    expected_image = os.path.join(root_path, 'resources', 'register_cropped_element.png')
    output_file = os.path.join(visual.output_directory, '01_screenshot_elem__screenshot_suffix.png')
    MagickEngine().assertSameFiles(output_file, expected_image, 0.1)

    # Output image and new baseline image must be equal
    baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_elem.png')
    MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
开发者ID:jframos,项目名称:toolium,代码行数:25,代码来源:test_visual_test.py

示例13: test_assert_screenshot_greater_threshold

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
def test_assert_screenshot_greater_threshold(driver_wrapper):
    visual = VisualTest(driver_wrapper)
    with pytest.raises(TypeError):
        visual.assert_screenshot(None, 'screenshot_full', threshold=2)
开发者ID:jframos,项目名称:toolium,代码行数:6,代码来源:test_visual_test.py

示例14: VisualTests

# 需要导入模块: from toolium.visual_test import VisualTest [as 别名]
# 或者: from toolium.visual_test.VisualTest import assert_screenshot [as 别名]
class VisualTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # Get file paths
        cls.root_path = os.path.dirname(os.path.realpath(__file__))
        cls.file_v1 = os.path.join(cls.root_path, 'resources', 'register.png')
        cls.file_v2 = os.path.join(cls.root_path, 'resources', 'register_v2.png')
        cls.file_small = os.path.join(cls.root_path, 'resources', 'register_small.png')
        cls.file_ios = os.path.join(cls.root_path, 'resources', 'ios.png')

    def setUp(self):
        # Remove previous visual path
        visual_path = os.path.join(self.root_path, 'output', 'visualtests')
        if os.path.exists(visual_path):
            shutil.rmtree(visual_path)

        # Reset wrappers pool values
        DriverWrappersPool._empty_pool()
        DriverWrapper.config_properties_filenames = None

        # Create a new wrapper
        self.driver_wrapper = DriverWrappersPool.get_default_wrapper()
        self.driver_wrapper.driver = mock.MagicMock()

        # Configure properties
        config_files = ConfigFiles()
        config_files.set_config_directory(os.path.join(self.root_path, 'conf'))
        config_files.set_config_properties_filenames('properties.cfg')
        config_files.set_output_directory(os.path.join(self.root_path, 'output'))
        self.driver_wrapper.configure(tc_config_files=config_files)
        self.driver_wrapper.config.set('VisualTests', 'enabled', 'true')

        # Create a new VisualTest instance
        self.visual = VisualTest(self.driver_wrapper)

    @classmethod
    def tearDownClass(cls):
        # Remove visual path
        visual_path = os.path.join(cls.root_path, 'output', 'visualtests')
        if os.path.exists(visual_path):
            shutil.rmtree(visual_path)

        # Reset wrappers pool values
        DriverWrappersPool._empty_pool()
        DriverWrapper.config_properties_filenames = None

    def test_no_enabled(self):
        # Update conf and create a new VisualTest instance
        self.driver_wrapper.config.set('VisualTests', 'enabled', 'false')
        self.visual = VisualTest(self.driver_wrapper)

        self.visual.assert_screenshot(None, filename='screenshot_full', file_suffix='screenshot_suffix')
        self.driver_wrapper.driver.save_screenshot.assert_not_called()

    def test_engine_pil(self):
        assert_is_instance(self.visual.engine, PilEngine)

    def test_engine_perceptual(self):
        # Update conf and create a new VisualTest instance
        self.driver_wrapper.config.set('VisualTests', 'engine', 'perceptualdiff')
        self.visual = VisualTest(self.driver_wrapper)

        assert_is_instance(self.visual.engine, PerceptualEngine)

    # def test_engine_magick(self):
    #    self.driver_wrapper.config.set('VisualTests', 'engine', 'imagemagick')
    #    visual = VisualTest()
    #    assert_is_instance(visual.engine, MagickEngine)

    def test_engine_empty(self):
        # Update conf and create a new VisualTest instance
        self.driver_wrapper.config.set('VisualTests', 'engine', '')
        self.visual = VisualTest(self.driver_wrapper)

        assert_is_instance(self.visual.engine, PilEngine)

    def test_engine_unknown(self):
        # Update conf and create a new VisualTest instance
        self.driver_wrapper.config.set('VisualTests', 'engine', 'unknown')
        self.visual = VisualTest(self.driver_wrapper)

        assert_is_instance(self.visual.engine, PilEngine)

    def test_compare_files_equals(self):
        message = self.visual.compare_files(self._testMethodName, self.file_v1, self.file_v1, 0)
        assert_is_none(message)

    def test_compare_files_diff(self):
        message = self.visual.compare_files(self._testMethodName, self.file_v1, self.file_v2, 0)
        assert_in('by a distance of 522.65', message)

    def test_compare_files_diff_fail(self):
        # Update conf and create a new VisualTest instance
        self.driver_wrapper.config.set('VisualTests', 'fail', 'true')
        self.visual = VisualTest(self.driver_wrapper)

        with assert_raises(AssertionError):
            self.visual.compare_files(self._testMethodName, self.file_v1, self.file_v2, 0)

    def test_compare_files_size(self):
#.........这里部分代码省略.........
开发者ID:cesarca,项目名称:toolium,代码行数:103,代码来源:test_visual_test.py


注:本文中的toolium.visual_test.VisualTest.assert_screenshot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。