def setUp(self): self.current_directory = os.path.dirname(os.path.abspath(__file__)) mock = WebdriverMock( command_executor_url="http://{host}:{port}/wd/hub".format( host=Config.server, port=Config.port), desired_capabilities=DesiredCapabilities.CHROME) self.dali = Dali(mock)
def test_scenario_opera(self): self.driver = Remote( desired_capabilities=DesiredCapabilities.OPERA, command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port), ) dali = Dali(self.driver) # driver can navigate through himself self.driver.get(self.page_url("colored")) self.screenshot1 = dali.take_screenshot(resolution="800x600", path_to_save=self.current_directory) # and we can use scenario with preset resolution def scenario(driver): driver.get(self.page_url("colored")) self.screenshot2 = dali.take_screenshot( resolution="800x600", scenario=scenario, scenario_args=self.driver, path_to_save=self.current_directory ) self.assertTrue(os.path.exists(self.screenshot1)) self.assertTrue(os.path.exists(self.screenshot2)) image1 = Image.open(self.screenshot1) image2 = Image.open(self.screenshot2) matrix1 = numpy.asarray(image1) matrix2 = numpy.asarray(image2) numpy.testing.assert_array_equal(matrix1, matrix2)
def test_example(self): def callback(driver): """ :type driver: Remote """ driver.implicitly_wait(5) driver.get("http://go.2gis.com/uvaw") driver.find_element_by_css_selector(".dg-traf-scores-wr").click() dali = Dali(self.driver) options1 = Options( substitute={".dg-routs>.dg-btn-label": "Lorem Ipsum"}, hide_elements=[".dg-start-banner"], disable_animation=True) options2 = Options(hide_elements=[".dg-start-banner"], disable_animation=True) file1 = dali.take_screenshot( resolution="1024x768", scenario=callback, scenario_args=self.driver, options=options1, path_to_save="./", ) file2 = dali.take_screenshot( resolution="1024x768", scenario=callback, scenario_args=self.driver, options=options2, path_to_save="./", ) diff = dali.compare_images(file1, file2, "./out.png") self.assertEquals(diff, 0.0, "The difference is %f" % diff)
class ScenarioTestCase(unittest.TestCase): def setUp(self): self.current_directory = os.path.dirname(os.path.abspath(__file__)) mock = WebdriverMock( command_executor_url="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port), desired_capabilities=DesiredCapabilities.CHROME ) self.dali = Dali(mock) def tearDown(self): pass def test_scenario_without_scenario_and_parameters(self): self.dali.run_scenario() def test_scenario_without_parameters(self): def scenario(): pass self.dali.run_scenario(scenario) def test_scenario_with_return(self): def scenario(): return 1 result = self.dali.run_scenario(scenario) self.assertEqual(1, result) def test_scenario_with_one_parameter(self): def scenario(a): return a value = 1 result = self.dali.run_scenario(scenario, value) self.assertEqual(scenario(value), result) def test_scenario_with_string_parameter(self): def scenario(str): return str.split(' ') string = "a b c" result = self.dali.run_scenario(scenario, string) self.assertEqual(scenario(string), result) def test_scenario_with_several_parameters(self): def scenario(a, b): return a + b result = self.dali.run_scenario(scenario, (1, 1)) self.assertEqual(2, result) result = self.dali.run_scenario(scenario, [1, 1]) self.assertEqual(2, result) result = self.dali.run_scenario(scenario, {'b': 1, 'a': 1}) self.assertEqual(2, result)
class ScenarioTestCase(unittest.TestCase): def setUp(self): self.current_directory = os.path.dirname(os.path.abspath(__file__)) mock = WebdriverMock( command_executor_url="http://{host}:{port}/wd/hub".format( host=Config.server, port=Config.port), desired_capabilities=DesiredCapabilities.CHROME) self.dali = Dali(mock) def tearDown(self): pass def test_scenario_without_scenario_and_parameters(self): self.dali.run_scenario() def test_scenario_without_parameters(self): def scenario(): pass self.dali.run_scenario(scenario) def test_scenario_with_return(self): def scenario(): return 1 result = self.dali.run_scenario(scenario) self.assertEqual(1, result) def test_scenario_with_one_parameter(self): def scenario(a): return a value = 1 result = self.dali.run_scenario(scenario, value) self.assertEqual(scenario(value), result) def test_scenario_with_string_parameter(self): def scenario(str): return str.split(' ') string = "a b c" result = self.dali.run_scenario(scenario, string) self.assertEqual(scenario(string), result) def test_scenario_with_several_parameters(self): def scenario(a, b): return a + b result = self.dali.run_scenario(scenario, (1, 1)) self.assertEqual(2, result) result = self.dali.run_scenario(scenario, [1, 1]) self.assertEqual(2, result) result = self.dali.run_scenario(scenario, {'b': 1, 'a': 1}) self.assertEqual(2, result)
def setUp(self): self.current_directory = os.path.dirname(os.path.abspath(__file__)) mock = WebdriverMock( command_executor_url="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port), desired_capabilities=DesiredCapabilities.CHROME ) self.dali = Dali(mock)
def test_example(self): def callback(driver): """ :type driver: Remote """ driver.implicitly_wait(5) driver.get("http://go.2gis.com/uvaw") driver.find_element_by_css_selector(".dg-traf-scores-wr").click() dali = Dali(self.driver) options1 = Options( substitute={".dg-routs>.dg-btn-label": "Lorem Ipsum"}, hide_elements=[".dg-start-banner"], disable_animation=True ) options2 = Options( hide_elements=[".dg-start-banner"], disable_animation=True ) file1 = dali.take_screenshot( resolution="1024x768", scenario=callback, scenario_args=self.driver, options=options1, path_to_save="./", ) file2 = dali.take_screenshot( resolution="1024x768", scenario=callback, scenario_args=self.driver, options=options2, path_to_save="./", ) diff = dali.compare_images(file1, file2, "./out.png") self.assertEquals(diff, 0.0, "The difference is %f" % diff)