Exemple #1
0
def seed_html_fault(html, elements, prop, value):
    while elements:
        e = random.choice(elements)
        elements.remove(e)
        original_style = None
        if prop in e.attrib:
            original_value = e.attrib[prop]
            e.attrib[prop] = value
            util.save_file(lxml.html.tostring(html, doctype=html.doctype),
                           'test.html')
            util.screenshot('test.html', 'test.png')
            e.attrib[prop] = original_value
        else:
            e.attrib[prop] = value
            util.save_file(lxml.html.tostring(html, doctype=html.doctype),
                           'test.html')
            util.screenshot('test.html', 'test.png')
            del e.attrib[prop]
        if not filecmp.cmp('oracle.png', 'test.png'):
            xpath = get_xpath(e)
            default_value = util.get_default_value('oracle.html',
                                                   xpath,
                                                   prop,
                                                   css=False)
            return (xpath, default_value, value)
            break
    return (None, None, None)
Exemple #2
0
def seed_css_fault(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    original_style = None
    if 'style' in e.attrib:
      original_style = e.attrib['style']
      e.attrib['style'] += ';{0}:{1};'.format(prop, value)
    else:
      e.attrib['style'] = '{0}:{1};'.format(prop, value)
    util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
    util.screenshot('test.html', 'test.png')
    if original_style is not None:
      e.attrib['style'] = original_style
    else:
      del e.attrib['style']
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop)
      return (xpath, default_value, value)
      break
  return (None, None, None)
Exemple #3
0
def seed_error(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    #print 'Trying ', e
    original_style = None
    if 'style' in e.attrib:
      original_style = e.attrib['style']
      e.attrib['style'] += ';{0}:{1};'.format(prop, value)
    else:
      e.attrib['style'] = '{0}:{1};'.format(prop, value)
    util.save_file(lxml.html.tostring(html), 'test.html')
    util.screenshot('test.html', 'test.png')
    if original_style:
      e.attrib['style'] = original_style
    else:
      del e.attrib['style']
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop)
      return (xpath, default_value, value)
      break
  return (None, None, None)
Exemple #4
0
def seed_html_fault(html, elements, prop, value):
  while elements:
    e = random.choice(elements)
    elements.remove(e)
    original_style = None
    if prop in e.attrib:
      original_value = e.attrib[prop]
      e.attrib[prop] = value
      util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
      util.screenshot('test.html', 'test.png')
      e.attrib[prop] = original_value
    else:
      e.attrib[prop] = value
      util.save_file(lxml.html.tostring(html, doctype=html.doctype), 'test.html')
      util.screenshot('test.html', 'test.png')
      del e.attrib[prop]
    if not filecmp.cmp('oracle.png', 'test.png'):
      xpath = get_xpath(e)
      default_value = util.get_default_value('oracle.html', xpath, prop, 
        css=False)
      return (xpath, default_value, value)
      break
  return (None, None, None)