def CreateUIActionList(actions_per_command, num_commands, given_seed=None):
    """Generate user-like pseudo-random action sequences.

  Args:
    actions_per_command: length of each ui action sequence.
    num_commands: number of sequences to generate.
    seed: optional rand seed for this list.

  Returns:
    XML format command list string, readable by automated_ui_tests.
  """
    doc = xml.dom.minidom.Document()
    command_list = doc.createElement('CommandList')
    doc.appendChild(command_list)
    for _ in xrange(num_commands):
        command = doc.createElement('command')
        command_list.appendChild(command)
        seed = ui_model.Seed(given_seed)
        command.setAttribute('seed', str(seed))
        browser = ui_model.BrowserState()
        for _ in xrange(actions_per_command):
            action = ui_model.GetRandomAction(browser)
            browser = ui_model.UpdateState(browser, action)
            action_tuple = action.split(';')
            action_element = doc.createElement(action_tuple[0])
            if len(action_tuple) == 2:
                action_element.setAttribute('url', action_tuple[1])
            command.appendChild(action_element)
    return doc.toprettyxml()
Esempio n. 2
0
 def testUIActions(self):
   """Generates and runs actions forever."""
   self.browser = ui_model.BrowserState(advanced_actions=True)
   count = 0
   start_time = time.time()
   while True:
     count += 1
     sys.stdout.write('%d:%.3f > ' % (count, time.time() - start_time))
     action = ui_model.GetRandomAction(self.browser)
     self.ApplyAction(action)
Esempio n. 3
0
 def RunActionList(self):
   """Runs actions from a file."""
   f = open('list')
   actions = f.readlines()
   self.browser = ui_model.BrowserState(advanced_actions=True)
   count = 0
   for action in actions:
     count += 1
     sys.stdout.write('%d > ' % count)
     action = action.strip()
     self.ApplyAction(action)
   raw_input('Press key to continue.')