Commit 57d2e3ba authored by Douglas's avatar Douglas

jstestnode: parsing test results with lxml for much better parsing performance

parent efd39c9a
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import argparse, os, re, shutil, subprocess, sys, traceback import argparse, os, re, shutil, subprocess, sys, traceback
from erp5.util import taskdistribution from erp5.util import taskdistribution
from time import gmtime, strftime from time import gmtime, strftime
from lxml import etree
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
...@@ -62,29 +63,34 @@ def main(): ...@@ -62,29 +63,34 @@ def main():
By.XPATH, '//p[@id="qunit-testresult" and contains(text(), "completed")]') By.XPATH, '//p[@id="qunit-testresult" and contains(text(), "completed")]')
)) ))
html_parser = etree.HTMLParser(recover=True)
body = etree.fromstring(browser.page_source.encode('UTF-8'), html_parser)
browser.title.encode('UTF-8') browser.title.encode('UTF-8')
print browser.find_element_by_id("qunit-testresult").text browser.quit()
print ' '.join(body.xpath('//*[@id="qunit-testresult"]//text()'))
for elt in browser.find_elements_by_xpath('//ol[@id="qunit-tests"]/li'): for elt in body.xpath('.//ol[@id="qunit-tests"]/li'):
test_name = '%s: %s' % ( test_name = '%s: %s' % (
elt.find_element_by_xpath('.//span[@class="module-name"]').text, elt.xpath('.//span[@class="module-name"]')[0].text,
elt.find_element_by_xpath('.//span[@class="test-name"]').text elt.xpath('.//span[@class="test-name"]')[0].text
) )
print elt.get_attribute('class'), elt.find_element_by_tag_name('strong').text print elt.get('class'), ''.join(elt.xpath('.//strong')[0].itertext())
# print elt.find_element_by_tag_name('ol').get_attribute('innerHTML') # print elt.find_element_by_tag_name('ol').get_attribute('innerHTML')
failure = int(elt.find_element_by_xpath('.//b[@class="failed"]').text) failure = int(elt.xpath('.//b[@class="failed"]')[0].text)
success = int(elt.find_element_by_xpath('.//b[@class="passed"]').text) success = int(elt.xpath('.//b[@class="passed"]')[0].text)
test_line_dict[test_name] = { test_line_dict[test_name] = {
'test_count': success + failure, 'test_count': success + failure,
'error_count': 0, 'error_count': 0,
'failure_count': failure, 'failure_count': failure,
'skip_count': 0, 'skip_count': 0,
'duration': int(elt.find_element_by_xpath('.//span[@class="runtime"]').text.split()[0]), 'duration': int(elt.xpath('.//span[@class="runtime"]')[0].text.split()[0]),
'command': elt.find_element_by_xpath('.//a[text()="Rerun"]').get_attribute('href'), 'command': elt.xpath('.//a[text()="Rerun"]')[0].get('href'),
'stdout': agent, 'stdout': agent,
'stderr': '', 'stderr': '',
'html_test_result': elt.find_element_by_tag_name('ol').get_attribute('innerHTML') 'html_test_result': etree.tostring(elt.xpath('.//ol')[0])
} }
tool = taskdistribution.TaskDistributionTool(portal_url=args.master_url) tool = taskdistribution.TaskDistributionTool(portal_url=args.master_url)
...@@ -121,4 +127,4 @@ def main(): ...@@ -121,4 +127,4 @@ def main():
browser.quit() browser.quit()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
\ No newline at end of file
...@@ -35,6 +35,7 @@ recipe = zc.recipe.egg ...@@ -35,6 +35,7 @@ recipe = zc.recipe.egg
eggs = eggs =
erp5.util erp5.util
selenium selenium
lxml
interpreter = pythonwitheggs interpreter = pythonwitheggs
[renderjs-repository.git] [renderjs-repository.git]
...@@ -106,7 +107,7 @@ mode = 0644 ...@@ -106,7 +107,7 @@ mode = 0644
[template-runTestSuite] [template-runTestSuite]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/runTestSuite.in url = ${:_profile_base_location_}/runTestSuite.in
md5sum = 13a56b1b6b2d54dc27ed6570e4b5f1d7 md5sum = 88e820d30b36ecca9b45242ce4a52039
output = ${buildout:directory}/runTestSuite.in output = ${buildout:directory}/runTestSuite.in
mode = 0644 mode = 0644
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment