How would one click on a button, wait for an event like blur and then get the pagesource of the site?
I know i can use the getPagesource() method, but I only wanna do this after a jquery loading image has been shown.
If the blur event results in a visible effect, you could wait for that effect, like waiting for an image to be shown.
Otherwise, if there is no visible effect from that event, you would need a "testing hook" to tell your test that the function associated with that event already ran, like a javascript variable being set to a known value that you could query in the test.
For both cases you could use an explicit wait for the condition, like what is shown in the documentation:
http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits
EDIT:
Regarding your comment, Nyegaard, you could use an explicit wait like this one:
WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
Boolean expectedTextAppeared =
(new WebDriverWait(driver, 10))
.until(ExpectedConditions.textToBePresentInElement(
By.id("ctl00_content_createnewschema_modalAlert_alertMessage"), "textYoureExpecting"));
This code will wait for "textYoureExpecting" to appear in the span with a timeout of 10 seconds. If it takes more time for it to appear, you just need to adjust the timeout.
For all AJAX requests in the webpage I use jQuery.Active flag to determine if the page is loaded or not. If jQuery.Active is non-zero that means those are the number of active requests the browser is dealing with. When it comes down to zero, that means number of active requests are none. I haven't used this flag for blur events, but you might as well give it a try. You should definitely use implicitly and explicitly waits Luiz suggested. Here is a function that waits for 5 minutes for active requests to complete. You could perhaps parameterize that, add try, catch etc.
public int waitforAJAXRequestsToComplete(){
long start = System.currentTimeMillis();
long duration;
boolean ajaxNotReady = true;
while(ajaxNotReady){
if(((JavascriptExecutor)driver).executeScript("return jQuery.active").toString().equals("0"))
return 0;
duration = System.currentTimeMillis() - start;
duration = (long) (duration/(60*1000F));
if(duration>5.0)
return 1;
}
return 1;
}
Related
How do I know if the timer is running or already started? Without waiting the time is elapsed?
UINT_PTR nID = SetTimer(123, 60x1000, NULL); // Info after 1 Min.
bool bTimerStarted = false; // do I need this bool var to check the state of the timer?
if (nID == 123)
bTimerStarted = true;
You cannot. There is no API to query whether any given timer exists, without also resetting that timer (which SetTimer can do).
Then again, I cannot think of a situation where this would be required. Unless you've designed yourself into a corner previously. In that case, solve the architectural issue, and you'll find that you won't need this information either.
I'm having a little trouble working with the linearRampToValueAtTime on a BiQuadFilter applied to a WebAudio.
The audio works ok, and the initial lowpass filter is applied.
Problem is, as soon as I use the linearRamp method to bring up the frequency, it seems to ignore the endTime parameter (or better, it's not time correctly).
Some code to explain it better.
Here's the instancing:
this.audioLoader.load( 'public/media/soundtrack-es_cobwebs_in_the_sky.mp3', buffer => {
this.sounds.soundtrack = new THREE.Audio(this.listener);
const audioContext = this.sounds.soundtrack.context;
this.biquadFilter = audioContext.createBiquadFilter();
this.biquadFilter.type = "lowpass"; // Low pass filter
this.biquadFilter.frequency.setValueAtTime(200, audioContext.currentTime);
this.sounds.soundtrack.setBuffer(buffer);
this.sounds.soundtrack.setFilter(this.biquadFilter);
this.sounds.soundtrack.setVolume(0.5);
this.sounds.soundtrack.play();
})
Until here, everything looks ok. The sound plays muffled as needed.
Then, after a certain event, there's a camera transition, where I want the sound to gradually open up.
As a endTime parameter, I'm passing 2 seconds + the internal context delta.
this.sounds.soundtrack.filters[0].frequency.linearRampToValueAtTime(2400, 2 + this.sounds.soundtrack.context.currentTime);
Expecting to hear the ramp in two seconds, but the sound opens up immediately.
What am I missing?
The linear ramp will be applied using the previous event as the startTime. In your case that will be audioContext.currentTime at the point in time when you created the filter. If that is sufficiently long ago it will sound as if the ramp jumps right to the end value. You can fix that by inserting a new event right before the ramp.
const currentTime = this.sounds.soundtrack.context.currentTime;
const filter = this.sounds.soundtrack.filters[0];
filter.frequency.setValueAtTime(200, currentTime);
filter.frequency.linearRampToValueAtTime(2400, currentTime + 2);
I'm trying to spoof keystrokes; to be a bit more precise: I'm replaying a number of keystrokes which should all get sent at a certain time - sometimes several at the same time (or at least as close together as reasonably possible).
Implementing this using XTestFakeKeyEvent, I've come across a problem. While what I've written so far mostly works as it is intended and sends the events at the correct time, sometimes a number of them will fail. XTestFakeKeyEvent never returns zero (which would indicate failure), but these events never seem to reach the application I'm trying to send them to. I suspect that this might be due to the frequency of calls being too high (sometimes 100+/second) as it looks like it's more prone to fail when there's a large number of keystrokes/second.
A little program to illustrate what I'm doing, incomplete and without error checks for the sake of conciseness:
// #includes ...
struct action {
int time; // Time where this should be executed.
int down; // Keydown or keyup?
int code; // The VK to simulate the event for.
};
Display *display;
int nactions; // actions array length.
struct action *actions; // Array of actions we'll want to "execute".
int main(void)
{
display = XOpenDisplay(NULL);
nactions = get_actions(&actions);
int cur_time;
int cur_i = 0;
struct action *cur_action;
// While there's still actions to execute.
while (cur_i < nactions) {
cur_time = get_time();
cur_action = actions + cur_i;
// For each action that is (over)due.
while ((cur_action = actions + cur_i)->time <= cur_time) {
cur_i++;
XTestFakeKeyEvent(display, cur_action->code,
cur_action->down, CurrentTime);
XFlush(display);
}
// Sleep for 1ms.
nanosleep((struct timespec[]){{0, 1000000L}}, NULL);
}
}
I realize that the code above is very specific to my case, but I suspect that this is a broader problem - which is also why I'm asking this here.
Is there a limit to how often you can/should flush XEvents? Could the application I'm sending this to be the issue, maybe failing to read them quickly enough?
It's been a little while but after some tinkering, it turned out that my delay between key down and key up was simply too low. After setting it to 15ms the application registered the actions as keystrokes properly and (still) with very high accuracy.
I feel a little silly in retrospect, but I do feel like this might be something others could stumble over as well.
Is there a way when I click on a ToolStripButton, it shows the WaitCursor and updates the StatusStrip for about 10 seconds, then returns back to normal. I just don't know how to type in the coding.
If someone could guide me through the process. (or even give me the code)
Thank You
J Mahone
Using a timer:
1:Add a timer from your component toolbox to your form.
2:Set the inteval to 10,000 (this is in milliseconds, 1000 = 1 second)
3:In the timers' "Tick" event, write this code:
Timer1.stop 'This assumes your timer it named Timer1
Me.Cursor = Cursors.Default
4: When you want to make it show the cursor, either have a method to do both these lines and call the method or just write these 2 lines all over the place:
Me.Cursor = Cursors.WaitCursor
Timer1.Start
I'd suggest to use async/await to keep the "normal" program flow.
Me.Cursor = Cursors.WaitCursor
Await Task.Delay(10000)
Me.Cursor = Cursors.Default
I want to have a stopwatch on the site, which displays running time on the label without reloading a page. Is it possible to do this on client side? Should I use Ajax timer or smth else from .net?
Website is in C#.
Some links or demos would be really helpful ! Thanks !
You can do this with basic JavaScript using setTimeout:
var totalSeconds = 0
function stopwatch() {
// increment the seconds
totalSeconds++;
// display the seconds to the user
document.getElementById("<%=myLabel.ClientID%>").innerHTML = "You have spent " + totalSeconds + " on this page.";
// wait a second and call the timer again
setTimeout("stopwatch()", 1000);
}
// trigger the timer
timer();
Update: If the user is going to be on the page for a while you probably want to display a slightly more user-friendly message then "You have spent 1000 seconds on this page". Here's a quick JavaScript function that'll transform the seconds into time elapsed.
It is possible to do in javascript only. There are so many example out there. Just google them. Here's one.