I'm using Androidviewclient for black-box testing of a GUI and I need to record the response time of a button; for example I need to know how long it takes for the next screen to appear from the time I click a "Next" button On a GUI.
Take a look at the profileStart() and profileEnd() in common.py (https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/common.py). They will provide you the means of profiling those cases.
Related
I'm working on an application in Windows CVI that needs to run some code for a series of time intervals set by the user via text entry boxes. The boxes include three for how long to run each process, one to show the total time the processes will take, and one to show the time remaining.
My implementation currently is to have a function with static variables to track which process is running and how long is left in the current process, then move on when that time has elapsed. This function triggers on pushing a start button. Unfortunately, the code stops on the click of the start button as it seems to be waiting for the code to finish executing before it allows any further inputs.
Is there a "right" way to do this? Maybe something with multithreading or a pre-built timer application?
Got an answer here: "You are on the right way speaking about timers: place a timer control on your panel, set it to disabled, put your code in the timer callback and run the program. When the user inputs the required time, set the ATTR_INTERVAL attribute of the timer to this value, next enable the timer with ATRT_ENABLED attribute and you'll have your timed function up and running!"
I am targeting WPF .NET 4.6.1.
I am constantly doing this:
btnClick
{
Task T1 = Task.Run<List<Double>>( AsyncFunction );
T1.Wait(.1);
Dispatcher.Invoke(() => { txtStatus.Text+="HOLD ON.."; };
T1.Wait(.1);
}
The only way I can get this to actually update the UI between these Wait(s) is to do:
Dispatcher.Invoke(new Action(()=>{}),priority: DispatcherPriority.ApplicationIdle);
Is this right? Is this portable? Describe discuss different approaches on different platforms (UWP, Windows 10 Phone).
Possibly see Raymond Chen: https://devblogs.microsoft.com/oldnewthing/20190327-00/?p=102364
I explicity do not want to use Async Button Event because I need to be able to help the user, at least put logic for a tenth of a second completion check and not have the user slamming the async button handler trying to get results and congesting my sensor network with data.
You know I eventually want to get the result of this too, and process it, IN THE SAME EVENT HANDLER CODE, so like I don't want to use BackroundWorker and then have the user have to Click another button to poll the Results, which may STILL BE EMPTY and make everybody REALLY REALLY MAD. And I don't want to Poll the results automatically and then poll the sensors network again and cause MORE congestion.
I explicity do not want to use Async Button Event because I need to be able to help the user, at least put logic for a tenth of a second completion check and not have the user slamming the async button handler trying to get results and congesting my sensor network with data.
The easiest solution is to do it the way everyone else solves it: disable the button while the operation is in progress.
async btnClick
{
btn.Enabled = false;
try
{
txtStatus.Text += "HOLD ON..";
var result = await Task.Run(() => AsyncFunction());
... // update UI with result.
}
finally { btn.Enabled = true; }
}
As an interim update, my testing indicates that both async event handlers and small synchronous Wait(s) are both appropriate approaches. I am achieving significantly better initial response by delegating only Wait(.1) to the network operation, initiating a DispatcherInvoke(()=>{txtStatus+="WAIT.."} and immediately followed by Dispatch(() =>{;//}, DispatcherPriority.ApplicationIdle).
Using an async event handler, and IProgress (you don't even need Dispatcher, just alter a bound control) inside the network call results in similar progress update, but with an initial response that may not be acceptable.
Using the synchronous waits results in a stalling of the UI Paint that makes any gradually updating progress bar appear very jerky.
For me, the progress bar being jerky is not the issues, because I am giving the operator direct feedback with WAIT.. WAIT .. WAIT ..And all the progress bar is doing is showing, by stalling, how backed up the thing is, but I retain enough synchronous control to jam an oscillating CAUTION in there. The oscillation may be jerky but trained operators will know, if that CAUTION keeps toggling, however unevenly, you are on, even if the gradual progress bar stalls and starts.
And, I can detect this in synchronous code, and then do something about it on the fly, like, offload the whole network call and then force the user to queue and poll.
UPDATE
async Task<List<Double>> NetworkList(IProgress<Int32> NetworkProgress)
{
List<Double> _results = new List<Double>();
foreach(var aNetwork in LotsOfNetworksCouldTakeAwhile)
{
SendPingFarAwayLand();
await Task.Delay(delay: TimeSpan.Frommilliseconds(100);
Double PingTime = GetPingTimeOrNull();
_results.Add(PingTIme);
NetworkProgress.Report( aNetwork.NetworkID );
}
}
async btnClick
{
TimeSpan IDLE_LONG_ENOUGH_SO_DISPATCHER_UPDATES_UI = TimeSpan.FromMilliseconds(50);
txtStatus += "WORKING...";
await Task.Delay(delay: IDLE_LONG_ENOUGH_SO_DISPATCHER_UPDATES_UI);
Task<List<Double>> results = await NetworkList(_Progress);
dependencyObject1.ObservableList1.Add(results);
return;
}
This seems to work at least on my computer. About 50 millis is enough to guarantee the dispatcher processes your latest "WORKING..." message immediately. If you don't, you may hit the dispatcher on an up cycle, but maybe not, and it will start on LongNetworkList and it may be a half second before you even see that something is happening.
It's almost like do you want the sprint team captain to hit the stopwatch, or run with you. Delay of 50 millis to even start on the work seems like a lot if you are trying to ping two sub 10ms networks. But if you have even one aberrant one in there that immediately takes up the whole 100ms await and STILL doesn't return anything for you to report progress on, it's nice to have put up something on the screen.
Kudos to Cleary, I'm switching to Reactive.NET, right after lunch.
I need to check if an element is appearing after refreshing a page continuously, cause it takes a while for the changes to be reflected and the element to appear in that page.
Is there any built in method in selenium using Ruby as the programming language ?
Just to confirm, it sounds like the page does not dynamically update once the content is available, so you have to wait until that is true, and then manual refresh, right?
I don't know of anything built into selenium to handle this. It feels like it might even be a symptom of a UI that needs a little more design work (pardon my critique). If the user is experiencing the same thing as the test -- kicking off an action, waiting some unspecified period of time, and then manually refreshing to see the results -- that's a kind of lousy user experience. If that's a bad assumption, and there IS feedback (e.g. a spinner), then your best option will be to conditionally wait for the spinner to appear and then disappear, and then refresh a single time.
If there's really no visible feedback, then you still have a couple of options:
Easy: Hardcode a sleep that's longer than the operation will ever take to complete, and refresh once.
Medium: In a loop, sleep for a constant delay, refresh, repeat until some timeout.
Hard: If the delay required varies widely (sometimes seconds, sometimes minutes), you might consider an exponential back off solution, that sleeps for increasingly longer delays each iteration, before ultimately timing out. The upside is that you're not frantically refreshing dozens of times, the downside is that your delay might be unnecessarily long, if the content arrives just after the next big delay begins.
You can use wait method for the element to be available.
If you need to refresh the page continuously just make sure to wait after each refresh.
I use react.js + es6 + webpack to develop my application.
recently, I find if I click a button multiple times in short time, the click handler will trigger multiple times.
I think it's a common case, code snippet like this:
#debounce()
onMidCardClick(url) {
console.count('onMidCardClick trigger times : ');
window.location.href = url;
}
before navigate to the url address, onMidCardClick event handler will triggers multiple times.
So, my way is create a debounce.decorator.js to handle this situation.
I think my way's advantage is easy to read and keep maintainability.
My question is:
1. Is it necessary to handle this? I mean, maybe react synthetic event will handle this for me?
2. My application has many events, I add debounce decorator for many of them. I test it, it works fine, but I am not sure I am correct. Because I saw many applications not deal with this.
No, all you need to do is, the moment user clicks a button, disable the button till you get the response. You can also disable other buttons too if required. Ex.
<button type="button" disabled={!this.clicked}>Button</button>
From a usability point of view, if the user clicks on a button/li/div element and you are executing some logic, it is better to give a visual indicator that some processing is happening, with a loader or a progress bar.
You can write a react component for a full page loader like this and show it to the user, which effectively prevents the user from clicking the element again while giving a visual clue as well.
My scenario. A page of my WP8 Silverlight app contains a ListBox control with the ability of item multiselection. When the user tap an item to toggle its selection state, I should perform a long operation for all items which are selected by that moment (for example, run a query to filter by the currently selected items). The user can tap some items very quickly, and there is no need to run the query every time after each tap (especially taking into account the fact that the query can take 1-2 seconds). I need to run the query if the user does nothing say for 1 or 2 seconds.
What is the best, not resource consuming, way to implement in WP8? Perhaps, the platform provides us with a useful service for that?
I would expect an application that behaves in such a way to be loathed by the users of it. But if you must then you simply need to reset a timer every time something that you consider as "activity" within your app happens. Presumably this'll be some form of user interaction such as page navigation or interacting/tapping/editing content.
It's crude but it'll work. It'll also negatively impact the battery too. You have been warned.
For Other Alternative see Resetting Idle Detection Countdown in Windows Phone
Your case sounds like a good candidate for Reactive Extensions
The following example uses an observer of ListBox selection changed event, and then wait for 1.5 seconds until reporting an observation:
var itemsChanged = (from evt in Observable.FromEventPattern<SelectionChangedEventArgs>(MyList, "SelectionChanged")
select MyList.SelectedItems)
.Throttle(TimeSpan.FromSeconds(1.5));
itemsChanged.ObserveOnDispatcher()
.Subscribe(items =>
{
Debug.WriteLine("----------------");
foreach (var item in items)
{
Debug.WriteLine(item);
}
}
);
Here is one solution in your scenario. note it is just the pseudo code to convey my solution
private bool isLoadingData = false;
private bool newQueryQueued = false;
///code in your itemselectionchanged event handler
if(isLoadingData)
{
newQueryQueued = true;
//Do not execute your query.
}
else
{
//Execute your query and get the result.
//after the query result is completed, execute the following code.
isLoadingData = false;
if(newQueryQueued)
{
isLoadingData = true;
newQueryQueued = false;
//Execute your query and get the result.
}
}
in the above pseudo code the query is executed only when it is need. say if use has tapped 4 item during first execution. it will not execute resource queries, because the previous result is still pending. and once the result is received the code will see if the user has changed his selection or not if the selection is changed than execute the query again.
and for the second part
I need to run the query if the user does nothing say for 1 or 2 seconds.
you need to implement timer on page load for what ever the time you want(1 or 2 seconds) and dispose off the timer after its first time elapses.
Hope this helps