private XTestStepValue GetOrCreateApiXTestStepValue(XTestStep apiTestStep, KeyValuePair <string, string> wseTestStepValue) { XTestStepValue apiTeststepValue = (XTestStepValue)apiTestStep .Search(string.Format(TqlToGetApiTestStepValue, wseTestStepValue.Key)) .FirstOrDefault(); //if xTestStepValue not present,create it. if (apiTeststepValue == null) { //check if module attribute is present. var xModuleAttribute = (XModuleAttribute)apiTestStep .Module.Search( string.Format(TqlToGetModuleAttributeInApiModule, wseTestStepValue.Key)).FirstOrDefault(); //if not present, Create it. if (xModuleAttribute == null) { XModuleAttribute m = CreateModuleAttribute(apiTestStep.Module as ApiModule, wseTestStepValue); apiTeststepValue = apiTestStep.CreateXTestStepValue(m); } //if already present, use it. else { apiTeststepValue = apiTestStep.CreateXTestStepValue(xModuleAttribute); } } return(apiTeststepValue); }
static void Main(string[] args) { using (TCAPI tcapi = TCAPI.CreateInstance()) { TCWorkspace workspace = tcapi.OpenWorkspace(@"C:\Users\estan\Desktop\trainings\TOSCA Customizations\Tosca Workspace\Training Customizations\Training Customizations.tws", "Admin", ""); TCProject project = workspace.GetProject(); List <TCObject> result = project.Search($"=>SUBPARTS:TCFolder[UniqueId==\"{unique_id_test_case_folder}\"]"); TCFolder testCaseFolder = (TCFolder)result.First(); testCaseFolder.Checkout(); TestCase testCase = testCaseFolder.CreateTestCase(); testCase.Name = "Test Creating Test Case"; XModule tboxSetBuffer = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_set_buffer}\"]").First(); XModule tboxWait = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_wait}\"]").First(); XTestStep setBufferTestStep = testCase.CreateXTestStepFromXModule(tboxSetBuffer); XTestStepValue setBUfferStepvalue = setBufferTestStep.CreateXTestStepValue(tboxSetBuffer.Attributes.First()); setBUfferStepvalue.Name = "Test Buffer Creation"; setBUfferStepvalue.Value = "42"; setBUfferStepvalue.ActionMode = XTestStepActionMode.Input; XTestStep tboxSetWaitTimeStep = testCase.CreateXTestStepFromXModule(tboxWait); XTestStepValue tboxWaitSettimeStepValue = tboxSetWaitTimeStep.TestStepValues.First(); tboxWaitSettimeStepValue.Value = "500"; } }
private static void CreateBodyParameterAtTeststepLevel(List <XTestStepValue> tcObjects, XModuleAttribute bodyAttribute, XTestStep apiTestStep) { foreach (XTestStepValue wseTestStepValue in tcObjects) { var apiTestStepValue = apiTestStep.CreateXTestStepValue(bodyAttribute); if (wseTestStepValue.SpecializationModule.Name == "Web service request data in XML Resource" || wseTestStepValue.SpecializationModule.Name == "Web service request data in JSON Resource") { apiTestStepValue.DataType = wseTestStepValue.DataType; apiTestStepValue.ActionMode = XTestStepActionMode.Insert; if (!wseTestStepValue.Value.IsNullOrBlankInTosca()) { apiTestStepValue.Value = "{RES[" + wseTestStepValue.Value + "]}"; } break; } if (wseTestStepValue.SpecializationModule.Name == "Plain Text") { if (wseTestStepValue.SubValues != null && wseTestStepValue.SubValues.Any()) { apiTestStepValue.DataType = wseTestStepValue.SubValues.First().DataType; apiTestStepValue.ActionMode = wseTestStepValue.SubValues.First().ActionMode; //if (StringExtensions.IsNullOrBlank(wTestStepValue)) apiTestStepValue.Value = wseTestStepValue.SubValues.FirstOrDefault(x => x.Name == "Value")?.Value; } if (!string.IsNullOrEmpty(apiTestStepValue.Value)) { apiTestStepValue.Value = CommonUtilities.RemoveExtraDoubleQuotes(apiTestStepValue.Value); } break; } var wTestStepValue = wseTestStepValue.SubValues.FirstOrDefault(x => x.Name == "Filepath")?.Value; if (!wTestStepValue.IsNullOrBlankInTosca()) { apiTestStepValue.ActionProperty = $"File"; apiTestStepValue.Operator = Operator.Equals; apiTestStepValue.Value = wTestStepValue; apiTestStepValue.ActionMode = XTestStepActionMode.Select; } } }
public void CreateTestStepFromSET(string setName, Dictionary <string, TestStepValueData> testStepValues) { TestStepFolder testStepFolder = parentObject as TestStepFolder; if (testStepFolder == null) { throw new NullReferenceException("CurrentFolder is not set"); } string query = "->PROJECT->AllOwnedSubItems=>SUBPARTS:XModule[SetWizard ==\"" + setName + "\"]"; TCObject tcObject = testStepFolder.Search(query)[0]; XModule xModule = tcObject as XModule; if (xModule == null) { return; } XTestStep testStep = testStepFolder.CreateXTestStepFromXModule(xModule); foreach (KeyValuePair <string, TestStepValueData> testStepValuePair in testStepValues) { foreach (XModuleAttribute xModuleAttribute in xModule.Attributes) { if (xModuleAttribute.Name != testStepValuePair.Key) { continue; } XTestStepValue testStepValue = testStep.CreateXTestStepValue(xModuleAttribute); TestStepValueData testStepValueData = testStepValuePair.Value; testStepValue.Value = testStepValueData.Value; testStepValue.ActionMode = ConvertActionMode(testStepValueData.ActionMode); } } }
public void Execute(XTestStep apiTestStep, XTestStep wseTestStep) { try { //Get Raw Value XTestStepValue wseTestStepValue = (XTestStepValue)wseTestStep.Search(TqlToGetWseTestStepValue).FirstOrDefault(); if (wseTestStepValue == null) { return; } //Extract value need to be filled in api test step string wseValue = GetRefinedWseTestStepValue(wseTestStepValue.Value); //Note: we ignore this step in case of response. if (!IsResponseTestStepValue) { //get api value string apiValue = GetValueInApiModule(apiTestStep.Module as ApiModule); //if values match,do nothing. if (!Regex.IsMatch(wseValue, @"\{.*\}") && apiValue == wseValue) { return; } } //if values does not match , Search if there is already a API xTestStepValue present. XTestStepValue apiTeststepValue = (XTestStepValue)apiTestStep.Search(TqlToGetApiTestStepValue).FirstOrDefault(); //if xTestStepValue not present,create it. if (apiTeststepValue == null) { //check if module attribute is present. var xModuleAttribute = (XModuleAttribute)apiTestStep .Module.Search(TqlToGetModuleAttributeInApiModule).FirstOrDefault(); //if not present, Create it. if (xModuleAttribute == null) { XModuleAttribute m = CreateModuleAttribute(apiTestStep.Module as ApiModule, wseTestStepValue); apiTeststepValue = apiTestStep.CreateXTestStepValue(m); } //if already present, use it. else { apiTeststepValue = apiTestStep.CreateXTestStepValue(xModuleAttribute); } } //API xTestStepValue is present now. Assign Values to it now. apiTeststepValue.Disabled = wseTestStepValue.Disabled; apiTeststepValue.Value = wseValue; apiTeststepValue.ActionMode = wseTestStepValue.ActionMode; apiTeststepValue.Condition = wseTestStepValue.Condition; apiTeststepValue.Path = wseTestStepValue.Path; } catch (Exception e) { FileLogger.Instance.Error("Setting value failed : ", e); } }