/// <summary> Deserialization implementation. </summary> public override bool Deserialize(XElement elem, ITypeData t, Action <object> setter) { if (t.DescendsTo(typeof(IDynamicStep)) == false) { return(false); } try { IDynamicStep step = (IDynamicStep)t.CreateInstance(Array.Empty <object>()); Serializer.Register(step); TryDeserializeObject(elem, TypeData.GetTypeData(step), setter, step, logWarnings: false); ITestStep genStep = step.GetStep(); bool res = true; if (elem.IsEmpty == false) { res = TryDeserializeObject(elem, TypeData.GetTypeData(genStep), setter, genStep, logWarnings: false); } else { setter(genStep); } Serializer.GetSerializer <TestStepSerializer>().FixupStep(genStep, true); return(res); } catch (Exception e) { Log.Error("Unable to deserialize step of type {0}. Error was: {1}", t, e.Message); Log.Debug(e); return(true); } }
/// <summary> /// Get corresponding Field value for field name /// </summary> /// <param name="fieldName"></param> /// <returns></returns> public override object GetFieldValue(string fieldName) { if (String.CompareOrdinal(fieldName, m_stepsFieldName) == 0) { List <SourceTestStep> sourceSteps = new List <SourceTestStep>(); foreach (ITestAction action in m_testCase.Actions) { ITestStep step = action as ITestStep; if (step != null) { SourceTestStep sourceStep = new SourceTestStep(); sourceStep.title = step.Title; sourceStep.expectedResult = step.ExpectedResult; sourceStep.attachments = new List <string>(); foreach (var attachment in step.Attachments) { sourceStep.attachments.Add(attachment.Name); } sourceSteps.Add(sourceStep); } } return(sourceSteps); } else { return(base.GetFieldValue(fieldName)); } }
/// <summary> /// Replaces the steps information shared step. /// </summary> /// <param name="sharedStep">The shared step.</param> /// <param name="testSteps">The test steps.</param> private void ReplaceStepsInSharedStep(SharedStep sharedStep, List <TestStep> testSteps) { if (this.ReplaceContext.ReplaceInTestSteps) { sharedStep.ISharedStep.Actions.Clear(); List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { ITestStep testStepCore = sharedStep.ISharedStep.CreateTestStep(); if (this.ReplaceContext.ReplaceInTestSteps) { string newActionTitle = currentStep.ActionTitle.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs); log.InfoFormat("Change Test step action title from \"{0}\" to \"{1}\"", currentStep.ActionTitle, newActionTitle); testStepCore.Title = newActionTitle; string newActionexpectedResult = currentStep.ActionExpectedResult.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs); log.InfoFormat("Change Test step action expected result from \"{0}\" to \"{1}\"", currentStep.ActionExpectedResult, newActionexpectedResult); testStepCore.ExpectedResult = newActionexpectedResult; } else { testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; } sharedStep.ISharedStep.Actions.Add(testStepCore); } } }
protected sealed override List <CasTransactionOutcome> ExecuteTests(TestCasConnectivity.TestCasConnectivityRunInstance instance) { TaskLogger.LogEnter(); try { VirtualDirectoryUriScope virtualDirectoryUriScope; Uri testUri = this.GetTestUri(instance, out virtualDirectoryUriScope); base.WriteVerbose(Strings.CasHealthWebAppStartTest(testUri)); IRequestAdapter requestAdapter = this.CreateRequestAdapter(virtualDirectoryUriScope); IExceptionAnalyzer exceptionAnalyzer = this.CreateExceptionAnalyzer(testUri); IResponseTracker responseTracker = this.CreateResponseTracker(); IHttpSession session = this.CreateHttpSession(requestAdapter, exceptionAnalyzer, responseTracker, instance); this.HookupEventHandlers(session); CasTransactionOutcome casTransactionOutcome = this.CreateOutcome(instance, testUri, responseTracker); string userName; string domain; SecureString secureString; this.GetUserParameters(instance, out userName, out domain, out secureString); ITestStep testStep = this.CreateScenario(instance, testUri, userName, domain, secureString, virtualDirectoryUriScope, instance.CasFqdn); testStep.BeginExecute(session, new AsyncCallback(this.ScenarioExecutionFinished), new object[] { testStep, instance, responseTracker, casTransactionOutcome, secureString }); } finally { TaskLogger.LogExit(); } return(null); }
/// <summary> Deserialization implementation. </summary> public override bool Deserialize(XElement elem, ITypeData t, Action <object> setResult) { if (t.IsA(typeof(TestStepList)) == false) { return(false); } var steps = new TestStepList(); foreach (var subnode in elem.Elements()) { ITestStep result = null; try { if (!Serializer.Deserialize(subnode, x => result = (ITestStep)x)) { Log.Warning(subnode, "Unable to deserialize step."); continue; // skip to next step. } } catch (Exception ex) { Log.Error(ex); continue; } if (result != null) { steps.Add(result); } } setResult(steps); return(true); }
/// <summary> /// Ensures that duplicate step IDs are not present in the test plan and updates an ID->step mapping. /// </summary> /// <param name="step">the step to fix.</param> /// <param name="recurse"> true if child steps should also be 'fixed'.</param> public void FixupStep(ITestStep step, bool recurse) { if (stepLookup.TryGetValue(step.Id, out ITestStep currentStep) && currentStep != step && !ignoredGuids.Contains(step.Id)) { step.Id = Guid.NewGuid(); if (step is IDynamicStep) { // if newStep is an IDynamicStep, we just print in debug. Log.Debug("Duplicate test step ID found in dynamic step. The duplicate ID has been changed for step '{0}'.", step.Name); } else { Log.Warning("Duplicate test step ID found. The duplicate ID has been changed for step '{0}'.", step.Name); } } stepLookup[step.Id] = step; if (recurse == false) { return; } foreach (var step2 in step.ChildTestSteps) { FixupStep(step2, true); } }
/// <summary> /// Saves the specified shared step. /// </summary> /// <param name="sharedStep">The shared step.</param> /// <param name="createNew">if set to <c>true</c> [create new].</param> /// <param name="newSuiteTitle">The new suite title.</param> /// <param name="testSteps">The test steps.</param> /// <returns></returns> public static SharedStep Save(this SharedStep sharedStep, ITestManagementTeamProject testManagementTeamProject, bool createNew, ICollection <TestStep> testSteps, bool shouldSetArea = true) { SharedStep currentSharedStep = sharedStep; if (createNew) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Create(); currentSharedStep = new SharedStep(sharedStepCore); } if (shouldSetArea) { currentSharedStep.ISharedStep.Area = sharedStep.Area; } currentSharedStep.ISharedStep.Title = sharedStep.Title; currentSharedStep.ISharedStep.Priority = (int)sharedStep.Priority; currentSharedStep.ISharedStep.Actions.Clear(); currentSharedStep.ISharedStep.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sharedStep.TeamFoundationId); List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { ITestStep testStepCore = currentSharedStep.ISharedStep.CreateTestStep(); testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; currentSharedStep.ISharedStep.Actions.Add(testStepCore); } currentSharedStep.ISharedStep.Flush(); currentSharedStep.ISharedStep.Save(); return(currentSharedStep); }
private ITestStep RunIfTestStepLayer(bool performAction = true) { ITestStep testStep = null; XmlNode currentNode; while (this.testStack.Count > 0 && testStep == null) { currentNode = this.testStack.Pop(); performAction = this.performStack.Pop(); if (currentNode.Name == "If") { this.RunThenElseLayer(currentNode, performAction); } else if (currentNode.Name == "RunTestStep") { testStep = InformationObject.TestStepData.SetUpTestStep(this.ReplaceIfToken(currentNode.InnerText, this.XMLDataFile), performAction); } else { Logger.Warn($"We currently do not deal with this: {currentNode.Name}"); } } return(testStep); }
private void ScenarioExecutionFinished(IAsyncResult result) { TaskLogger.LogEnter(); object[] array = result.AsyncState as object[]; ITestStep testStep = array[0] as ITestStep; TestCasConnectivity.TestCasConnectivityRunInstance testCasConnectivityRunInstance = array[1] as TestCasConnectivity.TestCasConnectivityRunInstance; IResponseTracker responseTracker = array[2] as IResponseTracker; CasTransactionOutcome casTransactionOutcome = array[3] as CasTransactionOutcome; SecureString secureString = array[4] as SecureString; try { testStep.EndExecute(result); this.CompleteSuccessfulOutcome(casTransactionOutcome, testCasConnectivityRunInstance, responseTracker); } catch (Exception ex) { testCasConnectivityRunInstance.Outcomes.Enqueue(TestWebApplicationConnectivity2.GenerateVerboseMessage(ex.ToString())); this.CompleteFailedOutcome(casTransactionOutcome, testCasConnectivityRunInstance, responseTracker, ex); } finally { TaskLogger.LogExit(); if (secureString != null) { secureString.Dispose(); } if (testCasConnectivityRunInstance != null) { testCasConnectivityRunInstance.Outcomes.Enqueue(casTransactionOutcome); testCasConnectivityRunInstance.Result.Complete(); } } }
bool loadScopeParameter(Guid scope, ITestStep step, IMemberData member, string parameter) { ITestStepParent parent; if (scope == Guid.Empty) { parent = step.GetParent <TestPlan>(); } else { ITestStep subparent = step.Parent as ITestStep; while (subparent != null) { if (subparent.Id == scope) { break; } subparent = subparent.Parent as ITestStep; } parent = subparent; } if (parent == null) { return(false); } member.Parameterize(parent, step, parameter); return(true); }
/// <summary> /// Заполняет Excel таблицу данными по шагам тестового случая. /// </summary> /// <param name="testActions">Шаги теста.</param> private void BySteps(TestActionCollection testActions) { int stepId = 1; foreach (var stestStep in testActions) { ITestStep testStep = stestStep as ITestStep; if (testStep != null) { xlWorkSheet.Cells[row, 3] = stepId.ToString() + @". " + testStep.Title.ToPlainText(); xlWorkSheet.Cells[row, 4] = testStep.ExpectedResult.ToPlainText(); stepId++; row++; } else { //расшаренный шаг ISharedStep testStepS = stestStep as ISharedStep; if (testStepS != null) { xlWorkSheet.Cells[row, 3] = testStepS.Title.ToString() + @". " + testStep.Title.ToPlainText(); stepId++; row++; } } } }
internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig) { ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); _testStep = testStep; }
/// <summary> /// Initializes a new instance of the <see cref="TestStep" /> class. /// </summary> /// <param name="isShared">if set to <c>true</c> [is shared].</param> /// <param name="title">The title.</param> /// <param name="testStepGuid">The test step unique identifier.</param> /// <param name="testStepCore">The test step core.</param> public TestStep(bool isShared, string title, Guid testStepGuid, ITestStep testStepCore) : this(isShared, title, testStepGuid) { this.TestStepId = testStepCore.Id; this.ActionTitle = testStepCore.Title.ToPlainText(); this.ActionExpectedResult = testStepCore.ExpectedResult.ToPlainText(); this.OriginalActionTitle = testStepCore.Title.ToPlainText(); this.OriginalActionExpectedResult = testStepCore.ExpectedResult.ToPlainText(); this.isInitialized = true; }
internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig) { FailOnError = true; ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); _testStep = testStep; }
public ComparisonResult(ITestStep testStep, IExpectedContent expectedContent, IActualContent actualContent) { Guard.IsNotNull(testStep, nameof(testStep)); Guard.IsNotNull(expectedContent, nameof(expectedContent)); Guard.IsNotNull(actualContent, nameof(actualContent)); this.Step = testStep; lazyResult = new Lazy <bool>(() => expectedContent.CompareTo(actualContent)); }
/// <summary> Serialization implementation. </summary> public override bool Serialize(XElement elem, object obj, ITypeData expectedType) { if (currentNode.Contains(elem)) { return(false); } var objSerializer = Serializer.SerializerStack.OfType <IConstructingSerializer>().FirstOrDefault(); if (objSerializer?.CurrentMember == null || false == objSerializer.Object is ITestStep) { return(false); } ITestStep step = (ITestStep)objSerializer.Object; var member = objSerializer.CurrentMember; // here I need to check if any of its parent steps are forwarding // its member data. ITestStepParent parameterParemt = step.Parent; IMemberData parameterMember = null; while (parameterParemt != null && parameterMember == null) { var members = TypeData.GetTypeData(parameterParemt).GetMembers().OfType <IParameterMemberData>(); parameterMember = members.FirstOrDefault(x => x.ParameterizedMembers.Any(y => y.Source == step && y.Member == member)); if (parameterMember == null) { parameterParemt = parameterParemt.Parent; } } if (parameterMember == null) { return(false); } elem.SetAttributeValue(Parameter, parameterMember.Name); if (parameterParemt is ITestStep parentStep) { elem.SetAttributeValue(Scope, parentStep.Id.ToString()); } // skip try { currentNode.Add(elem); return(Serializer.Serialize(elem, obj, expectedType)); } finally { currentNode.Remove(elem); } }
/// <summary> /// Generates all the step data from a set of TFS test actions /// </summary> /// <param name="actions">Collection of steps from the tc.</param> /// <param name="id">TFS tc id for displaying a helpful error message.</param> /// <param name="site">Required for pushing embedded steps to matching Site.</param> /// <returns></returns> public List <TestStepData> GetStepData(TestActionCollection actions, int id, Site site) { List <TestStepData> stepList = new List <TestStepData>(); foreach (ITestAction action in actions) { if (action is ISharedStepReference) { // if action is a shared step, ensure it is pushed to RF ISharedStepReference sharedRef = action as ISharedStepReference; var failures = this.Operations.CopyTestToRainforest(new List <int> { sharedRef.SharedStepId }, null, site).Result; // get the RFID for the TFS SharedStep int?rfId = this.GetRFID(sharedRef.SharedStepId); if (rfId == null) { throw new Core.ServiceException(Core.Error.TFSSharedTestDoesNotExist, sharedRef.SharedStepId.ToString()); } // add to list stepList.Add(new TestStepData(sharedRef.SharedStepId, rfId, null, null)); } else if (action is ITestStep) { // action is a normal step, not shared ITestStep step = action as ITestStep; stepList.Add(new TestStepData(null, null, Regex.Replace(step.Title, @"<[^>]*>", ""), Regex.Replace(step.ExpectedResult, @"<[^>]*>", ""))); // check for empty step if (stepList.Last().Title.Trim().Equals("")) { stepList.RemoveAt(stepList.Count - 1); continue; } var lastExpectedResult = stepList.Last().ExpectedResult.Trim(); // check for empty expected result if (lastExpectedResult.Equals("")) { throw new Core.ServiceException(Core.Error.EmptyExpectedResult, id.ToString()); } // check for a question mark on the expected result if (lastExpectedResult.Trim().Last() != '?') { stepList.Last().ExpectedResult += '?'; } } else { throw new Exception("TestCase action is unknown type."); } // TOEX -> this case shouldn't be hit ever } return(stepList); }
/// <summary> /// Updates testcase's field with corresponding value /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> public override void UpdateField(string fieldName, object value) { // If value is null then just take the default valuea nd return the default value if (value == null) { return; } List <SourceTestStep> sourceSteps = value as List <SourceTestStep>; // If the value is a List of test steps then Update th testcase with test steps if (sourceSteps != null) { m_stepsFieldName = fieldName; foreach (SourceTestStep sourceStep in sourceSteps) { // Update the Test step's text with correct parameters string title = sourceStep.title; string expectedResult = sourceStep.expectedResult; if (m_areRichSteps) { // This is temporary. Work around for product issue. title = title.Replace("\r\n", "<P>").Replace("\n", "<P>").Replace("\r", "<P>"); expectedResult = expectedResult.Replace("\r\n", "<P>").Replace("\n", "<P>").Replace("\r", "<P>"); } // Creating TCM Test Step and filling testcase with them ITestStep step = m_testCase.CreateTestStep(); step.Title = title; // Set the TestStepType properly for validated steps if (!String.IsNullOrEmpty(expectedResult)) { step.ExpectedResult = expectedResult; step.TestStepType = TestStepType.ValidateStep; } if (sourceStep.attachments != null) { foreach (string filePath in sourceStep.attachments) { ITestAttachment attachment = step.CreateAttachment(filePath); step.Attachments.Add(attachment); } } m_testCase.Actions.Add(step); } } // else if it is a normal tfs field then just updates the tfs' testcase field else { base.UpdateField(fieldName, value); } }
/// <summary> /// Gets the activity. /// </summary> /// <param name="step">The step.</param> /// <returns></returns> /// <exception cref="InvalidOperationException">Do</exception> public static IActivity GetActivity(ITestStep step, IReporter reporter, IAutomationDriver driver) { if (_instance._activities.ContainsKey(step.Do)) { var activityType = _instance._activities[step.Do]; return((IActivity)Activator.CreateInstance(activityType, step, reporter, driver)); } throw new InvalidOperationException($"Invalid activity {nameof(step.Do)}"); }
internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig, bool runConcurrently, bool failOnError) { ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); _testStep = testStep; RunConcurrently = runConcurrently; FailOnError = failOnError; }
public TestStepForImage(IReadOnlyList <ICloudOCRService> ocrServices, IComputer computer, ITestStep action, ILogger logger, IEngineConfig config, IOpenCVSUtils openCVService) : base(ocrServices, config, computer, logger, openCVService) { _step = action; }
internal BizUnitTestStepWrapper(ITestStep testStep, XmlNode stepConfig, bool runConcurrently, bool failOnError) { ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); _testStep = testStep; RunConcurrently = runConcurrently; _failOnError = failOnError; }
private void SetProperty(ITestStep ts, PropertyInfo pInfo, string propertyName, string propertyType, string propertyValue) { if (propertyType == "System.Double") { double result; if (Double.TryParse(propertyValue, out result)) { pInfo.SetValue(ts, result, null); } } else if (propertyType == "System.Int32") { int result; if (Int32.TryParse(propertyValue, out result)) { pInfo.SetValue(ts, result, null); } } else if (propertyType == "System.String") { // ??? Why this happen ??? if (propertyName == "technology") { ((SelectTechnology)ts).technology = propertyValue; } else { pInfo.SetValue(ts, propertyValue, null); } } else if (propertyType == "System.Boolean") { bool result; if (bool.TryParse(propertyValue, out result)) { pInfo.SetValue(ts, result, null); } } else if (propertyType.StartsWith("Enumeration.")) { Type t = PluginGetType(pInfo.PropertyType.FullName); object value = Enum.Parse(t, propertyValue); pInfo.SetValue(ts, value, null); } else { throw new InvalidDataException ("Property[" + propertyName + "] type " + propertyType + "is not supported!"); } }
private async Task <IStepRunResult> RunStep(ITestStep testStep) { try { return(await testStep.Run(null)); } catch (Exception exception) { return(new ErrorResult(testStep, exception)); } }
private void writeTestSteps(ref Excel.Worksheet xlWorkSheet, ITestStep tStep, ref int iRow, ref int iColumn) { string strStep = Regex.Replace(tStep.Title, @"<[^>]+>| ", "").Trim(); string strExpectedResult = Regex.Replace(tStep.ExpectedResult, @"<[^>]+>| ", "").Trim(); iColumn = 2; xlWorkSheet.Cells[iRow, 11] = strStep; xlWorkSheet.Cells[iRow, 12] = strExpectedResult; xlWorkSheet.Cells[iRow, 9] = "Test Step"; iRow++; }
/// <summary> /// Replaces the test steps information in specific test case. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="testSteps">The test steps.</param> private void ReplaceStepsInTestCase(TestCase testCase, List <TestStep> testSteps) { if (this.ReplaceContext.ReplaceSharedSteps || this.ReplaceContext.ReplaceInTestSteps) { testCase.ITestCase.Actions.Clear(); List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { if (currentStep.IsShared && !addedSharedStepGuids.Contains(currentStep.TestStepGuid) && this.ReplaceContext.ReplaceSharedSteps) { if (this.ReplaceContext.ReplaceSharedSteps) { List <int> newSharedStepIds = this.GetNewSharedStepIds(currentStep.SharedStepId, this.ReplaceContext.ObservableSharedStepIdReplacePairs); foreach (int currentId in newSharedStepIds) { if (currentId != 0) { log.InfoFormat("Replace shared step with title= \"{0}\", id= \"{1}\" to \"{2}\"", currentStep.Title, currentStep.SharedStepId, currentId); this.AddNewSharedStepInternal(testCase, addedSharedStepGuids, currentStep, currentId); } else { log.InfoFormat("Remove shared step with title= \"{0}\", id= \"{1}\"", currentStep.Title, currentStep.SharedStepId); } } } else { this.AddNewSharedStepInternal(testCase, addedSharedStepGuids, currentStep, currentStep.SharedStepId); } } else if (!currentStep.IsShared) { ITestStep testStepCore = testCase.ITestCase.CreateTestStep(); if (this.ReplaceContext.ReplaceInTestSteps) { string newActionTitle = currentStep.ActionTitle.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs); log.InfoFormat("Change Test step action title from \"{0}\" to \"{1}\"", currentStep.ActionTitle, newActionTitle); testStepCore.Title = newActionTitle; string newActionexpectedResult = currentStep.ActionExpectedResult.ToString().ReplaceAll(this.ReplaceContext.ObservableTextReplacePairs); log.InfoFormat("Change Test step action expected result from \"{0}\" to \"{1}\"", currentStep.ActionExpectedResult, newActionexpectedResult); testStepCore.ExpectedResult = newActionexpectedResult; } else { testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; } testCase.ITestCase.Actions.Add(testStepCore); } } } }
private void ExecuteSteps(XmlNodeList steps) { if (null == steps) { return; } foreach (XmlNode stepConfig in steps) { bool runConcurrently = false; XmlNode assemblyPath = stepConfig.SelectSingleNode("@assemblyPath"); XmlNode typeName = stepConfig.SelectSingleNode("@typeName"); XmlNode runConcurrentlyNode = stepConfig.SelectSingleNode("@runConcurrently"); if (null != runConcurrentlyNode) { runConcurrently = Convert.ToBoolean(runConcurrentlyNode.Value); } object obj = CreateStep(typeName.Value, assemblyPath.Value); ITestStep step = obj as ITestStep; try { // Should this step be executed concurrently? if (runConcurrently) { this.logger.WriteLine(string.Format("\nStep: {0} started c o n c u r r e n t l y @ {1}", typeName.Value, GetNow())); Interlocked.Increment(ref this.inflightQueueDepth); ThreadPool.QueueUserWorkItem(new WaitCallback(this.WorkerThreadThunk), new ConcurrentTestStepWrapper(step, stepConfig, this, typeName.Value)); } else { this.logger.WriteLine(string.Format("\nStep: {0} started @ {1} ", typeName.Value, GetNow())); step.Execute(stepConfig, context); } } catch (Exception e) { this.logger.LogException(e); throw; } if (!runConcurrently) { this.logger.WriteLine(string.Format("Step: {0} ended @ {1}", typeName.Value, GetNow())); } FlushConcurrentQueue(false); } FlushConcurrentQueue(true); }
private void ExecuteStep(ITestCase tc, ITestStep step) { step.ActualResult = ""; if (step.Action.IsElementDependent) ExecuteElementDependentAction(tc, step); else TryExecuteNonElementDependentAction(tc, step); PrepareDefectIfAny(tc, step); }
/// <summary> /// Used to add a test step to a test case at a specific stage of the test. /// </summary> /// /// <param name='testStep'>The test step to add to the test case.</param> /// <param name='config'>The configuration for the test step to be used when it is executed.</param> /// <param name='stage'>The stage of the test case in which to add the test step</param> /// <param name='runConcurrently'>Specifies whether the test step /// should run concurrently to other test steps. Defaults to false if not specified.</param> /// <param name='failOnError'>Specifies whether the entire test case /// should fail if this individual test step fails, defaults to true if not specified.</param> public void AddTestStep(ITestStep testStep, string config, TestStage stage, bool runConcurrently, bool failOnError) { ArgumentValidation.CheckForNullReference(testStep, "testStep"); ArgumentValidation.CheckForNullReference(config, "config"); var doc = new XmlDocument(); doc.LoadXml(config); XmlNode configNode = doc.DocumentElement; AddTestStepInternal(new BizUnitTestStepWrapper(testStep, configNode, runConcurrently, failOnError), stage); }
private static void LoadTestSteps(ITestCase testCase, Microsoft.TeamFoundation.TestManagement.Client.ITestCase newTestCase) { foreach (ITestCaseStep step in testCase.Steps) { ITestStep testStep = newTestCase.CreateTestStep(); testStep.Title = step.Actions; testStep.Description = step.Actions; testStep.ExpectedResult = step.ExpectedResults; testStep.TestStepType = string.IsNullOrEmpty(testStep.ExpectedResult) ? TestStepType.ActionStep : TestStepType.ValidateStep; newTestCase.Actions.Add(testStep); } }
/// <summary> /// Initializes a new instance of the <see cref="NavigateActivity" /> class. /// </summary> /// <param name="step">The step.</param> /// <param name="reporter">The reporter.</param> /// <param name="driver">The driver.</param> /// <exception cref="System.ArgumentException">Argument</exception> public NavigateActivity(ITestStep step, IReporter reporter, IAutomationDriver driver) : base(step, reporter, driver) { if (!Uri.IsWellFormedUriString(step.Argument, UriKind.Absolute)) { throw new ArgumentException($"{nameof(step.Argument)} is not a valid Uri. A valid absolute Uri must be specified."); } Action = ActivityTypes.Navigate; _argument = step.Argument; _element = step.Element; }
/// <inheritdoc/> public ITestStep GetNextTestStep() { // reached end of loop, check if should loop again. if (this.testStack.Count == 0 && this.ShouldExecuteAmountOfTimes > this.ExecuteCount) { this.AddNodesToStack(this.TestFlow); this.ExecuteCount += 1; } ITestStep testStep = this.RunIfTestStepLayer(); return(testStep); }
/// <summary> /// Creates the new shared step. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="sharedStepTitle">The shared step title.</param> /// <param name="stepTitle">The step title.</param> /// <param name="expectedResult">The expected result.</param> /// <returns>the shared step core object</returns> public static ISharedStep CreateNewSharedStep(TestCase testCase, string sharedStepTitle, string stepTitle, string expectedResult) { ISharedStepReference sharedStepReferenceCore = testCase.ITestCase.CreateSharedStepReference(); ISharedStep sharedStepCore = ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; sharedStepCore.Title = sharedStepTitle; ITestStep testStepCore = sharedStepCore.CreateTestStep(); testStepCore.ExpectedResult = expectedResult; testStepCore.Title = stepTitle; sharedStepCore.Actions.Add(testStepCore); return sharedStepCore; }
internal BizUnitTestStepWrapper(XmlNode stepConfig) { FailOnError = true; ArgumentValidation.CheckForNullReference(stepConfig, "stepConfig"); LoadStepConfig(stepConfig); object obj = ObjectCreator.CreateStep(TypeName, _assemblyPath); _testStep = obj as ITestStep; if (null == _testStep) { throw new ArgumentException(string.Format("The test step could not be created, check the test step type and assembly path are correct, type: {0}, assembly path: {1}", TypeName, _assemblyPath)); } }
protected override void RunTestsInternal(ITestCommand rootTestCommand, ITestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor) { using (progressMonitor) { progressMonitor.BeginTask("Verifying Specifications", rootTestCommand.TestCount); if (options.SkipTestExecution) { SkipAll(rootTestCommand, parentTestStep); } else { RunTest(rootTestCommand, parentTestStep, progressMonitor); } } }
public static void Verify(StringBuilder scenarioDescription, ITestStep testStep, ExceptionConfiguration exceptionConfiguration) { scenarioDescription.Append(testStep.Description); try { testStep.Action(); scenarioDescription.AppendLine(testStep.SuccessSuffix); } catch (Exception e) { if (!exceptionConfiguration.ExpectException) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw; } var exceptionType = e.GetType(); if (exceptionType != exceptionConfiguration.ExpectedExceptionType) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception of type {0} but caught type {1}", exceptionConfiguration.ExpectedExceptionType, exceptionType), e); } if (exceptionConfiguration.ExpectExceptionMessage) { if (e.Message != exceptionConfiguration.ExpectedExceptionMessage) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception message '{0}' but had '{1}'", exceptionConfiguration.ExpectedExceptionMessage, e.Message), e); } } exceptionConfiguration.CaughtExpectedException(); scenarioDescription.AppendLine(testStep.SuccessSuffix); } }
private void RunTest(ITestCommand testCommand, ITestStep parentTestStep, IProgressMonitor progressMonitor) { ITest test = testCommand.Test; progressMonitor.SetStatus(test.Name); MachineSpecificationTest specification = test as MachineSpecificationTest; MachineContextTest description = test as MachineContextTest; if (specification != null) { //RunContextTest(specification, testComman); } else if (description != null) { RunContextTest(description, testCommand, parentTestStep); } else { Debug.WriteLine("Got something weird " + test.GetType().ToString()); } }
private void ExecuteElementDependentAction(ITestCase tc, ITestStep step) { try { TryExecuteElementDependentAction(tc, step); } catch (ElementNotFound) { step.ActualResult = MySetup.Default.ElementNotFoundText; } catch (NotAbleToClick ex) { step.ActualResult = ex.Message; } catch (NotAbleToExecuteAction ex) { step.ActualResult = ex.Message; } finally { SaveActualResult(tc, step); } }
private void RunContextTest(MachineContextTest description, ITestCommand testCommand, ITestStep parentTestStep) { ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep); testContext.LifecyclePhase = LifecyclePhases.SetUp; description.SetupContext(); bool passed = true; foreach (ITestCommand child in testCommand.Children) { MachineSpecificationTest specification = child.Test as MachineSpecificationTest; if (specification != null) { passed &= RunSpecificationTest(specification, child, testContext.TestStep); } } testContext.LifecyclePhase = LifecyclePhases.TearDown; description.TeardownContext(); testContext.FinishStep(passed ? TestOutcome.Passed : TestOutcome.Failed, null); }
private IWebElement GetElement(ITestStep step) { try { return _executor.GetElement(step.Action); } catch (ElementNotFound) { return _executor.GetElement(step.Action); } }
private bool RunSpecificationTest(MachineSpecificationTest specification, ITestCommand testCommand, ITestStep parentTestStep) { ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep); testContext.LifecyclePhase = LifecyclePhases.Execute; var result = specification.Execute(); if (result.Passed) { testContext.FinishStep(TestOutcome.Passed, null); } else { testContext.FinishStep(TestOutcome.Failed, null); } return result.Passed; }
private void SaveActualResult(ITestCase tc, ITestStep step) { _testWriter.SaveStepStatus(_browserName, tc, step); }
private void TryExecuteElementDependentAction(ITestCase tc, ITestStep step) { var element = GetElement(step); SaveElementTag(step.ID, element); if (step.Action.IsReturningValue) step.ActualResult = _executor.ExecuteElementDependentReadingAction(step.Action, element); else _executor.ExecuteElementDependentActionCommand(step.Action, element); }
private void TryExecuteNonElementDependentAction(ITestCase tc, ITestStep step) { try { if (step.Action.IsReturningValue) step.ActualResult = _executor.ExecuteNonElementDependentReadingAction(step.Action); else _executor.ExecuteNonElementDependentAction(step.Action); } catch (NotAbleToExecuteAction ex) { step.ActualResult = ex.Message; } finally { SaveActualResult(tc, step); } }
private void PrepareDefectIfAny(ITestCase tc, ITestStep step) { if (IsFailed(step.Status)) PrepareDefect(tc, step.ID); }
private void PopulateTestStep(ITestStep step, string title, string expectedResult) { step.Title = GetStepText(title); step.ExpectedResult = GetStepText(expectedResult); step.TestStepType = String.IsNullOrWhiteSpace(expectedResult) ? TestStepType.ActionStep : TestStepType.ValidateStep; }