本文整理汇总了C#中OpenQA.Selenium.Remote.Command类的典型用法代码示例。如果您正苦于以下问题:C# Command类的具体用法?C# Command怎么用?C# Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于OpenQA.Selenium.Remote命名空间,在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes a command
/// </summary>
/// <param name="commandToExecute">The command you wish to execute</param>
/// <returns>A response from the browser</returns>
public Response Execute(Command commandToExecute)
{
if (commandToExecute == null)
{
throw new ArgumentNullException("commandToExecute", "Command to execute cannot be null");
}
Response toReturn = null;
if (commandToExecute.Name == DriverCommand.NewSession)
{
this.service.Start();
}
// Use a try-catch block to catch exceptions for the Quit
// command, so that we can get the finally block.
try
{
toReturn = this.internalExecutor.Execute(commandToExecute);
}
finally
{
if (commandToExecute.Name == DriverCommand.Quit)
{
this.service.Dispose();
}
}
return toReturn;
}
示例2: CreateWebRequest
/// <summary>
/// Creates a web request for your command
/// </summary>
/// <param name="baseUri">Uri that will have the command run against</param>
/// <param name="commandToExecute">Command to execute</param>
/// <returns>A web request of what has been run</returns>
public HttpWebRequest CreateWebRequest(Uri baseUri, Command commandToExecute)
{
HttpWebRequest request = null;
string[] urlParts = this.resourcePath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < urlParts.Length; i++)
{
string urlPart = urlParts[i];
if (urlPart.StartsWith("{", StringComparison.OrdinalIgnoreCase) && urlPart.EndsWith("}", StringComparison.OrdinalIgnoreCase))
{
urlParts[i] = GetCommandPropertyValue(urlPart, commandToExecute);
}
}
Uri fullUri;
string relativeUrl = string.Join("/", urlParts);
bool uriCreateSucceeded = Uri.TryCreate(baseUri, relativeUrl, out fullUri);
if (uriCreateSucceeded)
{
request = HttpWebRequest.Create(fullUri) as HttpWebRequest;
request.Method = this.method;
}
else
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to create URI from base {0} and relative path {1}", baseUri == null ? string.Empty : baseUri.ToString(), relativeUrl));
}
return request;
}
示例3: Execute
public Response Execute(Command commandToExecute)
{
Response result = null;
if (commandToExecute.Name == DriverCommand.NewSession && this.Service != null)
{
this.Service.Start();
}
try
{
result = RealExecutor.Execute(commandToExecute);
return result;
}
catch (Exception e)
{
if ((commandToExecute.Name == DriverCommand.NewSession) && (this.Service != null))
{
this.Service.Dispose();
}
throw e;
}
finally
{
if (result != null && result.Status != WebDriverResult.Success &&
commandToExecute.Name == DriverCommand.NewSession && this.Service != null)
{
this.Service.Dispose();
}
if (commandToExecute.Name == DriverCommand.Quit && this.Service != null)
{
this.Service.Dispose();
}
}
}
示例4: Send
/// <summary>
/// Sends a command to the SafariDriver and waits for a response.
/// </summary>
/// <param name="command">The <see cref="Command"/> to send to the driver.</param>
/// <returns>The <see cref="Response"/> from the command.</returns>
public Response Send(Command command)
{
SafariCommand wrappedCommand = new SafariCommand(command);
this.commandQueue.Enqueue(wrappedCommand);
string commandJson = JsonConvert.SerializeObject(wrappedCommand);
this.connection.Send(commandJson);
return this.WaitForResponse(TimeSpan.FromSeconds(30));
}
示例5: ExtractParameters
private static Dictionary<string, object> ExtractParameters(Command command)
{
if (command == null)
{
throw new ArgumentNullException("command", "command must not be null");
}
return command.Parameters;
}
示例6: ExtractName
private static string ExtractName(Command command)
{
if (command == null)
{
throw new ArgumentNullException("command", "command must not be null");
}
return command.Name;
}
示例7: ExtractSessionId
private static SessionId ExtractSessionId(Command command)
{
if (command == null)
{
throw new ArgumentNullException("command", "command must not be null");
}
return command.SessionId;
}
示例8: ForwardCommand
public string ForwardCommand(Command commandToForward, bool verbose = true, int timeout = 0)
{
var serializedCommand = JsonConvert.SerializeObject(commandToForward);
var response = this.SendRequest(serializedCommand, verbose, timeout);
if (response.Key == HttpStatusCode.OK)
{
return response.Value;
}
throw new InnerDriverRequestException(response.Value, response.Key);
}
示例9: Execute
/// <summary>
/// Executes a command
/// </summary>
/// <param name="commandToExecute">The command you wish to execute</param>
/// <returns>A response from the browser</returns>
public Response Execute(Command commandToExecute)
{
CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name);
HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);
request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
request.Accept = RequestAcceptHeader;
if (request.Method == CommandInfo.PostCommand)
{
string payload = commandToExecute.ParametersAsJsonString;
byte[] data = Encoding.UTF8.GetBytes(payload);
request.ContentType = JsonMimeType;
System.IO.Stream requestStream = request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
}
return CreateResponse(request);
}
示例10: DoImpl
protected override string DoImpl()
{
// It is easier to reparse desired capabilities as JSON instead of re-mapping keys to attributes and calling type conversions,
// so we will take possible one time performance hit by serializing Dictionary and deserializing it as Capabilities object
var serializedCapability =
JsonConvert.SerializeObject(this.ExecutedCommand.Parameters["desiredCapabilities"]);
this.Automator.ActualCapabilities = Capabilities.CapabilitiesFromJsonString(serializedCapability);
var innerIp = this.InitializeApplication(this.Automator.ActualCapabilities.DebugConnectToRunningApp);
this.Automator.CommandForwarder = new Requester(innerIp, this.Automator.ActualCapabilities.InnerPort);
long timeout = this.Automator.ActualCapabilities.LaunchTimeout;
const int PingStep = 500;
var stopWatch = new Stopwatch();
while (timeout > 0)
{
stopWatch.Restart();
Logger.Trace("Ping inner driver");
var pingCommand = new Command(null, "ping", null);
var responseBody = this.Automator.CommandForwarder.ForwardCommand(pingCommand, false, 2000);
if (responseBody.StartsWith("<pong>", StringComparison.Ordinal))
{
break;
}
Thread.Sleep(PingStep);
stopWatch.Stop();
timeout -= stopWatch.ElapsedMilliseconds;
}
// TODO throw AutomationException with SessionNotCreatedException if timeout and uninstall the app
Console.WriteLine();
// Gives sometime to load visuals (needed only in case of slow emulation)
Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);
var jsonResponse = this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities);
return jsonResponse;
}
示例11: Execute
/// <summary>
/// Executes a command
/// </summary>
/// <param name="commandToExecute">The command you wish to execute</param>
/// <returns>A response from the browser</returns>
public Response Execute(Command commandToExecute)
{
CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name);
HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
HttpWebRequest request = info.CreateWebRequest(remoteServerUri, commandToExecute);
request.Timeout = 15000;
request.Accept = "application/json, image/png";
if (request.Method == CommandInfo.PostCommand)
{
string payload = commandToExecute.ParametersAsJsonString;
byte[] data = Encoding.UTF8.GetBytes(payload);
request.ContentType = "application/json";
System.IO.Stream requestStream = request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
}
return CreateResponse(request);
}
示例12: Execute
/// <summary>
/// Executes a command
/// </summary>
/// <param name="commandToExecute">The command you wish to execute</param>
/// <returns>A response from the browser</returns>
public Response Execute(Command commandToExecute)
{
CommandInfo info = commandDictionary[commandToExecute.Name];
HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
HttpWebRequest request = info.CreateWebRequest(remoteServerUri, commandToExecute);
request.Accept = "application/json, image/png";
string payload = JsonConvert.SerializeObject(commandToExecute.Parameters, new JsonConverter[] { new PlatformJsonConverter(), new CookieJsonConverter(), new CharArrayJsonConverter() });
if (request.Method == CommandInfo.PostCommand)
{
byte[] data = Encoding.UTF8.GetBytes(payload);
request.ContentType = "application/json";
request.KeepAlive = false;
System.IO.Stream requestStream = request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
}
return CreateResponse(request);
}
示例13: ConnectToApp
private void ConnectToApp()
{
long timeout = this.Automator.ActualCapabilities.LaunchTimeout;
const int PingStep = 500;
var stopWatch = new Stopwatch();
while (timeout > 0)
{
stopWatch.Restart();
Logger.Trace("Ping inner driver");
var pingCommand = new Command(null, "ping", null);
var responseBody = this.Automator.CommandForwarder.ForwardCommand(pingCommand, false, 2000);
if (responseBody.StartsWith("<pong>", StringComparison.Ordinal))
{
break;
}
Thread.Sleep(PingStep);
stopWatch.Stop();
timeout -= stopWatch.ElapsedMilliseconds;
}
}
示例14: Execute
public Response Execute(Command commandToExecute)
{
if (commandToExecute == null)
{
throw new ArgumentNullException("commandToExecute", "Command may not be null");
}
if (commandToExecute.Name == DriverCommand.NewSession)
{
this.service.Start();
}
try
{
return this.internalExecutor.Execute(commandToExecute);
}
finally
{
if (commandToExecute.Name == DriverCommand.Quit)
{
this.service.Dispose();
}
}
}
示例15: Execute
/// <summary>
/// Executes a command with the ChromeDriver.
/// </summary>
/// <param name="commandToExecute">The command you wish to execute</param>
/// <returns>A response from the browser</returns>
public override Response Execute(Command commandToExecute)
{
Response toReturn = null;
if (commandToExecute.Name == DriverCommand.NewSession)
{
this.service.Start();
}
// Use a try-catch block to catch exceptions for the Quit
// command, so that we can get the finally block.
try
{
toReturn = base.Execute(commandToExecute);
}
finally
{
if (commandToExecute.Name == DriverCommand.Quit)
{
this.service.Dispose();
}
}
return toReturn;
}