예제 #1
0
파일: gen.py 프로젝트: jineli/websee
def process_css(test_dir, oracle_html, total):
  for cate in const.css:
    for prop in const.css[cate]:
      prop_total = 0
      elements = oracle_html.xpath("//*")
      filter_list = ['html', 'link', 'head', 'meta', 'title', 'style', 'script',
        'body']
      elements = [e for e in elements if e.tag not in filter_list]
      while elements:  
        if 'color' in cate:
          (xpath, default_value, value) = seed_css_color(oracle_html, 
            elements, prop)
        elif 'numeric' in cate:
          (xpath, default_value, value) = seed_css_numeric(oracle_html,
            elements, prop)
        elif 'pre-defined' in cate:
          (xpath, default_value, value) = seed_css_predefined(oracle_html, 
            elements, prop)
        if xpath:
          diff = util.diff_image('oracle.png', 'test.png')
          diff.save('diff.png', 'PNG')
          total += 1
          prop_total += 1
          testcase = 'test' + str(total)
          testcase_dir = test_dir + '/' + testcase
          os.mkdir(testcase_dir)
          shutil.copyfile('oracle.html', testcase_dir + '/oracle.html')
          shutil.copyfile('test.html', testcase_dir + '/test.html')
          shutil.copyfile('oracle.png', testcase_dir + '/oracle.png')
          shutil.copyfile('test.png', testcase_dir + '/test.png')
          shutil.copyfile('diff.png', testcase_dir + '/diff.png')
          write_description(test_dir, url, prop, default_value, value, xpath, testcase, 'css')
        if prop_total == 1:
          break
  return total
예제 #2
0
def process(url):
  if os.path.isfile('description.txt'):
    os.remove('description.txt')
  shutil.rmtree('test')
  os.mkdir('test')
  oracle_html = get_oracle(url)
  total = 0
  for cate in classify.category:
    for prop in classify.category[cate]:
      current = 0
      elements = oracle_html.xpath("//*")
      filter_list = ['html', 'link', 'head', 'meta', 'title', 'style', 'script', 'body']
      elements = [e for e in elements if e.tag not in filter_list]  
      while elements:
        if 'color' in cate:
          (xpath, default_value, value) = seed_color(oracle_html, elements, prop)
        elif 'numeric' in cate:
          (xpath, default_value, value) = seed_numeric(oracle_html, elements, prop)
        elif 'pre-defined' in cate:
          (xpath, default_value, value) = seed_predefined(oracle_html, elements, prop)
        if xpath:
          diff = util.diff_image('oracle.png', 'test.png')
          diff.save('diff.png', 'PNG')
          total += 1
	  current += 1
          path = 'test' + str(total)
          os.mkdir('test/' + path)
          shutil.copyfile('oracle.html', 'test/' + path + '/oracle.html')
          shutil.copyfile('test.html', 'test/' + path + '/test.html')
          shutil.copyfile('oracle.png', 'test/' + path + '/oracle.png')
          shutil.copyfile('test.png', 'test/' + path + '/test.png')
          shutil.copyfile('diff.png', 'test/' + path + '/diff.png')
          write_description(url, prop, default_value, value, xpath, path)
        if current == 20:
          break
예제 #3
0
def process_html(test_dir, oracle_html, total):
    for cate in const.html:
        for prop in const.html[cate]:
            prop_total = 0
            elements = oracle_html.xpath("//*")
            filter_list = [
                'html', 'link', 'head', 'meta', 'title', 'style', 'script',
                'body'
            ]
            elements = [e for e in elements if e.tag not in filter_list]
            if len(const.html_elements[prop]):
                elements = [
                    e for e in elements if e.tag in const.html_elements[prop]
                ]
            while elements:
                if 'boolean' in cate:
                    (xpath, default_value,
                     value) = seed_html_boolean(oracle_html, elements, prop)
                elif 'numeric' in cate:
                    (xpath, default_value,
                     value) = seed_html_numeric(oracle_html, elements, prop)
                elif 'pre-defined' in cate:
                    (xpath, default_value,
                     value) = seed_html_predefined(oracle_html, elements, prop)
                if xpath:
                    diff = util.diff_image('oracle.png', 'test.png')
                    diff.save('diff.png', 'PNG')
                    total += 1
                    prop_total += 1
                    testcase = 'test' + str(total)
                    testcase_dir = test_dir + '/' + testcase
                    os.mkdir(testcase_dir)
                    shutil.copyfile('oracle.html',
                                    testcase_dir + '/oracle.html')
                    shutil.copyfile('test.html', testcase_dir + '/test.html')
                    shutil.copyfile('oracle.png', testcase_dir + '/oracle.png')
                    shutil.copyfile('test.png', testcase_dir + '/test.png')
                    shutil.copyfile('diff.png', testcase_dir + '/diff.png')
                    write_description(test_dir, url, prop, default_value,
                                      value, xpath, testcase, 'html')
                    print total
                if prop_total == 1:
                    break
    return total