def has_failed(self): bars = self.browser.find_by_xpath('//div%s/div%s/span%s' % ( class_xpath_to_css(self.css_root), class_xpath_to_css('alert'), class_xpath_to_css('bar'), )) return any(['failed' in bar['class'] for bar in bars])
def get_failures(self): rootDescribes = self.browser.find_by_xpath('//*%s/*%s%s' % ( class_xpath_to_css('jasmine_reporter'), class_xpath_to_css('suite'), class_xpath_to_css('failed'), )) specs = [] def traverse(describes, specs): for describe in describes: desc = describe.find_by_css('.description') spec = {} children = spec[desc.first.text] = [] specs.append(spec) if 'suite' in describe['class']: traverse( describe.find_by_xpath('*%s' % class_xpath_to_css('failed')), children ) elif 'spec' in describe['class']: children.extend(map(lambda el: el.text, describe.find_by_css('.resultMessage'))) traverse(rootDescribes, specs) return specs
def description(self): if hasattr(self, '_description'): return self._description bars = self.browser.find_by_xpath('//div%s/div%s/span%s' % ( class_xpath_to_css(self.css_root), class_xpath_to_css('alert'), class_xpath_to_css('bar'), )) bars = [bar for bar in bars if self._specs_re.match(bar.text) and not bar.text[0] == '0'] if not bars: return "Jasmine 2" self._description = bars[0].text return self._description
def get_failures(self): ''' this function returns an array with the following structure: [{'title of test suite': [{'title of nested test suite': [{'spec description': ['spec error message']}, ...] , ...] , ...] ''' results = self.browser.find_by_xpath('//div%s/div%s' % ( class_xpath_to_css(self.css_root), class_xpath_to_css('results') )) failure_details = results.find_by_xpath('div%s/div%s' % ( class_xpath_to_css('failures'), class_xpath_to_css('failed'), )) summaryRoots = results.find_by_xpath('div%s/*' % ( class_xpath_to_css('summary'), )) detail_messages = {} for detail in failure_details: id = detail.find_by_xpath('div%s/a' % ( class_xpath_to_css('description'),))[0]['href'] messages = [m.text for m in detail.find_by_xpath('div%s/div%s' % ( class_xpath_to_css('messages'), class_xpath_to_css('result-message')))] detail_messages[id] = messages specs = [] def traverse(describes, specs): for describe in describes: if 'suite-detail' in describe['class']: pass elif 'suite' in describe['class']: desc = describe.find_by_xpath('*%s/a' % ( class_xpath_to_css('suite-detail'),)).first # Strangely, text fails desc = desc.text or desc.html spec = {} children = spec[desc] = [] traverse(describe.find_by_xpath('*'), children) if children: specs.append(spec) elif 'specs' in describe['class']: failures = describe.find_by_xpath('*%s/a' % ( class_xpath_to_css('failed'),)) for failure in failures: id = failure['href'] title = failure.text or failure.html specs.append({title: detail_messages[id]}) traverse(summaryRoots, specs) return specs
def traverse(describes, specs): for describe in describes: if 'suite-detail' in describe['class']: pass elif 'suite' in describe['class']: desc = describe.find_by_xpath('*%s/a' % ( class_xpath_to_css('suite-detail'),)).first # Strangely, text fails desc = desc.text or desc.html spec = {} children = spec[desc] = [] traverse(describe.find_by_xpath('*'), children) if children: specs.append(spec) elif 'specs' in describe['class']: failures = describe.find_by_xpath('*%s/a' % ( class_xpath_to_css('failed'),)) for failure in failures: id = failure['href'] title = failure.text or failure.html specs.append({title: detail_messages[id]})
def get_failures(self): specs = [] fail_container = self.browser.find_by_id('qunit-tests') fail_suites = fail_container.find_by_xpath('*%s' % class_xpath_to_css('fail')) for suite in fail_suites: suite_description_node = suite.find_by_tag('strong').first # hack to make message "pickable" # some drivers (selenium) do not allow to get the text if the element is not visible suite_description_node.click() description = suite_description_node.text fail_messages = map(lambda el: el.text, suite.find_by_xpath('ol/li%s' % class_xpath_to_css('fail'))) specs.append({ description: fail_messages }) return specs
def traverse(describes, specs): for describe in describes: desc = describe.find_by_css('.description') spec = {} children = spec[desc.first.text] = [] specs.append(spec) if 'suite' in describe['class']: traverse( describe.find_by_xpath('*%s' % class_xpath_to_css('failed')), children ) elif 'spec' in describe['class']: children.extend(map(lambda el: el.text, describe.find_by_css('.resultMessage')))