private void TrySetupSteps(DriverType driverType, SeleniteTest test, IWebDriver webDriver) { if (test.TestCollection.SetupSteps.IsNullOrNotAny()) return; var fileName = String.IsNullOrWhiteSpace(test.TestCollection.SetupStepsFile) ? test.TestCollection.ResolvedFile : test.TestCollection.SetupStepsFile; foreach (var pair in _setupStepsMap) { if (pair.Key.Target != webDriver) continue; if (pair.Value.Any(f => String.Equals(f, fileName, StringComparison.InvariantCultureIgnoreCase))) return; } foreach (var setupStep in test.TestCollection.SetupSteps) _testService.ExecuteTest(webDriver, driverType, setupStep, true); var weakReference = new WeakReference(webDriver); var testFiles = new List<string> { fileName }; _setupStepsMap.Add(weakReference, testFiles); }
public ICommand CreateCommand(dynamic command, SeleniteTest test) { string name = command.Name; if (String.IsNullOrWhiteSpace(name)) throw new ArgumentException("Command name not specified"); var type = CommandTypeMap.Value[name]; if (type == null) throw new ArgumentException("Command not found: " + name); dynamic result = Activator.CreateInstance(type); var properties = GetProperties(type); foreach (var property in properties) { var pValue = command[property.Name]; var jValue = pValue as JValue; var value = jValue == null ? (object) pValue : jValue.Value; if (value == null) continue; var converted = Convert.ChangeType(value, property.PropertyType); property.InvokeSetMethod((object) result, converted); } var commandBase = (CommandBase)result; commandBase.Test = test; commandBase.Validate(); return commandBase; }
public void ExecuteTest(DriverType driverType, SeleniteTest test) { var webDriver = _driverFactory.GetBrowser(driverType); TrySetupSteps(driverType, test, webDriver); _testService.ExecuteTest(webDriver, driverType, test); }
public ICommand CreateCommand(string name, IDictionary<string, string> values, SeleniteTest test) { dynamic command = new {Name = name}; foreach (var value in values) command[value.Key] = value.Value; return CreateCommand(command, test); }
private string GenerateTestMethod(string testCollectionRelativePath, Manifest manifest, SeleniteTest test) { var tokenReplacer = new Func<Match, string>(match => { switch (match.Value) { case "@{TestName}": return test.Name; case "@{OverrideDomain}": return manifest.OverrideDomain; case "@{TestCollectionName}": return testCollectionRelativePath; case "@{TestCollectionNameFriendly}": var extension = Path.GetExtension(testCollectionRelativePath); var pathWithoutExtension = testCollectionRelativePath.Substring(0, testCollectionRelativePath.Length - extension.Length); var cleanName = DisallowedTestNamePattern.Replace(pathWithoutExtension, "_"); cleanName = cleanName.TrimStart('_'); return cleanName; case "@{TestNameFriendly}": return DisallowedTestNamePattern.Replace(test.Name, "_"); case "@{TestJson}": return JsonConvert.SerializeObject(test, Formatting.Indented); case "@{SkipParameter}": if (!test.TestCollection.Enabled) return "(Skip = \"Disabled in Test Collection JSON\")"; if (!test.Enabled) return "(Skip = \"Disabled in Test JSON\")"; return string.Empty; default: throw new InvalidOperationException("Invalid token: " + match.Value); } }); return TokenFinder.Replace(TestMethodTemplate, new MatchEvaluator(tokenReplacer)); }
private SeleniteTest CreateTest(TestCollection testCollection, dynamic test, string domain, bool isEnabled = true) { var url = test.Url.ToString(); var baseUri = domain.EndsWith("/") ? new Uri(domain) : new Uri(domain + "/"); var relativeUri = new Uri(baseUri, url); var testInstance = new SeleniteTest { TestCollection = testCollection, Enabled = isEnabled, Name = test.Name, Description = test.Description, Url = url, TestUrl = relativeUri.ToString(), Macros = GetDictionaryFromJObject(test.Macros) }; var commands = new List<ICommand>(); foreach (var command in test.Commands) commands.Add(_commandService.CreateCommand(command, testInstance)); testInstance.Commands = commands; return testInstance; }