Visual Studio Web Performance Test - performance

I'm running into a "bad request" error when playing back a test. I've tracked it down to a comma and space in a button that has "Yes, Do" as its value. There is functionality in another page that runs based on this value. When I remove the comma and space in the both pages everything works perfectly. I've tried toggling the 'url encode' property for that field in the Web Perf Test to true, but it still fails. When I look at the details of the request it shows "Yes,+Do" as the querystring param. I can't change the control value in this situation. Any hints?

It seems odd that the value of a button is being passed as a query string parameter in the first place...
Is it set up where there is an extraction rule from a prior request and then that context parameter is used for a later request? If so, you can actually modify the value. You can either hard code the value in the later request, or if you still need to get it dynamically but just modify it, you can create a pretty simple plugin. Sample code for it would be:
public class StringCharsFromParam: WebTestRequestPlugin
{
public override void PreRequest(object sender, PreRequestEventArgs e)
{
string ExtractParam = ((string)e.WebTest.Context["NameOfContextParameter"]);
if (ExtractParam != null && ExtractParam.Contains(", ")
{
e.WebTest.Context["NameOfContextParameter"] = ExtractParam.Replace(", ", "");
}
}
}
You would then add this WebTestRequestPlugin to your WebTest.

Related

Visual Studio: Use csv file for “Find Text” validation in web performance test not working

I am using csv file for posting the data and checking the response back, where in find text, i want to use the same csv files.
In string body im using :{{DataSource1.Table#csv.objectId}} which is working fine for posting request.
same thing i passed in find text in validation rule, it doesn't work and i am getting failure for this validation rule.
In validation rule, i am using "Find Text" and passing {{DataSource1.Table#csv.objectId}}
The "Details" tab show this for the validation rule :
Find Text Validation The required text '{{DataSource1.Table#csv.objectId}}' did not appear in the HTML response. FindText={{DataSource1.Table#csv.objectId}}, IgnoreCase=True, UseRegularExpression=True, PassIfTextFound=True
Tried using custom validation rule and tried passing context parameter.Same issue.Validation rule for it is below:
Many places where a ".webtest" allows a context parameter (CP) have a "bind" facility on the property. For example, look at the Value property of a "Header" to a request, it has a drop-down list giving access to CPs.
Some properties of a ".webtest" allow CPs to be embedded in the text. For example the Url property of a request allows things like text{{CpOne}}moretext{{CpTwo}}etc.
Unfortunately there are some properties of a ".webtest" that only allow text and do not expand embedded CPs. I have not found any clear statement of which places allow bound CPs, which support embedded CPs and which allow neither. Also I have not found any built in support for CPs in user-written plugins or extraction rules or validation rules. My approach has been to try using CPs wherever I need them and, when they do not work, write my own code that does what is needed.
You might write your own validation rule as described in this Microsoft page. The code could be based on the following code which has not been tested.
public class FindCpValueInResponseBody : ValidateResponseUrl
{
public string CpWithTextToFind { get; set; }
public override void Validate(object sender, ValidationEventArgs e)
{
string TextToFind = e.WebTest.Context[CpWithTextToFind].ToString();
e.WebTest.AddCommentToResult("Looking for '" + TextToFind +"' (from CP '" + CpWithTextToFind + "').");
if (e.Response.BodyString.Contains(TextToFind))
{
e.IsValid = true;
e.Message = "Text '" + TextToFind + "' found.";
}
else
{
e.IsValid = false;
e.Message = "Text '" + TextToFind + "' not found.";
}
}
}
It should be a simple matter to enhance the above method to add the other properties of the built-in FindText validation rule; properties such as Pass if text found and Ignore case etc, should they be needed.
The above validation rule takes the context parameter name. So if the value is from a data source then the value should be something like DataSource1.Table#csv.objectId. Note that there are no curly braces (i.e. no { or }) and no leading or trailing whitespace.

Conditional AJAX confirm with a new value in Wicket

I need to solve a simple problem, but yet I have not been able to found out any solution yet.
I have a simple DropDownChoice with AJAX onChange() JS event. I need to add a confirm box before the onUpdate() action is done - this is not difficult, BUT I need to display the confirm box only if the new selected value of the DropDownChoice is X (one certain value), and do not display the confirm box in any other case. Is it doable?
Short example snippet:
DropDownChoice<Integer> choice = new DropDownChoice<Integer>("id", new Model<Integer>(0));
choice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
// do some stuff
}
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new AjaxCallListener() {
#Override
public CharSequence getPrecondition(Component component) {
return "return confirm('Really?')"; // I NEED THIS DISPLAYED CONDITIONALLY
}
}
}
}
I don't know how to access the "choice" model object (converted input...) with the proposed value to add it to a condition in updateAjaxAttributes() method.
Thank you.
I think you should go for a JavaScript-based solution. The code of AJAX call listener is executed in a scope where you can use variable attrs. This variable contains the parameters used to perform AJAX call, including the id of the component. In this way you could check for selected value.
See more at http://wicket.apache.org/guide/guide/ajax.html#ajax_5

Windows phone 7: facing issue for passing parameters

Right now i am developing a Windows phone app, yes this is my first windows app. Right now i am facing an issue, don't know what's the silly mistake i made. Yes of course i have done debugging.
Now, what exactly i am doing?
Passing data from 1st page to 2nd page,
On the page, catching data inside onNavigateTo() method, yes i am receiving it correctly.
Based on the parameter/data (i.e. ID) i got, i am making web service call.
Problem:
If i move to the 3rd page from 2page and again came back to the 2nd page, its again making web call. i.e. calling DownloadStringAsync again in below code.
i.e. If 2nd page is having ListBox with 5 data, now clicking on particular item i am moving to 3rd page, if i came back to 2nd page from page 3, items get doubled i.e. 10 items (just because its making call again)
Here is the possible code for the reference:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
type = Convert.ToInt32(NavigationContext.QueryString["Type"]);
if (type != 0)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
client.DownloadStringAsync(new Uri(Utils.Constant.WebService_URL));
}
else
{
MessageBox.Show("Please check internet connection!!");
}
}
}
Can't you use the following code to test if the user used the back button?
e.NavigationMode == System.Windows.Navigation.NavigationMode.Back
sometimes this method(QueryString) create problems.
In back event it create problems
its betters to store the id(parameter) in isolatedstorage application key
IsolatedStorageSettings.ApplicationSettings["id"] = "your data";
OnNavigatedTo is called whenever you navigate to the page, either by a forward navigation, or a back navigation. That's why it's retriggered when you navigate back from page #3 to page #2.
You can avoid this by only triggering the network call on a forward navigation.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (this.isInitialized) return;
type = Convert.ToInt32(NavigationContext.QueryString["Type"]);
if (type != 0)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
client.DownloadStringAsync(new Uri(Utils.Constant.WebService_URL));
}
else
{
MessageBox.Show("Please check internet connection!!");
}
}
this.isInitialized = true;
}
Beware that NetworkInterface.GetIsNetworkAvailable can block (in this case the UI thread) for a long time in some scenarios, to work around this you can use network detection events.

How to get extra parameter from AjaxRequest wicket 6

Hi all wicket pros out there,
I would like to get extra parameter I added to the AjaxRequest in the respond(AjaxRequestTarget target) method of a AbstractDefaultAjaxBehaviour.
I build the Wicket.Ajax.get(...) call by myself and I could manage that the respond(AjaxRequestTarget target) method of the AbstractDefaultAjaxBehaviour is invoked, but I get stock in how to get the extra parameters I added in my js call.
So here the code what I'm doing:
js that is called onSelect:
Wicket.ajax.get({'u':'callbackUrl','c':'componetId', 'ep':{'objectId':'OBJECT_ID'}});
java snippet of the AbstractDefaultAjaxBehaviour:
onSelectBehavior = new AbstractDefaultAjaxBehavior(){
#Override
protected void respond(AjaxRequestTarget target) {
//here I want to get the OBJECT_ID I added in the Wicket.Ajax.get call above
}
};
The respond() method is invoked as expected, but I don't know how to get the OBJECT_ID.
Actually I'm not sure at all if I added the extra parameter in the right way to the wicket.ajax.get call.
In Wicket 1.4 I added the extra parameters as a url query string like ajaxCallUrl...?objectId=OBJECT_ID and in respond() I got them back from the RequestCycle RequestCycle().get().getRequest().getParameter('objectId')
If anyone could give me a hint, I would appreciate it :)
Thanks in advance,
Ronny
Your approach is correct. You should be able to get the parameter like this:
#Override
protected void respond(AjaxRequestTarget target)
{
getRequest().getRequestParameters().getParameterValue("objectId");
}
See my answer to this question for passing parameters directly from Wicket without constructing the ajax call yourself.

Out of Range exception while accessing the files in Windows 8 Metro app

Below is the code I used to access the asset file for a metro app I am working on.
async void readFileFromDisk (string fileName, string fileType)
{
string fileContent;
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileName);
using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read))
{
using (DataReader dataReader = new DataReader(readStream))
{
UInt32 numBytesLoaded = await dataReader.LoadAsync((UInt32)readStream.Size);
fileContent = dataReader.ReadString(numBytesLoaded);
}
}
This code is run in the handler for Loaded event for the page. I am currently getting an exception saying "Value does not fall in range". The error occurs at the first line itself, where I try to get storagefile handle from the installation folder.
On debugging, the fileName string comes out to be Null. I guess, I should be moving the code to some event which is fired at a later stage in page lifecycle, but can't seem to figure out what is the best place to do it. Suggestions??
P.S. I need to read this file before any interaction from user, as it reads the data for the level, that user will be interacting with.
Edit:
Missed a couple things.
The below function is called from the handler for loaded event.
void Game_Loaded(object sender, RoutedEventArgs e)
{
//read all level files to the strings
readFileFromDisk("//Assets/Levels/Start" + selectedLevel + ".txt", "Start");
This handler basically calls above function for different file paths, in similar manner. The string selected level is static variable, while the fileName string is created from the same.
Edit 2:
Found the issue, but solution is still far away. The return type of readFileFromDist method is causing trouble. Changed it to Task, and this part works fine, but I get "Object reference not set to an instance" error. Tried to convert Game_Loaded event handler to async too, to use await operators, but that gives me compiler error for "wrong return type".
SO, I tried removing async completely, but I guess I can't do that. There is no way to open files without using async function. So, I essentially need a way to call the readFileFromDisk function, using await, and continue with rest of the code execution once the task is completed. Something like, "IsCompleted" event for the awaited calls for the function.
Solved! Needed to use "ms:appx///Assets/filename.txt" instead of "//Assets/filename.txt".

Resources