Esempio n. 1
0
class ResizeTestCase(unittest.TestCase):
    def setUp(self):
        # NOTE current_directory is used in webserver setup
        self.current_directory = os.path.dirname(os.path.abspath(__file__))

    def tearDown(self):
        self.driver.quit()

    def test_core_screenshot_resize_firefox(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.FIREFOX,
            command_executor="http://{host}:{port}/wd/hub".format(
                host=Config.server, port=Config.port))
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url,
                       json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width,
                                                          height=height)
            self.assertEqual(resolution, actual_resolution)

    def test_core_screenshot_resize_chrome(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.CHROME,
            command_executor="http://{host}:{port}/wd/hub".format(
                host=Config.server, port=Config.port))
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url,
                       json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width,
                                                          height=height)
            self.assertEqual(resolution, actual_resolution)

    @unittest.expectedFailure
    def test_core_screenshot_resize_opera(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.OPERA,
            command_executor="http://{host}:{port}/wd/hub".format(
                host=Config.server, port=Config.port))
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url,
                       json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width,
                                                          height=height)
            self.assertEqual(resolution, actual_resolution)

    def test_core_screenshot_resize_internetexplorer(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER,
            command_executor="http://{host}:{port}/wd/hub".format(
                host=Config.server, port=Config.port))
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url,
                       json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width,
                                                          height=height)
            self.assertEqual(resolution, actual_resolution)
Esempio n. 2
0
class ResizeTestCase(unittest.TestCase):
    def setUp(self):
        # NOTE current_directory is used in webserver setup
        self.current_directory = os.path.dirname(os.path.abspath(__file__))

    def tearDown(self):
        self.driver.quit()


    def test_core_screenshot_resize_firefox(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.FIREFOX,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width, height=height)
            self.assertEqual(resolution, actual_resolution)

    def test_core_screenshot_resize_chrome(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.CHROME,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width, height=height)
            self.assertEqual(resolution, actual_resolution)

    @unittest.expectedFailure
    def test_core_screenshot_resize_opera(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.OPERA,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width, height=height)
            self.assertEqual(resolution, actual_resolution)

    def test_core_screenshot_resize_internetexplorer(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        resolutions = ["800x600", "1024x768", "1280x1024", "1366x768"]
        for resolution in resolutions:
            self.core.resize(resolution)
            size = self.driver.get_window_size()
            width = size["width"]
            height = size["height"]
            actual_resolution = "{width}x{height}".format(width=width, height=height)
            self.assertEqual(resolution, actual_resolution)
Esempio n. 3
0
class ScreenshotTestCase(BrowserTestCase):
    def setUp(self):
        # NOTE current_directory is used in webserver setup
        self.current_directory = os.path.dirname(os.path.abspath(__file__))
        super(ScreenshotTestCase, self).setUp()

    def tearDown(self):
        self.driver.quit()
        try:
            os.remove(self.first_screenshot)
        except (OSError, AttributeError):
            pass
        try:
            os.remove(self.second_screenshot)
        except (OSError, AttributeError):
            pass

        super(ScreenshotTestCase, self).tearDown()


    def test_core_screenshot_image_firefox(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.FIREFOX,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        self.load_page("picture1")
        self.first_screenshot = self.core.take(self.current_directory, TOptions())
        self.second_screenshot = self.core.take(self.current_directory, TOptions())

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_image_chrome(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.CHROME,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        self.load_page("picture1")
        self.first_screenshot = self.core.take(self.current_directory, TOptions())
        self.second_screenshot = self.core.take(self.current_directory, TOptions())

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_image_opera(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.OPERA,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        self.load_page("picture1")
        self.first_screenshot = self.core.take(self.current_directory, TOptions())
        self.second_screenshot = self.core.take(self.current_directory, TOptions())

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_image_internetexplorer(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        self.load_page("picture1")
        self.first_screenshot = self.core.take(self.current_directory, TOptions())
        self.second_screenshot = self.core.take(self.current_directory, TOptions())

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_disable_animation_firefox(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.FIREFOX,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        option = TOptions(disable_animation=True)

        self.load_page("animation")
        self.first_screenshot = self.core.take(self.current_directory, option)

        self.load_page("animation")
        #sleep to get another state of animation
        time.sleep(0.5)
        self.second_screenshot = self.core.take(self.current_directory, option)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_disable_animation_chrome(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.CHROME,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        option = TOptions(disable_animation=True)

        self.load_page("animation")
        self.first_screenshot = self.core.take(self.current_directory, option)

        self.load_page("animation")
        #sleep to get another state of animation
        time.sleep(0.5)
        self.second_screenshot = self.core.take(self.current_directory, option)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_disable_animation_opera(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.OPERA,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        option = TOptions(disable_animation=True)

        self.load_page("animation")
        self.first_screenshot = self.core.take(self.current_directory, option)

        self.load_page("animation")
        #sleep to get another state of animation
        time.sleep(0.5)
        self.second_screenshot = self.core.take(self.current_directory, option)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_disable_animation_internetexplorer(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        options = TOptions(disable_animation=True)

        self.load_page("animation")
        self.first_screenshot = self.core.take(self.current_directory, options)

        self.load_page("animation")
        #sleep to get another state of animation
        time.sleep(0.5)
        self.second_screenshot = self.core.take(self.current_directory, options)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_hide_elements_firefox(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.FIREFOX,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        options = TOptions(hide_elements=['#pic'])

        self.load_page("hide_elements1")
        self.first_screenshot = self.core.take(self.current_directory, options)

        self.load_page("hide_elements2")
        self.second_screenshot = self.core.take(self.current_directory, options)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_hide_elements_chrome(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.CHROME,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        options = TOptions(hide_elements=['#pic'])

        self.load_page("hide_elements1")
        self.first_screenshot = self.core.take(self.current_directory, options)

        self.load_page("hide_elements2")
        self.second_screenshot = self.core.take(self.current_directory, options)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_hide_elements_opera(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.OPERA,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        options = TOptions(hide_elements=['#pic'])

        self.load_page("hide_elements1")
        self.first_screenshot = self.core.take(self.current_directory, options)

        self.load_page("hide_elements2")
        self.second_screenshot = self.core.take(self.current_directory, options)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)

    def test_core_screenshot_hide_elements_internetexplorer(self):
        # Dali setup
        self.driver = Remote(
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER,
            command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port)
        )
        self.core = DaliCore()
        self.core.init(self.driver.command_executor._url, json.dumps(self.driver.capabilities))

        options = TOptions(hide_elements=['#pic'])

        self.load_page("hide_elements1")
        self.first_screenshot = self.core.take(self.current_directory, options)

        self.load_page("hide_elements2")
        self.second_screenshot = self.core.take(self.current_directory, options)

        self.assertTrue(os.path.exists(self.first_screenshot))
        self.assertTrue(os.path.exists(self.second_screenshot))

        image1 = Image.open(self.first_screenshot)
        image2 = Image.open(self.second_screenshot)

        matrix1 = numpy.asarray(image1)
        matrix2 = numpy.asarray(image2)

        numpy.testing.assert_array_equal(matrix1, matrix2)