private dynamic FormatGridOptions(string option, Type testClassType) { if (bool.TryParse(option, out bool result)) { return(result); } else if (option.StartsWith("env_") || option.StartsWith("vault_")) { return(SecretsResolver.GetSecret(() => option)); } else if (option.StartsWith("AssemblyFolder", StringComparison.Ordinal)) { var executionFolder = ExecutionDirectoryResolver.GetDriverExecutablePath(); option = option.Replace("AssemblyFolder", executionFolder); if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX)) { option = option.Replace('\\', '/'); } return(option); } else { var runName = testClassType.Assembly.GetName().Name; var timestamp = $"{DateTime.Now:yyyyMMdd.HHmm}"; return(option.Replace("{runName}", timestamp).Replace("{runName}", runName)); } }
private dynamic FormatGridOptions(string option, Type testClassType) { if (bool.TryParse(option, out bool result)) { return(result); } else if (int.TryParse(option, out int resultNumber)) { return(resultNumber); } else if (double.TryParse(option, out double resultRealNumber)) { return(resultRealNumber); } else if (option.StartsWith("env_") || option.StartsWith("vault_")) { return(SecretsResolver.GetSecret(() => option)); } else { var runName = testClassType.Assembly.GetName().Name; var timestamp = $"{DateTime.Now:yyyyMMdd.HHmm}"; return(option.Replace("{runName}", timestamp).Replace("{runName}", runName)); } }
private void LoginToService(QT.QTestService serviceToLogin) { string token = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().Token); if (!string.IsNullOrEmpty(token)) { serviceToLogin.SetAuthorizationToken(token); } string userName = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().UserName); string password = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().Password); if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { serviceToLogin.SetUserCredentials(userName, password); } if (string.IsNullOrEmpty(token) && string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) { throw new ArgumentNullException("Please set qTest token or username & password in the testFrameworkSettings.json"); } QT.ServiceResponse <string> response = serviceToLogin.Login(); if (!response.IsSuccess) { throw new InvalidOperationException($"Unable to login to service: {serviceToLogin.GetType()}"); } }
static JiraApiClient() { string baseUrl = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <JiraBugReportingSettings>().Url); _token = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <JiraBugReportingSettings>().Token); _projectName = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <JiraBugReportingSettings>().ProjectName); _restClient = new RestClient(baseUrl).UseSerializer <JsonNetSerializer>(); }
static TelemetryService() { var config = new TelemetryConfiguration(SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AppInsightsSettings>().InstrumentationKey)); TelemetryClient = new TelemetryClient(config); // Enable filter by product version. TelemetryClient.Context.Component.Version = typeof(TelemetryService).Assembly.GetName().Version.ToString(); TelemetryClient.Context.GlobalProperties.Add("Client OS", System.Runtime.InteropServices.RuntimeInformation.OSDescription); TelemetryClient.Context.Component.Version = typeof(TelemetryService).Assembly.GetName().Version.ToString(); TelemetryClient.Context.Device.OperatingSystem = System.Runtime.InteropServices.RuntimeInformation.OSDescription; }
public static Tuple <string, string> GetCredentials() { var user = SecretsResolver.GetSecret(USER_ENVIRONMENTAL_VARIABLE); var accessKey = SecretsResolver.GetSecret(ACCESS_KEY_ENVIRONMENTAL_VARIABLE); if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(accessKey)) { return(Tuple.Create(user, accessKey)); } return(GetCredentialsFromConfig()); }
public FormRecognizer() { string endpoint = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <CognitiveServicesSettings>().FormRecognizerEndpoint); string subscriptionKey = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <CognitiveServicesSettings>().FormRecognizerSubscriptionKey); if (string.IsNullOrEmpty(endpoint) || string.IsNullOrEmpty(subscriptionKey)) { throw new ArgumentException("To use the FormRecognizer you need to set a valid endpoint and subscription key for Azure Form Recognizer Cognitive Service in the testFrameworkSettings.json under cognitiveServicesSettings section. Please check BELLATRIX docs for more info - https://docs.bellatrix.solutions/web-automation/image-recognition/"); } _client = Authenticate(endpoint, subscriptionKey); }
private QT.ServiceResponse <QT.TestCase> UpdateBasicTestCase(long?testCaseId, string precondition) { QT.ServiceResponse <QT.TestCase> result; QT.TestCase existingTestCase = new QT.TestCase(); existingTestCase.Precondition = precondition; existingTestCase.Properties = ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().FieldValues; long projectId = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().ProjectId).ToLong(); result = _testDesignService.UpdateTestCase(projectId, (long)testCaseId, existingTestCase); return(result); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { services.AddDbContext <RegistryDbContext>(opt => opt.UseSqlServer(SecretsResolver.ResolveEmbeddedSecret(HostingEnvironment.EnvironmentName, Configuration, Configuration.GetConnectionString("Registry")))); services.AddMediatR(typeof(Startup).Assembly, typeof(GetResult).Assembly); services.AddSwaggerGen(SwaggerHelper.ConfigureSwaggerGen); services.AddMvc().AddJsonOptions(j => { j.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; j.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); }); }
public QTestTestCaseManagementService() { // we must login first to be able to make any request to the server // or we will get 401 error try { var serviceAddress = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().ServiceAddress); LoginToService(_testDesignService = new QT.TestDesignService(serviceAddress)); LoginToService(_projectService = new QT.ProjectService(serviceAddress)); } catch (Exception ex) { Logger.LogError($"qTest Login was unsuccesful, {ex.Message}"); } }
public AzureTestCasesService() { _uri = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsDynamicTestCasesSettings>().Url); _personalAccessToken = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsDynamicTestCasesSettings>().Token); _project = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsDynamicTestCasesSettings>().ProjectName); }
static AzureQueryExecutor() { _uri = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsBugReportingSettings>().Url); _personalAccessToken = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsBugReportingSettings>().Token); _project = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsBugReportingSettings>().ProjectName); }
static AzureQueryExecutor() { _uri = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsDynamicTestCasesSettings>().Url); _personalAccessToken = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <AzureDevOpsDynamicTestCasesSettings>().Token); }
public DTC.TestCase InitTestCase(TestCasesContext testCasesContext) { QT.ServiceResponse <QT.TestCase> result = default; QT.TestCase qTestCreatedTestCase = new QT.TestCase(); QT.TestCase qTestExistingTestCase = testCasesContext.TestCase != null?ServicesCollection.Current.Resolve <QT.TestCase>() : null; if (string.IsNullOrEmpty(testCasesContext.SuiteId)) { throw new ArgumentException("You must specify a qTest SuiteId."); } // Generate the identification token placed in the beginning of the description. string formattedAutomationId = $"#QE-{testCasesContext.TestCaseId}"; if (!string.IsNullOrEmpty(testCasesContext.TestCaseDescription)) { testCasesContext.TestCaseDescription = $"{formattedAutomationId}-{testCasesContext.TestFullName} \r\n{testCasesContext.TestCaseDescription}"; } else { testCasesContext.TestCaseDescription = $"{formattedAutomationId}-{testCasesContext.TestFullName} \r\n"; } long projectId = SecretsResolver.GetSecret(() => ConfigurationService.GetSection <QTestDynamicTestCasesSettings>().ProjectId).ToLong(); if (!string.IsNullOrEmpty(testCasesContext.TestCaseId)) { // Check if a test case with this ID exists in qTest if (qTestExistingTestCase == null) { qTestExistingTestCase = _testDesignService.ListTestCase(projectId, testCasesContext.SuiteId.ToLong(), expandSteps: true).Data?.FindLast(tcase => tcase.Description.Trim().StartsWith(formattedAutomationId)); } if (qTestExistingTestCase != null) { // Existing test case was found. Update the test cases if a collection is provided if (testCasesContext.TestSteps != null && testCasesContext.TestSteps.Any()) { QT.TestCase updateCase = new QT.TestCase(); bool shouldUpdate = false; // Compare the existing test cases and the New ones using Serialization. Update if they are different. if (testCasesContext.TestSteps.Select(x => x.Description).Stringify() != qTestExistingTestCase.TestSteps.Select(x => x.Description).Stringify()) { updateCase.TestSteps = new List <QT.TestStep>(); foreach (var testStep in testCasesContext.TestSteps) { string description = IsValidJson(testStep.Description) ? testStep.Description : JsonConvert.ToString(testStep.Description).Trim('"'); string expected = IsValidJson(testStep.Expected) ? testStep.Expected : JsonConvert.ToString(testStep.Expected).Trim('"'); updateCase.TestSteps.Add(new QT.TestStep() { Description = description, Expected = expected }); } shouldUpdate = true; } // Set precondition if (testCasesContext.Precondition != qTestExistingTestCase.Precondition) { updateCase.Precondition = testCasesContext.Precondition; shouldUpdate = true; } // Update using the SDK if diffs are found if (shouldUpdate) { result = _testDesignService.UpdateTestCase(projectId, qTestExistingTestCase.Id, updateCase); } } qTestCreatedTestCase = qTestExistingTestCase; } else { // Create brand-new test case // The specific here is that we need to create a very basic test case, and then update it with the details QT.TestCase testCase = new QT.TestCase() { Name = testCasesContext.TestCaseName, ParentId = testCasesContext.SuiteId.ToLong(), Description = testCasesContext.TestCaseDescription, }; // Call SDK testDesign service result = _testDesignService.CreateTestCase(projectId, testCase); if (result.Data != null) { result = UpdateBasicTestCase(result.Data.Id, testCasesContext.Precondition); } } } if (result != null && !result.IsSuccess) { throw new InvalidOperationException(string.Format("Cannnot create test case [{0}] - {1}", result.Error.Code, result.Error.Message)); } else if (result != null) { qTestCreatedTestCase = result.Data; } // Set requirement relation once the test case has been created if (!string.IsNullOrEmpty(testCasesContext.RequirementId)) { IList <long> testCaseList = new List <long> { qTestCreatedTestCase.Id }; var requirementResponse = _projectService.LinkTestCaseRequirement(projectId, new QT.LinkTestCaseRequirement() { RequirementId = testCasesContext.RequirementId.ToLong(), TestCases = testCaseList }); if (requirementResponse != null && !requirementResponse.IsSuccess) { throw new InvalidOperationException($"Cannnot link test case {qTestCreatedTestCase.Id} to requirement {testCasesContext.RequirementId}. {requirementResponse.Error}"); } } ServicesCollection.Current.RegisterInstance(qTestCreatedTestCase); TestCase createdTestCase = new TestCase(testCasesContext.TestCaseId, qTestCreatedTestCase.Name, qTestCreatedTestCase.Description, qTestCreatedTestCase.Precondition); createdTestCase.TestSteps = testCasesContext.TestSteps; return(createdTestCase); }