private static PhantomJSDriverService CreateServiceWithNonDefaultValues() { var suppliedService = PhantomJSDriverService.CreateDefaultService(); var properties = suppliedService.GetType().GetProperties(); foreach (var property in properties) { var jsonAttribute = property.GetCustomAttributes(typeof(JsonPropertyAttribute), false).SingleOrDefault() as JsonPropertyAttribute; var defaultValueAttrbute = property.GetCustomAttributes(typeof(DefaultValueAttribute), false).SingleOrDefault() as DefaultValueAttribute; if (jsonAttribute != null) { switch (property.PropertyType.Name) { case "String": // Supply a distinct string property.SetValue(suppliedService, "string" + number++, null); break; case "Boolean": // Use the value opposite the configured default property.SetValue(suppliedService, !(Convert.ToBoolean(defaultValueAttrbute.Value)), null); break; case "Int32": // Supply a non-zero number property.SetValue(suppliedService, number++, null); break; } } } return(suppliedService); }
/// <summary> /// Initializes a new instance of the <see cref="AdSenseSpawner" /> class. /// </summary> public AdSenseSpawner() { Cache = new List<IAdSenseDriver>(); _driverService = PhantomJSDriverService.CreateDefaultService(); _driverService.HideCommandPromptWindow = true; }
private static PhantomJSDriverService SerializeAndDeserializeService(PhantomJSDriverService suppliedService) { string json = JsonConvert.SerializeObject(suppliedService, Formatting.Indented); var deserializedService = JsonConvert.DeserializeObject <PhantomJSDriverService>(json); return(deserializedService); }
/// <summary> /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities()) { // Add the custom commandInfo of PhantomJSDriver CommandInfo commandInfo = new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/phantom/execute"); this.CommandExecutor.CommandInfoRepository.TryAddCommand(CommandExecutePhantomScript, commandInfo); }
public void ShouldNotSerializeUnmodifiedProperties() { var suppliedService = PhantomJSDriverService.CreateDefaultService(); string json = suppliedService.ToJson(); var parsedObject = JObject.Parse(json); Assert.That(parsedObject.Properties().Count(), Is.EqualTo(0), "Actual JSON: " + json); }
private static string GetCommandLineArgumentsViaReflection(PhantomJSDriverService driverService) { // Use reflection to access protected CommandLineArguments property var commandLineArgumentsProperty = typeof(PhantomJSDriverService).GetProperty("CommandLineArguments", BindingFlags.NonPublic | BindingFlags.Instance); var commandLineArguments = commandLineArgumentsProperty.GetValue(driverService, null) as string; return(commandLineArguments); }
public virtual void ShouldNotIncludeNonConfiguredOptionsInCommandLineArguments() { var driverService = PhantomJSDriverService.CreateDefaultService(); string commandLineArguments = GetCommandLineArgumentsViaReflection(driverService); var actualArguments = GetActualArguments(commandLineArguments); var expectedArguments = new List <string>(new[] { "webdriver" }); Assert.That(actualArguments, Is.EquivalentTo(expectedArguments)); }
public void ShouldIncludeGenericArgumentsInCommandLineArgumentsWithALeadingSpace() { var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.AddArgument("--foo=bar"); driverService.AddArgument("--bar=baz"); var commandLineArguments = GetCommandLineArgumentsViaReflection(driverService); Assert.That(commandLineArguments.Contains(" --foo=bar --bar=baz")); }
public void ShouldNotSerializeArguments() { var suppliedService = PhantomJSDriverService.CreateDefaultService(); suppliedService.AddArgument("foo"); suppliedService.AddArgument("bar"); //string json = JsonConvert.SerializeObject(suppliedService); string json = suppliedService.ToJson(); Assert.That(json.Contains("foo"), Is.False, "Actual JSON: " + json); Assert.That(json.Contains("bar"), Is.False, "Actual JSON: " + json); }
private static void AssertSerializableProperties(PhantomJSDriverService suppliedService, PhantomJSDriverService deserializedService) { var serializableProperties = GetSerializableProperties(); foreach (var property in serializableProperties) { object expectedValue = property.GetValue(suppliedService, null); object actualValue = property.GetValue(deserializedService, null); Assert.That(expectedValue, Is.EqualTo(actualValue), string.Format("Value for property '{0}' did not match.", property.Name)); } }
private void InitializeProperties() { PropertyInfo[] properties = typeof(PhantomJSDriverService).GetProperties(); for (int i = 0; i < properties.Length; i++) { PropertyInfo propertyInfo = properties[i]; if (PhantomJSDriverService.IsSerializableProperty(propertyInfo)) { object propertyDefaultValue = PhantomJSDriverService.GetPropertyDefaultValue(propertyInfo); if (propertyDefaultValue != null) { propertyInfo.SetValue(this, propertyDefaultValue, null); } } } }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified driver service. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> used to initialize the driver.</param> public PhantomJSDriver(PhantomJSDriverService service) : this(service, new PhantomJSOptions()) { }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified <see cref="PhantomJSDriverService"/>. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), ConvertOptionsToCapabilities(options)) { // Add the custom commandInfo of PhantomJSDriver CommandInfo commandInfo = new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/phantom/execute"); this.CommandExecutor.CommandInfoRepository.TryAddCommand(CommandExecutePhantomScript, commandInfo); }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified /// <see cref="PhantomJSDriverService"/> and options. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { }
/// <summary> /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities()) { }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified /// <see cref="PhantomJSDriverService"/> and options. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { }
private static PhantomJSDriverService SerializeAndDeserializeService(PhantomJSDriverService suppliedService) { string json = JsonConvert.SerializeObject(suppliedService, Formatting.Indented); var deserializedService = JsonConvert.DeserializeObject<PhantomJSDriverService>(json); return deserializedService; }
public static PhantomJSDriverService CreateDefaultService(string driverPath) { return(PhantomJSDriverService.CreateDefaultService(driverPath, PhantomJSDriverService.PhantomJSDriverServiceFileName)); }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class with the desired options. /// </summary> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> public PhantomJSDriver(PhantomJSOptions options) : this(PhantomJSDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(60)) { }
public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), PhantomJSDriver.ConvertOptionsToCapabilities(options)) { CommandInfo commandInfo = new CommandInfo("POST", "/session/{sessionId}/phantom/execute"); base.CommandExecutor.CommandInfoRepository.TryAddCommand("executePhantomScript", commandInfo); }
/// <summary> /// Initializes a new instance of the <see cref="AdSenseDriver"/> class. /// </summary> /// <param name="service">The <see cref="T:OpenQA.Selenium.PhantomJS.PhantomJSDriverService" /> used to initialize the driver.</param> public AdSenseDriver(PhantomJSDriverService service) : base(service) { }
/// <summary> /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param> public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities()) { }
private static PhantomJSDriverService SerializeAndDeserializeServiceUsingToJson(PhantomJSDriverService suppliedService) { string json = suppliedService.ToJson(); var deserializedService = JsonConvert.DeserializeObject<PhantomJSDriverService>(json); return deserializedService; }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified path /// to the directory containing PhantomJS.exe, options, and command timeout. /// </summary> /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param> /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param> /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param> public PhantomJSDriver(string phantomJSDriverServerDirectory, PhantomJSOptions options, TimeSpan commandTimeout) : this(PhantomJSDriverService.CreateDefaultService(phantomJSDriverServerDirectory), options, commandTimeout) { }
private static void AssertSerializableProperties(PhantomJSDriverService suppliedService, PhantomJSDriverService deserializedService) { var serializableProperties = GetSerializableProperties(); foreach (var property in serializableProperties) { object expectedValue = property.GetValue(suppliedService, null); object actualValue = property.GetValue(deserializedService, null); Assert.That(expectedValue, Is.EqualTo(actualValue), string.Format("Value for property '{0}' did not match.", property.Name)); } }
private static string GetCommandLineArgumentsViaReflection(PhantomJSDriverService driverService) { // Use reflection to access protected CommandLineArguments property var commandLineArgumentsProperty = typeof(PhantomJSDriverService).GetProperty("CommandLineArguments", BindingFlags.NonPublic | BindingFlags.Instance); var commandLineArguments = commandLineArgumentsProperty.GetValue(driverService, null) as string; return commandLineArguments; }
private static PhantomJSDriverService SerializeAndDeserializeServiceUsingToJson(PhantomJSDriverService suppliedService) { string json = suppliedService.ToJson(); var deserializedService = JsonConvert.DeserializeObject <PhantomJSDriverService>(json); return(deserializedService); }
/// <summary> /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified driver service. /// </summary> /// <param name="service">The <see cref="PhantomJSDriverService"/> used to initialize the driver.</param> public PhantomJSDriver(PhantomJSDriverService service) : this(service, new PhantomJSOptions()) { }
public static PhantomJSDriverService CreateDefaultService() { string driverPath = DriverService.FindDriverServiceExecutable(PhantomJSDriverService.PhantomJSDriverServiceFileName, PhantomJSDriverService.PhantomJSDownloadUrl); return(PhantomJSDriverService.CreateDefaultService(driverPath)); }