def test_eyes_runner(driver, runner): eyes = Eyes(runner) eyes2 = Eyes(runner) eyes.server_url = "https://eyes.applitools.com/" eyes.send_dom = True eyes2.send_dom = False eyes.stitch_mode = StitchMode.CSS eyes2.stitch_mode = StitchMode.CSS batch_info = BatchInfo("Runner Testing") batch_info.id = "RCA_Batch_ID" eyes.batch_info = batch_info eyes2.batch_info = batch_info driver.get( "http://applitools.github.io/demo/TestPages/VisualGridTestPage/index.html" ) eyes.open( driver, "Applitools Eyes Java SDK", "Classic Runner Test", dict(width=1200, height=800), ) eyes2.open( driver, "Applitools Eyes Java SDK", "Classic Runner 2 Test", dict(width=1200, height=800), ) eyes.check("Step 1", Target.window().fully().ignore_displacements(False)) eyes2.check("Step 1", Target.window().fully().ignore_displacements(False)) eyes.close_async() eyes.open( driver, "Applitools Eyes Java SDK", "Classic Runner Test", dict(width=1200, height=800), ) eyes.check("Step 2", Target.window().fully().ignore_displacements(False)) eyes.close_async() eyes2.close(True) driver.quit() all_tests_results = runner.get_all_test_results() if len(all_tests_results.all_results) != 3: raise Exception
def register_or_get_batch(self, batch): # type: (Union[basestring, BatchInfo]) -> BatchInfo if isinstance(batch, basestring): return self._batch_registry.setdefault(batch, BatchInfo(batch)) elif isinstance(batch, BatchInfo): return self._batch_registry.setdefault(batch.id, batch) else: raise ValueError("Not supported `batch` value")
def test_set_value_to_conf(conf): batch = BatchInfo() ( conf.set_batch(batch) .set_branch_name("branch name") .set_agent_id("agent id") .set_parent_branch_name("parent branch name") .set_baseline_branch_name("baseline branch name") .set_baseline_env_name("baseline env name") .set_environment_name("env name") .set_save_diffs(True) .set_app_name("app name") .set_test_name("test name") .set_viewport_size({"width": 400, "height": 300}) .set_session_type(SessionType.PROGRESSION) .set_ignore_caret(False) .set_host_app("host app") .set_host_os("host os") .set_match_timeout(100000) .set_match_level(MatchLevel.EXACT) .set_ignore_displacements(True) .set_save_new_tests(False) .set_save_failed_tests(True) .set_failure_reports(FailureReports.IMMEDIATE) .set_send_dom(True) .set_use_dom(True) .set_enable_patterns(True) .set_stitch_overlap(100) .set_api_key("api key") .set_server_url("https://server.url") ) assert conf.batch == batch assert conf.server_url == "https://server.url" assert conf.api_key == "api key" assert conf.stitch_overlap == 100 assert conf.enable_patterns == True assert conf.use_dom == True assert conf.send_dom == True assert conf.failure_reports == FailureReports.IMMEDIATE assert conf.save_failed_tests == True assert conf.save_new_tests == False assert conf.match_level == MatchLevel.EXACT assert conf.match_timeout == 100000 assert conf.host_os == "host os" assert conf.host_app == "host app" assert conf.ignore_caret == False assert conf.session_type == SessionType.PROGRESSION assert conf.viewport_size == {"width": 400, "height": 300} assert conf.test_name == "test name" assert conf.app_name == "app name" assert conf.save_diffs == True assert conf.environment_name == "env name" assert conf.baseline_env_name == "baseline env name" assert conf.baseline_branch_name == "baseline branch name" assert conf.parent_branch_name == "parent branch name" assert conf.agent_id == "agent id" assert conf.branch_name == "branch name"
def test_batch_info_serializing(eyes, driver_mock): date = datetime.datetime.strptime("2019-06-04T10:27:15Z", "%Y-%m-%dT%H:%M:%SZ") eyes.batch = BatchInfo("Batch Info", date) eyes.batch.sequence_name = "Sequence" if not eyes._visual_grid_eyes: session_info = open_and_get_start_session_info(eyes, driver_mock) info_json = json_utils.to_json(session_info) batch_info = json.loads(info_json)["startInfo"]["batchInfo"] assert batch_info["name"] == "Batch Info" assert batch_info["batchSequenceName"] == "Sequence" assert batch_info["startedAt"] == "2019-06-04T10:27:15Z"
def create_eyes_batch(self, name=None, started_at=None, batch_id=None): """ Returns a BatchInfo object that may be used as batch argument on `Open Eyes Session`. For more information, read `Group tests into batches`. | =Arguments= | =Description= | | Name (str) | The name of the batch | | Started At (str or datetime) | The date and time that will be displayed in the Test Manager as the batch start time *(*)* | | Batch ID (str) | This argument groups together tests ran in different executions | The *Started At* argument may be passed as: - String: YYYY-mm-dd HH:MM:SS - Datetime variable: See [https://robotframework.org/robotframework/latest/libraries/DateTime.html|DateTime library] *(*)* Currently, due to a problem with Eyes, the Test Manager always shows the default batch start time, even when setting a custom one. *Example:* | ${batch}= | Create Eyes Batch | """ if started_at is not None: if type(started_at) is six.text_type: started_at = str(started_at) if isinstance(started_at, str): started_at = datetime.strptime(started_at, "%Y-%m-%d %H:%M:%S") print("###createbatch ###") print(name) print(started_at) print("###createbatch ###") if name is not None and started_at is not None: batch = BatchInfo(name, started_at) elif name is not None: batch = BatchInfo(name) elif started_at is not None: batch = BatchInfo(None, started_at) else: batch = BatchInfo() if batch_id is not None: batch.id = batch_id return batch
def session_start_info(): return SessionStartInfo( agent_id="eyes.core.python/3.15.4", session_type=SessionType.SEQUENTIAL, app_id_or_name="TestApp", ver_id=None, scenario_id_or_name="TestName", batch_info=BatchInfo(), baseline_env_name="Baseline env name", environment_name="Env name", environment=AppEnvironment(), default_match_settings=ImageMatchSettings( match_level=MatchLevel.STRICT), branch_name="branch Name", parent_branch_name="parentBranchName", baseline_branch_name="baselineBranchName", save_diffs=True, render=False, properties=[], )
}, "envName": null, "environment": null, "defaultMatchSettings": {"matchLevel": "STRICT", "exact": null}, "verId": null, "branchName": null, "parentBranchName": null, "properties": [] }""" SESSION_START_INFO_OBJ = SessionStartInfo( agent_id="eyes.core.python/3.15.4", session_type=SessionType.SEQUENTIAL, app_id_or_name="TestApp", ver_id=None, scenario_id_or_name="TestName", batch_info=BatchInfo(), baseline_env_name="Baseline env name", environment_name="Env name", environment=AppEnvironment(), default_match_settings=ImageMatchSettings(match_level=MatchLevel.STRICT), branch_name="branch Name", parent_branch_name="parentBranchName", baseline_branch_name="baselineBranchName", save_diffs=True, render=False, properties=[], ) RUNNING_SESSION_DATA_RESPONSE_ID = "some id" RUNNING_SESSION_DATA_RESPONSE_URL = "http://some-session-url.com" RUNNING_SESSION_DATA_RESPONSE_SESSION_ID = "some session id" RUNNING_SESSION_DATA_RESPONSE_BATCH_ID = "other url"
def batch_info(): return BatchInfo(os.getenv("APPLITOOLS_BATCH_NAME", "Python SDK"))
class TestsVisualAI(unittest.TestCase): _batch = BatchInfo('Hackathon') _url = 'https://demo.applitools.com/hackathonV2.html' def setUp(self): self.driver = webdriver.Chrome('./chromedriver') self.eyes = Eyes() self.eyes.api_key = os.environ['APPLITOOLS_API_KEY'] self.eyes.batch = self._batch self.driver.get(self._url) def tearDown(self): self.eyes.abort() self.driver.close() def test_01_elements_presence_on_login_page(self): self.eyes.open(self.driver, "Hackathon app", "Test 01: elements presence", {'width': 800, 'height': 600}) self.eyes.check_window() self.eyes.close() user_password_data = lambda: ( ('', 'p'), ('u', ''), ('', ''), ('u', 'p') ) @data_provider(user_password_data) def test_02_login_errors(self, username, password): self.setUp() dr = self.eyes.open(self.driver, "Hackathon app", "Test 02: user={} and password={}".format(username, password), {'width': 800, 'height': 600}) dr.get(self._url) login_page = LoginPage(dr) login_page.set_username(username) login_page.set_password(password) login_page.click_login_button() self.eyes.check_window() self.eyes.check_region(Region(left=170, top=280, width=350, height=100)) self.eyes.close_async() def test_03_sort_order_and_data(self): login_page = LoginPage(self.driver) login_page.login('seba', 'seba') dr = self.eyes.open(self.driver, "Hackathon app", "Test 03: Table Sorting validation", {'width': 800, 'height': 600}) home_page = HomePage(dr) home_page.click_amount_header() home_page.scroll_down_to_chart() self.eyes.check_window() self.eyes.close() def test_04_chart_validation(self): login_page = LoginPage(self.driver) login_page.login('seba', 'seba') home_page = HomePage(self.driver) home_page.click_compare_expenses() dr = self.eyes.open(self.driver, "Hackathon app", "Test 04: Chart validation", {'width': 800, 'height': 600}) chart_page = ChartPage(dr) self.eyes.check_window() chart_page.click_show_next_year_button() self.eyes.check_window() self.eyes.close() def test_05_dynamic_add(self): self.driver.get('https://demo.applitools.com/hackathonV2.html?showAd=true') login_page = LoginPage(self.driver) login_page.login('seba', 'seba') self.eyes.open(self.driver, "Hackathon app", "Test 05: Dynamic content validation", {'width': 800, 'height': 600}) self.eyes.check_window() self.eyes.close()
def batch_info(): return BatchInfo("Python SDK Mobile")
def set_batch(self, batch_id): batch_info = BatchInfo() batch_info.name = self.test_name batch_info.id = batch_id self.eyes.batch = batch_info
def batch_info(): """Use one BatchInfo for all tests inside a module.""" return BatchInfo("UFG Hackathon")
def batch_info(): """Use one BatchInfo for all tests inside module.""" return BatchInfo("Applitools Demo Visual Tests")
def batch_info(self): """ Use one BatchInfo for all tests inside module """ return BatchInfo("Some general Test cases name")
def open_eyes_session( self, apikey=None, appname=None, testname=None, library=None, width=None, height=None, osname=None, browsername=None, matchlevel=None, enable_eyes_log=None, enable_http_debug_log=None, baselinename=None, batch=None, branchname=None, parentbranch=None, serverurl=None, force_full_page_screenshot=None, stitchmode=None, matchtimeout=None, hidescrollbars=None, save_new_tests=None, wait_before_screenshots=None, send_dom=None, stitchcontent=False, isdisabled=None, ): """ Starts a session (=test) with Applitools. Some of the following arguments may also be defined on library import. See `Before running tests` or `Importing`. | =Arguments= | =Description= | | API Key (str) | *Mandatory* - User's Applitools Eyes key | | Application Name (str) | *Mandatory* - The name of the application under test | | Test Name (str) | *Mandatory* - The test name | | Library (str) | Library to test (Either SeleniumLibrary or AppiumLibrary) | | Width (int) | The width of the browser window e.g. 1280 | | Height (int) | The height of the browser window e.g. 1000 | | Operating System (str) | The operating system of the test, can be used to override the OS name to allow cross OS verification | | Browser Name (str) | The browser name for the test, can be used to override the browser name to allow cross browser verification | | Match Level (str) | The match level for the comparison of this test's checkpoints - can be STRICT, LAYOUT, CONTENT or EXACT | | Enable Eyes Log (bool) | Determines if the trace logs of Applitools Eyes SDK are activated for this session | | Enable HTTP Debug Log (bool) | The HTTP Debug logs will not be included by default. To activate, pass 'True' in the variable | | Baseline Name (str) | Name of the branch where the baseline reference will be taken from and where new and accepted steps will be saved to | | Batch (str or BatchInfo) | The desired batch. See `Group tests into batches` | | Branch Name (str) | The branch to use to check test | | Parent Branch (str) | Parent Branch to base the new Branch on | | Server URL (str) | The URL of the Eyes server. If not provided then your test will run on the public cloud | | Force Full Page Screenshot (bool) | Will force the browser to take a screenshot of whole page | | Stitch Mode (str) | Type of stitching used for full page screenshots - can be CSS or SCROLL | | Match Timeout (int) | Determines how much time in milliseconds Eyes continues to retry the matching before declaring a mismatch on this test checkpoints | | Hide Scrollbars (bool) | Sets if the scrollbars are hidden this session's tests, by passing 'True' or 'False' in the variable | | Save New Tests (bool) | Sets if the new checkpoints on this session are automatically accepted, by passing 'True' or 'False' in the variable | | Wait Before Screenshots (int) | Determines the number of milliseconds that Eyes will wait before capturing a screenshot on this test checkpoints | | Send DOM (bool) | Sets if DOM information should be sent for this session's checkpoints | | Stitch Content (bool) | If this test checkpoint's elements/region are scrollable, determines if Eyes will scroll this them to take a full region/element screenshot | | Is Disabled (bool) | Determines whether or not interactions with Eyes will be silently ignored for this test | *Mandatory Arguments:* They may be defined through this keyword, or when importing the library. In order to run a test, provide at least the API Key, Application Name and Test Name. When opening the session on a mobile browser or hybrid app, the context must be set to WEBVIEW in order to retrieve the correct viewport size. Geolocation of the device may have to be set after switching context. *Example:* | Open Eyes Session | YourApplitoolsKey | AppName | TestName | SeleniumLibrary | 1024 | 768 | OSOverrideName | BrowserOverrideName | layout | ${true} | batchname=BatchName | serverurl=https://myserver.com | """ if appname is None: appname = self.library_arguments["appname"] if testname is None: testname = self.library_arguments["testname"] if apikey is None: apikey = self.library_arguments["apikey"] if library is None: library = self.library_arguments["library"] if osname is None: osname = self.library_arguments["osname"] if browsername is None: browsername = self.library_arguments["browsername"] if matchlevel is None: matchlevel = self.library_arguments["matchlevel"] if enable_eyes_log is None: enable_eyes_log = self.library_arguments["enable_eyes_log"] if serverurl is None: serverurl = self.library_arguments["serverurl"] if save_new_tests is None: save_new_tests = self.library_arguments["save_new_tests"] if matchtimeout is None: matchtimeout = self.library_arguments["matchtimeout"] if serverurl is None: variables.eyes = Eyes() else: variables.eyes = Eyes(serverurl) variables.eyes.api_key = apikey try: libraryInstance = BuiltIn().get_library_instance(library) if library == "AppiumLibrary": driver = libraryInstance._current_application() else: driver = libraryInstance.driver except RuntimeError: raise Exception("%s instance not found" % library) if enable_eyes_log is not None: variables.logger_to_use = True utils.manage_logging(enable_eyes_log, enable_http_debug_log) if osname is not None: variables.eyes.host_os = osname if browsername is not None: variables.eyes.host_app = browsername if baselinename is not None: variables.eyes.baseline_branch_name = baselinename if batch is not None: print(batch) print("***batch***") if type(batch) is six.text_type: batch = str(batch) batches_list = variables.batches # If batch argument is string if isinstance(batch, str): # Check for batch with same name for batch_element in batches_list: if batch_element.name == batch: variables.eyes.batch = batch_element print("222222222") break # If a batch with this name is not yet on the list if variables.eyes.batch is None: print("333333333") new_batch = BatchInfo(batch) variables.eyes.batch = new_batch variables.batches.append(new_batch) # If batch argument is BatchInfo else: # Check for batch with same name and date for batch_element in batches_list: if (batch_element.name == batch.name and batch_element.started_at == batch.started_at): variables.eyes.batch = batch_element break # If the list doesn't contain a batch with the same name and date if variables.eyes.batch is None: print("hello batch") variables.eyes.batch = batch variables.batches.append(batch) if matchlevel is not None: variables.eyes.match_level = utils.get_match_level(matchlevel) if parentbranch is not None: variables.eyes.parent_branch_name = parentbranch if branchname is not None: variables.eyes.branch_name = branchname if osname is not None: variables.eyes.host_os = osname if stitchmode is not None: variables.eyes.stitch_mode = utils.get_stitch_mode(stitchmode) if matchtimeout is not None: variables.eyes.match_timeout = int(matchtimeout) if force_full_page_screenshot is not None: variables.eyes.force_full_page_screenshot = force_full_page_screenshot if save_new_tests is not None: variables.eyes.save_new_tests = save_new_tests if wait_before_screenshots is not None: variables.eyes.wait_before_screenshots = int( wait_before_screenshots) if send_dom is not None: variables.eyes.send_dom = send_dom if stitchcontent is not False: variables.stitchcontent = stitchcontent print(variables.eyes.batch) print(type(variables.eyes.batch)) if width is None and height is None: variables.driver = variables.eyes.open(driver, appname, testname) else: variables.driver = variables.eyes.open(driver, appname, testname, { "width": int(width), "height": int(height) }) # Workaround - This property has to be called after opening session # Otherwise, the checks will throw exceptions if isdisabled is not None: variables.eyes.is_disabled = isdisabled
def batch_info(): return BatchInfo("Python SDK Selenium")
def batch_info(): batch_info = BatchInfo("hello world batch") batch_info.id = "hw_VG_Batch_ID" return batch_info