Skip to content
natanieljr edited this page Jul 31, 2018 · 1 revision

Extending

DroidMate can be extended by adding custom strategies, selectors and model features

Writing Custom Strategies

The project is written in Kotlin but fully Java compatible.

Writing a new strategy can be as easy as

import org.droidmate.exploration.actions.AbstractExplorationAction
import org.droidmate.exploration.strategy.widget.ExplorationStrategy

class CustomStrategy: ExplorationStrategy() {

	override fun chooseAction(): AbstractExplorationAction {
		/** TODO custom code to determine next exploration action **/
	}
}

Then all you need is to define a selector, such that DM-2 knows with which priority your strategy should be chosen (and under which conditions). We suggest you to use the ExplorationAPI to easily start an exploration.

import org.droidmate.ExplorationAPI
import org.droidmate.exploration.StrategySelector

class Main {
@JvmStatic fun main(args: Array<String>) {
  val cfg = ExplorationAPI.config(args)
  val customStrategy = CustomStrategy()
  val customStrategySelector = 
    StrategySelector(0, "custom", { _, pool, _ ->
						pool.getFirstInstanceOf(CustomStrategy::class.java)})

  ExplorationAPI.explore(cfg, strategies = listOf(customStrategy)
					, selectors = listOf(customStrategySelector)
//					, reportCreators = org.droidmate.command.ExploreCommand.defaultReportWatcher(cfg)
			)
}
}

If you want to use the default strategies, you should add them to the strategies list and the selectors collection. You can use org.droidmate.command.ExploreCommand.getDefaultSelectors(cfg) and org.droidmate.command.ExploreCommand.getDefaultStrategies(cfg) for this.

Other extensions

An executable example of how to create your own extensions to DroidMate can be found in repo/droidmate_usage_examples

Clone this wiki locally