def test_direct_feeding(self): obj = BlazeMeterUploader() self.sniff_log(obj.log) obj.engine = EngineEmul() mock = BZMock(obj._user) mock.mock_post.update({ 'https://data.blazemeter.com/submit.php?session_id=direct&signature=sign&test_id=None&user_id=None&pq=0&target=labels_bulk&update=1': {}, 'https://data.blazemeter.com/api/v4/image/direct/files?signature=sign': {"result": True}, 'https://a.blazemeter.com/api/v4/sessions/direct/stop': {"result": True}, 'https://data.blazemeter.com/submit.php?session_id=direct&signature=sign&test_id=None&user_id=None&pq=0&target=engine_health&update=1': { 'result': {'session': {}}} }) mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/sessions/direct': {"result": {}} }) mock.mock_patch.update({ 'https://a.blazemeter.com/api/v4/sessions/direct': {"result": {}} }) obj.parameters['session-id'] = 'direct' obj.parameters['signature'] = 'sign' obj.settings['token'] = 'FakeToken' obj.prepare() obj.startup() obj.check() obj.shutdown() obj.engine.stopping_reason = TaurusException("To cover") obj.post_process() self.assertNotIn("Failed to finish online", self.log_recorder.warn_buff.getvalue()) self.assertEquals('direct', obj._session['id']) self.assertEqual(9, len(mock.requests), "Requests were: %s" % mock.requests)
def post_process(self): self.log.warning( 'Part of result data might be missed here due to BM API specifics') if not self.detach and self.router and not self.test_ended: self.router.stop_test() if self.results_url: if self.browser_open in ('end', 'both'): open_browser(self.results_url) if self.router and self.router.master: full = self.router.master.get_full() if 'note' in full and full['note']: self.log.warning( "Cloud test has probably failed with message: %s", full['note']) for session in full.get('sessions', ()): for error in session.get("errors", ()): raise TaurusException(to_json(error)) if "hasThresholds" in full and full["hasThresholds"]: thresholds = self.router.master.get_thresholds() for item in thresholds.get('data', []): if item.get('success', None) is False: reason = None for assertion in item.get('assertions', []): if assertion.get('success', None) is False: criterion = assertion.get('field', '') label = assertion.get('label', '') reason = "Cloud failure criterion %r (on label %r) was met" % ( criterion, label) break if reason is None: reason = "Cloud tests failed because failure criteria were met" self.log.warning(reason) raise AutomatedShutdown(reason) # if we have captured HARs, let's download them for service in self.engine.config.get(Service.SERV, []): mod = service.get( 'module', TaurusConfigError("No 'module' specified for service")) assert isinstance(mod, str), mod module = self.engine.instantiate_module(mod) if isinstance(module, ServiceStubCaptureHAR): self._download_logs() break if "functionalSummary" in full: summary = full["functionalSummary"] if summary is None or summary.get("isFailed", False): raise AutomatedShutdown("Cloud tests failed")
def _find_by_css_selector(root, css_selector, raise_exception): element = None try: element = root.find_element_by_css_selector(css_selector) except NoSuchElementException as nse: if raise_exception: if root.tag_name == "slot": raise TaurusException( "Shadow DOM Slots are currently not supported in Taurus execution." ) raise nse pass return element
def _find_by_css_selector(root, css_selector, raise_exception): element = None try: # Chrome 96+ returns the element as a dict that includes the id if isinstance(root, dict): key = list(root.keys())[0] shadow_root_el = WebElement(_get_driver(), root[key]) element = shadow_root_el.find_element_by_css_selector(css_selector) else: element = root.find_element_by_css_selector(css_selector) except NoSuchElementException as nse: if raise_exception: if root.tag_name == "slot": raise TaurusException( "Shadow DOM Slots are currently not supported in Taurus execution." ) raise nse pass return element
def test_perform_prepare_exc(self): self.obj.engine.prepare_exc = TaurusException() ret = self.get_ret_code([RESOURCES_DIR + "json/mock_normal.json"]) self.assertEquals(1, ret)
def test_perform_prepare_exc(self): self.obj.engine.prepare_exc = TaurusException() ret = self.obj.perform( [__dir__() + "/resources/json/mock_normal.json"]) self.assertEquals(1, ret)