macacajs / NoSmoke

A cross platform UI crawler which scans view trees then generate and execute UI test cases.
https://macacajs.github.io/NoSmoke
MIT License
198 stars 57 forks source link

遍历算法描述 #1

Closed xudafeng closed 7 years ago

xudafeng commented 7 years ago
SamuelZhaoY commented 7 years ago
// Structure of Node
class Action {
  var type:Int
  var data:HashMap
  var status:Int  // Pending, Done, (? Other types of actions)
}

class Node {
  __weakRef var parent:Node
  var actions:[Action]
  var done:Bool
  function digest() => String
}

// Models
var currentNode:Node
var nodes:[Node] 

// Initialization
void function init() {
  var firstNode = currentPage()
  traverse(firstNode)
}

// Depth-First 
void function traverse(node:Node) {
  // Check if node is already in node list by comparing digest
  if nodes.contains(node) {
    if node.actions.allclear {
      nodes.remove(node)
      popViewController()
      return
    }
  } else {
    // Create actions list for node
    // Fetch source
    var source = getSource(node)

    // Scan whether source contains specific requirements from yml
    // If so, only those specific elements are recorded as actions .
    // else, all clickable types of elements are recorded as actions.

    var actions = filterActions(node, configuration)
    node.actions = actions
  }

  for actions in node.actions   {
    perform(action)
    action.status = done 
    traverse(currentPage())
  }
}

// Perform Actions 
void function perform(actions) {
    // Based on types of actions, perform corresponding operations indicated by action.data
}
xudafeng commented 7 years ago

https://github.com/macacajs/NoSmoke/pull/3