/// <summary> /// Perform app walker input /// </summary> /// <param name="device">The current device</param> /// <param name="nodes">All nodes on current screen</param> public void PerformInput(IAndroidDevice device, IList <Node> nodes) { if (_shouldOnlyTapClickAbleNodes) { nodes = nodes.Where(n => n.Clickable).ToList(); } if (nodes.Count == 0) { device.Interaction.InputKeyEvent(KeyEvents.Back); return; } var selectedNode = nodes[_rnd.Next(0, nodes.Count)]; var shouldStillTap = CheckTapCases(device, _tapCases, selectedNode); if (shouldStillTap) { device.Interaction.Tap(selectedNode); if (selectedNode.Focusable && selectedNode.LongClickable) { device.Interaction.InputText("Hello"); } } }
/// <summary> /// Set the owner of the service /// </summary> /// <param name="device">Owner of the service</param> public void InitializeServiceOwner(IAndroidDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } Device = device; }
/// <summary> /// Check if we have any case that want to stop the walk /// </summary> /// <param name="device">The current android device</param> /// <param name="stopCases">A list of provided stop cases</param> /// <param name="nodes">All nodes on the screen</param> /// <returns>True if we should stop the walk, false otherwise</returns> private bool StopWalk(IAndroidDevice device, IEnumerable <StopCase> stopCases, IList <Node> nodes) { var stopCase = stopCases.FirstOrDefault(s => s.IsMatching(nodes)); if (stopCase != null) { return(stopCase.Execute(device)); } return(false); }
/// <summary> /// Check if we have any matching tap case for this node and if so invoke it first. /// </summary> /// <param name="device">The current device.</param> /// <param name="tapCases">List of provided tap cases.</param> /// <param name="selectedNode">The currently selected node.</param> /// <returns>True if we still should tap the node, false otherwise.</returns> private bool CheckTapCases(IAndroidDevice device, IEnumerable <TapCase> tapCases, Node selectedNode) { var shouldStillTap = true; var matchingTapCase = tapCases.FirstOrDefault(t => t.IsMatching(selectedNode)); if (matchingTapCase != null) { shouldStillTap = matchingTapCase.Execute(device, selectedNode); } return(shouldStillTap); }
/// <summary> /// Initializes a new instance of the <see cref="BaseUiObject"/> class. /// </summary> /// <param name="device">The current android device object.</param> /// <param name="withs">A set of <see cref="With">Withs</see> that tell us how we should find the UI object./></param> protected BaseUiObject(IAndroidDevice device, params With[] withs) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (withs == null || withs.Length == 0) { throw new ArgumentException("Argument is empty collection", nameof(withs)); } Device = device; Withs = withs; }
/// <summary> /// Execute the case /// </summary> /// <param name="devie">The current device</param> /// <param name="node">The currently selected node</param> /// <returns>True if we should still tap on node, false otherwise</returns> public override bool Execute(IAndroidDevice devie, Node node) { return(_case.Invoke(devie, node)); }
/// <summary> /// Perform app walker input /// </summary> /// <param name="device">The current device</param> /// <param name="nodes">All nodes on current screen</param> public void PerformInput(IAndroidDevice device, IList <Node> nodes) { device.Interaction.Swipe(_swipeDirectionses[_rnd.Next(0, _swipeDirectionses.Count)], _duration); }
/// <summary> /// Start the timer. /// </summary> /// <param name="device">The current device.</param> public void StartTimer(IAndroidDevice device) { _timer.Start(); _timer.Elapsed += TimerOnElapsed; Device = device; }
/// <summary> /// Initializes a new instance of the <see cref="View"/> class. /// </summary> /// <param name="device">Current android device</param> protected View(IAndroidDevice device) { Device = device; InitializeUiObjects(); }
/// <summary> /// Execute the case /// </summary> /// <param name="devie">The current device</param> /// <param name="node">The currently selected node</param> /// <returns>True if we should still tap on node, false otherwise</returns> public abstract bool Execute(IAndroidDevice devie, Node node);
/// <summary> /// Execute the case /// </summary> /// <param name="device">The current device</param> /// <returns>True if we should stop the app walker run, false otherwise</returns> public abstract bool Execute(IAndroidDevice device);
/// <summary> /// Start the app walker /// </summary> /// <param name="device">Device to run walk with</param> /// <param name="package">Package to app walk. If null we start from current screen</param> /// <param name="activity">Activity to app walk. If null we start from current screen</param> /// <param name="timeCases">Time cases with specific actions that we want to perform in intervals</param> /// <param name="stopCases">Stop cases to decide if we should stop the run</param> public void Start(IAndroidDevice device, string package, string activity, IEnumerable <TimeCase> timeCases, IEnumerable <StopCase> stopCases) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (timeCases == null) { timeCases = new List <TimeCase>(); } if (stopCases == null) { stopCases = new List <FuncStopCase>(); } if (package != null && activity != null && _appWalkerConfiguration.ShouldStartActivity) { device.Activity.Start(package, activity, false, false); } foreach (var timeCase in timeCases) { timeCase.StartTimer(device); } var currentPackageAndActivity = device.Activity.GetCurrent(); var numberOfTimesOnPackageAndAcivity = 0; var uiService = device.Ui as UiService; var start = DateTime.Now; while (true) { if (_appWalkerConfiguration.WalkDuration > 0) { if ((DateTime.Now - start).Minutes > _appWalkerConfiguration.WalkDuration) { return; } } var nodes = ForceGetAllNodes(uiService); if (StopWalk(device, stopCases, nodes)) { return; } _inputs[_rnd.Next(0, _inputs.Count)].PerformInput(device, nodes); var packageAndActivity = device.Activity.GetCurrent(); if (package != null && !packageAndActivity.Contains(package) && _appWalkerConfiguration.ShouldGoBackToActivity) { device.Activity.Start(package, activity, false, false); } if (packageAndActivity != currentPackageAndActivity) { currentPackageAndActivity = packageAndActivity; numberOfTimesOnPackageAndAcivity = 0; } else { numberOfTimesOnPackageAndAcivity++; if (numberOfTimesOnPackageAndAcivity == _appWalkerConfiguration.MaxInputBeforeGoingBack) { device.Interaction.InputKeyEvent(KeyEvents.Back); numberOfTimesOnPackageAndAcivity = 0; } } Thread.Sleep(_appWalkerConfiguration.InputCooldown * 1000); } }
/// <summary> /// Start the app walker /// </summary> /// <param name="device">Device to run walk with</param> /// <param name="package">Package to app walk. If null we start from current screen</param> /// <param name="activity">Activity to app walk. If null we start from current screen</param> public void Start(IAndroidDevice device, string package, string activity) { Start(device, package, activity, new List <TimeCase>(), new List <StopCase>()); }
public void Configure(IAndroidDevice device) { // Do I need to do anything here? }
internal UiObjects(IAndroidDevice device, params With[] withs) : base(device, withs) { }
public ExampleClass(IAndroidDevice device) : base(device) { }