/// <summary> /// The actual method to get the test set/case/step data. /// </summary> /// <param name="testDataType"> 0 = testSetData, 1 = testCaseData, 2 = testStepData. </param> /// <param name="dataTypeName"> Name where to get the data from. </param> /// <param name="dataTypeLocation"> Arguments for the data. </param> /// <returns> The test data.</returns> private ITestData GetTestData(int testDataType, string dataTypeName, string dataTypeLocation) { ITestData testData = null; switch (testDataType) { case 0: testData = ReflectiveGetter.GetImplementationOfType <ITestSetData>(dataTypeLocation) .Find(x => x.Name.ToLower().Equals(dataTypeName.ToLower())); break; case 1: testData = ReflectiveGetter.GetImplementationOfType <ITestCaseData>(dataTypeLocation) .Find(x => x.Name.ToLower().Equals(dataTypeName.ToLower())); break; case 2: testData = ReflectiveGetter.GetImplementationOfType <ITestStepData>(dataTypeLocation) .Find(x => x.Name.ToLower().Equals(dataTypeName.ToLower())); break; default: throw new Exception("Not a valid testDataType"); } if (testData == null) { Console.WriteLine($"Sorry we do not currently support reading tests from: {dataTypeName}"); throw new Exception($"Cannot Find test data type {dataTypeName}"); } testData.SetUp(); return(testData); }
/// <inheritdoc/> public ITestStep SetUpTestStep(string testStepFileLocation, bool performAction = true) { TextInteractor interactor = new TextInteractor(testStepFileLocation); Dictionary <string, string> args = new Dictionary <string, string>(); interactor.Open(); while (!interactor.FinishedReading()) { this.FileData.Add(interactor.ReadLine()); } interactor.Close(); string[] values = this.FileData[0].Split(';'); TestStep testStep = ReflectiveGetter.GetEnumerableOfType <TestStep>() .Find(x => x.Name.Equals(values[1])); testStep.Name = values[0]; foreach (string arg in values[2].Split(',')) { string[] value = arg.Split('='); args.Add(value[0], value[1]); } testStep.Arguments = args; return(testStep); }
/// <summary> /// Gets the next Test Step. /// </summary> /// <returns>The next Test Step.</returns> public ITestStep GetNextTestStep() { if (this.testStepQueue.Count == 0) { string url = this.TestSetSheet.GetRow(this.RowIndex).GetCell(URLCOL)?.ToString() ?? string.Empty; string action = this.TestSetSheet.GetRow(this.RowIndex).GetCell(ACTIONCOL)?.ToString() ?? string.Empty; string xpath = this.TestSetSheet.GetRow(this.RowIndex).GetCell(XPATHCOL)?.ToString() ?? string.Empty; string permission = this.TestSetSheet.GetRow(this.RowIndex).GetCell(this.ColIndex)?.ToString() ?? string.Empty; string value; TestStep testStep; this.CheckPageNavigation(url); value = this.GetValue(permission); try { testStep = ReflectiveGetter.GetEnumerableOfType <TestStep>() .Find(x => x.Name.Equals(action)); testStep.Arguments.Add("value", value); testStep.Arguments.Add("comment", "xpath"); testStep.Arguments.Add("object", xpath); this.testStepQueue.Enqueue(testStep); } catch (System.NullReferenceException) { if (action == string.Empty) { Logger.Error("Missing Test Action!"); // throw new System.Exception("Missing Test Action!"); } else { Logger.Error("Cannot Find Test Step: " + action); } } this.RowIndex++; } return((TestStep)this.testStepQueue.Dequeue()); }
private ITestStep BuildTestStep(XmlNode testStepNode, bool performAction = true) { TestStep testStep = null; string name = this.ReplaceIfToken(testStepNode.Attributes["name"].Value, this.XMLDataFile); // initial value is respectRunAODAFlag // if we respect the flag, and it is not found, then default value is false. bool runAODA = InformationObject.RespectRunAODAFlag; if (runAODA) { if (testStepNode.Attributes["runAODA"] != null) { runAODA = bool.Parse(testStepNode.Attributes["runAODA"].Value); } else { runAODA = false; } } // populate runAODAPageName. Deault is Not provided. string runAODAPageName = "Not provided."; if (runAODA) { if (testStepNode.Attributes["runAODAPageName"] != null) { runAODAPageName = this.ReplaceIfToken(testStepNode.Attributes["runAODAPageName"].Value, this.XMLDataFile); } } // log is true by default. bool log = true; if (testStepNode.Attributes["log"] != null) { log = bool.Parse(testStepNode.Attributes["log"].Value); } Logger.Debug($"Test step '{name}': runAODA->{runAODA} runAODAPageName->{runAODAPageName} log->{log}"); testStep = ReflectiveGetter.GetEnumerableOfType <TestStep>() .Find(x => x.Name.Equals(testStepNode.Name)); if (testStep == null) { Logger.Error($"Was not able to find the provided test action '{testStepNode}'."); } else { for (int index = 0; index < testStepNode.Attributes.Count; index++) { testStepNode.Attributes[index].InnerText = this.ReplaceIfToken(testStepNode.Attributes[index].InnerText, this.XMLDataFile); string key = Resource.Get(testStepNode.Attributes[index].Name); if (key == null) { key = testStepNode.Attributes[index].Name; } testStep.Arguments.Add(key, testStepNode.Attributes[index].InnerText); } testStep.Name = name; testStep.ShouldLog = log; testStep.ShouldExecuteVariable = performAction; testStep.RunAODA = runAODA; testStep.RunAODAPageName = runAODAPageName; } return(testStep); }
/// <summary> /// The A Test Step. /// </summary> /// <param name="row">The row<see cref="T:List{object}"/>.</param> /// <returns>The <see cref="ITestStep"/>.</returns> private TestStep CreateTestStep(List <object> row) { TestStep testStep; // // ignore TESTCASE string testStepDesc = row[1]?.ToString() ?? string.Empty; // TESTCASEDESCRIPTION string action = row[3]?.ToString() ?? string.Empty; // ACTIONONOBJECT (test action) string obj = row[4]?.ToString() ?? string.Empty; // OBJECT string value = row[5]?.ToString() ?? string.Empty; // VALUE (of the control/field) string comment = row[6]?.ToString() ?? string.Empty; // COMMENTS (selected attribute) string stLocAttempts = row[8]?.ToString() ?? "0"; // LOCAL_ATTEMPTS string stLocTimeout = row[9]?.ToString() ?? "0"; // LOCAL_TIMEOUT string control = row[10]?.ToString() ?? string.Empty; // CONTROL string testStepType = row[12]?.ToString() ?? "0"; // TESTSTEPTYPE (formerly SEVERITY) string goToStep = row[13]?.ToString() ?? string.Empty; // GOTOSTEP int localAttempts = int.Parse(string.IsNullOrEmpty(stLocAttempts) ? "0" : stLocAttempts); if (localAttempts == 0) { localAttempts = 1; // alm.AlmGlobalAttempts; } int localTimeout = int.Parse(string.IsNullOrEmpty(stLocTimeout) ? "0" : stLocTimeout); if (localTimeout == 0) { localTimeout = int.Parse(GetEnvironmentVariable(EnvVar.TimeOutThreshold)); // alm.AlmGlobalTimeOut; } int testStepTypeId = int.Parse(string.IsNullOrEmpty(testStepType) ? "0" : testStepType); if (testStepTypeId == 0) { testStepTypeId = 1; } testStep = ReflectiveGetter.GetEnumerableOfType <TestStep>() .Find(x => x.Name.Equals(action)); if (testStep == null) { Logger.Error($"Sorry We can't find {action}"); } testStep.Description = testStepDesc; testStep.Arguments.Add("object", Helper.Cleanse(obj)); testStep.Arguments.Add("value", Helper.Cleanse(value)); testStep.Arguments.Add("comment", Helper.Cleanse(comment)); testStep.MaxAttempts = localAttempts; testStep.ShouldExecuteVariable = control != this.SKIP; if (testStepType != string.Empty) { switch (int.Parse(testStepType)) { case MANDATORY: // by default its manadatory settings. break; case IMPORTANT: break; case OPTIONAL: testStep.Optional = true; break; case CONDITIONAL: var nextsteps = goToStep.Split(',').Select(int.Parse).ToList(); this.NextTestStepPass = nextsteps[0]; this.NextTestStepFail = nextsteps[1]; break; case INVERTEDIMPORTANT: testStep.PassCondition = false; break; case INVERTEDMANDATORY: testStep.PassCondition = false; break; default: break; } } return(testStep); }