Reputation: 112
I have created a Web Performance and Load Test Project in MS Visual Studio 2015. Under the project, I created some web performance tests.
But we have different team environments and we want to run these tests on all servers, so I changed the url address by using "Context Parameters" under each web performance test
After using the context param, the URL becomes:
https://{{WebServer}}/WebSite/account/signin
and it works as expected.
But, I want to know is there a config file in which I can update server path, so the web test need not be changed every time.
I tried different options in Local.testsettings
and test.runsettings
. But could not make it dynamic.
Thanks.
Upvotes: 1
Views: 1430
Reputation: 112
Thanks for response. But we do not want to repeat the test cases. At present, we are reading config file in WebTestPlugin class as
public class LoginAssistPlugin : WebTestPlugin
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = configFilePath;
_config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
}
The above method is written in constructor of the plugin class. And the server hostname is set as static variable. Then we use other overridable methods from WebTestPlugin class like below to replace the WebContext Parameters in a web performance tests.
public override void PreRequest(object sender, PreRequestEventArgs e)
{
e.Request.Url = e.Request.Url.Replace("{{WebServer}}", _webServer);
e.Request.Url = e.Request.Url.Replace("{{IdentityServer}}", _identityServer);
e.Request.QueryStringParameters.ToList().ForEach(param => param.Value = param.Value.Replace("{{WebServer}}", _webServer));
e.Request.QueryStringParameters.ToList().ForEach(param => param.Value = param.Value.Replace("{{ClientId}}", _clientId));
e.Request.QueryStringParameters.ToList().ForEach(param => param.Value = param.Value.Replace("{{WebClientPath}}", _webClientPath));
//if(e.WebTest.Name == "signin")
// e.Request.QueryStringParameters.ToList().ForEach(param => param.Value = param.Value.Replace("{{UserName}}", userName));
e.Request.Headers.ToList().ForEach(header => header.Value = header.Value.Replace("{{WebClientPath}}", _webClientPath));
e.Request.Headers.ToList().ForEach(header => header.Value = header.Value.Replace("{{IdentityServer}}", _identityServer));
e.Request.Headers.ToList().ForEach(header => header.Value = header.Value.Replace("{{WebServer}}", _webServer));
e.Request.Headers.ToList().ForEach(header => header.Value = header.Value.Replace("{{ClientId}}", _clientId));
if (_token != null)
{
e.Request.Headers.Add("Authorization", "Bearer " + _token);
}
}
Then this plugin is used in each of web performance tests. Any more help / tips will be hlpfull.
Upvotes: 0
Reputation: 14076
There are a couple of options.
Context parameters may be set in the Load Test. Values set there override values set in a Web Test. Using this method perhaps you could make several copies of the Load Test, one for each of the required environments.
Environment variables can set or override the value of a context parameter. Setting an environment variable with the name "Test.MyWebServer" will override the value of the MyWebServer
context parameter.
Upvotes: 1