public void ConvertToSerializable_ForAllSupportedByTypes_ShouldReturnExpectedDictionary(By by, string locatorKey, string expectedLocatorValue) { Dictionary <string, string> result = by.ConvertToSerializable(); string actualLocatorValue; Assert.AreEqual(1, result.Count); Assert.IsTrue(result.TryGetValue(locatorKey, out actualLocatorValue)); Assert.AreEqual(expectedLocatorValue, actualLocatorValue); }
/// <summary> /// Executes an action using its proxy. /// </summary> /// <param name="actionProxy">The action proxy to execute.</param> /// <param name="by">A locator for the <see cref="IWebElement"/> to execute the action on.</param> /// <param name="timeoutInMilliSeconds">Timeout for the action execution duration.</param> /// <returns>A potentially updated <see cref="ActionProxy"/> with updated output fields (if any).</returns> public ActionProxy Execute(ActionProxy actionProxy, By by = null, int timeoutInMilliSeconds = -1) { if (by != null) { // Because serializing does not work 'out of the box' for By objects, // we need to handle that with a custom method. actionProxy.ProxyDescriptor.By = by.ConvertToSerializable(); } // The payload to be sent to the Agent needs to be formatted first. actionProxy.ProxyDescriptor.Parameters = this.FormatParameters(actionProxy); ActionExecutionResponse response = AgentClient.GetInstance().ExecuteProxy(actionProxy, timeoutInMilliSeconds); if (!response.ResultType.Equals(ActionExecutionResponse.ExecutionResultType.Passed)) { throw new SdkException($"Error occurred during addon action execution: {response.Message}"); } foreach (ActionExecutionResponse.ResultField field in response.Fields) { if (!field.Output) { // Skip input fields continue; } var proxyField = actionProxy.GetType().GetProperty(field.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); // Check if action has an attribute with the name of the field if (proxyField == null) { Logger.Warn($"Action {actionProxy.ProxyDescriptor.Guid} does not have a field named '{field.Name}'"); continue; } proxyField.SetValue(actionProxy, field.Value); Logger.Trace($"Value of output field '{proxyField.Name}' has been set to '{proxyField.GetValue(actionProxy)}'"); } return(actionProxy); }